Oct 28, 2017

How to run run Appium tests on iOS real device

Overview :-


Appium is an open source test automation tool for mobile applications. It allows you to test all the three types of mobile applications: native, hybrid and mobile web.It also allows you to run the automated tests on actual devices, emulators and simulators.

If you want to start mobile automation on iOS device/Simulator, first you must have to setup the compatible Xcode installation on your machine and drag the Xcode app to Applications. Now connect the iPhone device to your mac and find the UDID of connected device from iTunes.


Pre-requisites :-

1. JDK installation

2. Xcode Installation

3. Appium installation

4. Setup iOS real device tests with XCUITest


Prerequisted Jars:

  • java-client.jar - For Appium
  • selenium-server-standalone.jar - For webdriver capabilities
  • commons-validator.jar - if want to run appium server programatically



Example : 


To run your test on iOS real device browser, you have to pass the desire capabilities to the Appium driver. Desired capabilities are a set of keys and values (i.e., a map or hash) sent to the Appium server to tell the server what kind of automation session we’re interested in starting up. There are also various capabilities which can modify the behavior of the server during automation.

For example, we set the platformName capability to iOS to tell Appium that we want an iOS session, rather than an Android or Windows one.

To configure you test to run against safari browser simply set the “
BROWSER_NAME” to be “Safari”

public class WebTest {

static AppiumDriver driver;

public static void main(String[] args) throws InterruptedException {

       DesiredCapabilities iOSCapabilities = new DesiredCapabilities();
        iOSCapabilities.setCapability(CapabilityType.BROWSER_NAME, "Safari");
        iOSCapabilities.setCapability("deviceName", "iPhone");
        iOSCapabilities.setCapability("udid", <device udid>);
        iOSCapabilities.setCapability("xcodeOrgId", <10 digit xcodeOrgId>);
        iOSCapabilities.setCapability("xcodeSigningId", "iPhone Developer");
        iOSCapabilities.setCapability(CapabilityType.VERSION, "10.2");
        iOSCapabilities.setCapability("newCommandTimeout", 120);
        iOSCapabilities.setCapability("platformName", "iOS");
        iOSCapabilities.setCapability("automationName", "XCUITest");
        iOSCapabilities.setCapability("networkConnectionEnabled", true);
        iOSCapabilities.setCapability("safariAllowPopups", true);
        iOSCapabilities.setCapability("safariIgnoreFraudWarning", true);
        iOSCapabilities.setCapability("autoAcceptAlerts", true);
        iOSCapabilities.setCapability("locationServicesAuthorized", true);
    
try {
driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), iOSCapabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    driver.get("https://www.google.co.in");
    driver.findElement(By.name("q")).sendKeys("Welcome");
    System.out.println("done");
}
}

No comments:

Post a Comment

Mobile App Automation with Appium on Android Emulator/Device

Overview :- Appium  is an open source test automation tool for mobile applications. It allows you to test all the three types of mobile...