Skip to content
Martin Großmann edited this page Dec 18, 2023 · 7 revisions

Testerra-appium-connector

Dependencies

Include the following dependency in your project.

Gradle:

// Version from this module
implementation 'io.testerra:appium:2.1'
// Used Testerra version
implementation 'io.testerra:driver-ui:2.1'
implementation 'io.appium:java-client:7.3.0'

Maven:

<!-- Version from this module -->
<dependency>
    <groupId>io.testerra</groupId>
    <artifactId>appium</artifactId>
    <version>2.1</version>
</dependency>
<!-- Used Testerra version -->
<dependency>
    <groupId>io.testerra</groupId>
    <artifactId>driver-ui</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>7.3.0</version>
    <!-- Needed for correct Testerra logging -->
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Use Appium features

The connector uses the AppiumDriver that you can use to unlock appium related features on the implementation of WebDriver interface.

Appium test class

public class ExampleTest extends TesterraTest {

    @Test
    public void testT01_My_first_test() {

        WebDriver webDriver = WEB_DRIVER_MANAGER.getWebDriver();
        WEB_DRIVER_MANAGER.unwrapWebDriver(webDriver, AppiumDriver.class).ifPresent(appiumDriver -> {
            // Use Appium driver specific methods
            appiumDriver.rotate(ScreenOrientation.LANDSCAPE);
        });
    }
}

Properties

Basic configuration in test.properties

Property default Capability Description
tt.mobile.grid.url NONE - Grid URL of Appium / Selenium Grid ending on "wd/hub"
tt.mobile.grid.access.key NONE accessKey Access key of your user and project at Appium server, if needed.
tt.mobile.device.query.ios "@os='ios' and @category='PHONE'" deviceQuery Define the requested iOS device.
tt.mobile.device.query.android "@os='android' and @category='PHONE'" deviceQuery Define the requested Android device.

Device filtering

If you have to run your tests on specific mobile devices available on your mobile device farm, you can use the tt.mobile.device.query.android and tt.mobile.device.query.ios to filter for your devices by different properties. To reserve a device and run tests on it you can simply use WebDriverManager.getWebDriver() call. If one or more device(s) matches your filter, the driver will be instantiated, otherwise the call will fail.

The following query attributes are available for the device query strings.

  • @category
  • @os
  • @version
  • @manufacture
  • @model
  • @name

Please keep in mind, that you have to specify the device query for each operating system with the properties mentioned above. The default values will provide you a device with given operating system and of @category PHONE.

AppiumDriverRequest

You can also create new sessions by using the AppiumDriverRequest:

AppiumDriverRequest appiumRequest = new AppiumDriverRequest();
appiumRequest.setAccessKey(String);
appiumRequest.setDeviceQuery(String);
appiumRequest.setServerUrl(URL);
appiumRequest.setStartupTimeoutSeconds(int);
appiumRequest.setReuseTimeoutSeconds(int);

WebDriver appiumDriver = WEB_DRIVER_MANAGER.getWebDriver(appiumRequest);