Run Appium scripts remotely

This topic describes how to set up your Appium environment and run tests remotely in the SRF environment lab.

Prepare your Appium environment

To prepare your environment to run an automated Appium test, you must first configure your working environment, such as Visual Studio or Eclipse, to recognize the Appium project.

Visual Studio

To set up your Visual Studio environment with Appium, follow these steps:

  1. Create a new Unit Test project in Visual Studio.

  2. In the Solution Explorer, right-click References, and select Add Manage Nuget Packages.

  3. Search for ‘Appium Webdriver’, and then click Install. This updates the references to include the Appium drivers.

  4. Search for ‘Selenium WebDriver’, and then and click Install. This updates the references to include the Selenium drivers.

  5. Browse to the .cs file and add in your SRF capability code.

  6. Instantiate the Appium web driver.

  7. Define any relevant capabilities. For details, see Supported Appium capabilities.

  8. Continue with Prepare your Appium test.

Eclipse

To set up your Eclipse environment, follow these steps:

  1. Download the latest archive files of the following:

    Extract the contents of the downloaded archive files.

  2. In Eclipse, right-click your Appium project, and select Select Properties.

  3. Click on the Java Build Path node and select the Libraries tab.

  4. Click on Add External JARs and add the downloaded jars, one at a time:

    • the Java-client jar file extracted from the Selenium Java client download

    • the jar files in the libs folder of the extracted Selenium client download

    • the Java-client jar file extracted from the Java-Client for Appium download

  5. Click OK to close the Properties dialog box.

  6. Continue with Prepare your Appium test.

Back to top

Prepare your Appium test

Do the following to prepare your Appium test to run remotely in SRF:

  1. Add SRF URL and port values

    In the code the starts the session, replace the Appium server URL and port with the SRF URL and port.

    Use the following syntax:

    driver = new AndroidDriver(new URL("https://ftaas.saas.hpe.com:443" + "/wd/hub"), capabilities);
    driver = new IOSDriver(new URL("https://ftaas.saas.hpe.com:443" + "/wd/hub"), capabilities);
  2. Add your SRF client ID and secret

    In the code that starts the session, add your SRF client ID and secret as capability code.

    capabilities.SetCapability("SRF_CLIENT_ID", "<placeholder>");
    
    capabilities.SetCapability("SRF_CLIENT_SECRET", "<placeholder>");

    For more details, see Manage tunnels and Capability reference.

  3. Upload your apps

    Make your apps available for the test by uploading them to SRF.

    For details, see the Mobile Lab User Guide.

  4. Modify your code for deprecated elements and methods

    Beginning with version 1.6.3, Appium deprecated the following items:

    By.name element for findElement. Make sure to modify your code accordingly.
    scrollTo and scrollToExact methods.

    Instead, use a driver. execute command, for example,
    driver.execute('mobile: scroll', {element: el, toVisible: true})

  5. Continue with Run your test.

For more details about additional supported capabilities and samples, see:

Back to top

Run your test

Run your test using the relevant steps for your testing tool:

As your test runs, the device is locked and reserved by you in the SRF mobile lab.

The running tests icon in the upper right corner of SRF indicates that your test is running.

Back to top

Retrieve Appium logs

A log file is generated while your Appium test runs.

To retrieve the log, use the mc-wd:downloadLogs script and specify the encoding.

When the connector receives this command, it retrieves the contents of the Appium log file for the current testing session, as a string. Attach the string to the response body.

The Appium user's test code uses the string from the response body and processes it accordingly.

For example:

HashMap<String, String> encoding= new HashMap<String, String>();

encoding.put("encoding", "UTF-8");

String logFileContents = (String) wd.executeScript("mc-wd: downloadLogs", encoding);

Back to top

See also: