Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Last active August 17, 2022 12:02
Show Gist options
  • Save SarahElson/5dec33f506b821abb58350eaaa3c54dc to your computer and use it in GitHub Desktop.
Save SarahElson/5dec33f506b821abb58350eaaa3c54dc to your computer and use it in GitHub Desktop.
How To Automate iOS App Using Appium
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.URL;
public class vanilla_ios {
public static String userName = System.getenv("LT_USERNAME") == null ? "sidharth****" //Add username here
: System.getenv("LT_USERNAME");
public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "********" //Add accessKey here
: System.getenv("LT_ACCESS_KEY");
public static final String URL = "https://" + userName + ":" + accessKey + "@beta-hub.lambdatest.com/wd/hub";
public static IOSDriver driver = null;
public static void main(String[] args) throws Exception {
try {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformVersion", "15");
caps.setCapability("deviceName", "iPhone 12");
caps.setCapability("isRealMobile", true);
caps.setCapability("app", "******"); //Enter your app url
caps.setCapability("platformName", "iOS");
caps.setCapability("build", "Java Vanilla - iOS");
caps.setCapability("name", "Sample Test Java");
caps.setCapability("devicelog", true);
caps.setCapability("network", true);
driver = new IOSDriver(new URL("https://" + userName + ":" + accessKey + "@beta-hub.lambdatest.com/wd/hub"), caps);
Thread.sleep(2000);
//Opens the browser
MobileElement browser = (MobileElement) driver.findElementByAccessibilityId("Browser");
browser.click();
Thread.sleep(3000);
WebDriverWait el7 = new WebDriverWait(driver, 30);
el7.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url")));
driver.findElementById("url").sendKeys("https://www.lambdatest.com/");
//Clicks on the text box
WebDriverWait el = new WebDriverWait(driver,90);
MobileElement el4 = (MobileElement) driver.findElementByAccessibilityId("find");
el.until(ExpectedConditions.elementToBeClickable(el4));
el4.click();
el4.sendKeys("Lambdatest");
//((JavascriptExecutor) driver).executeScript("lambda-status=passed");
driver.quit();
} catch (Exception t) {
System.out.println(t);
driver.quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment