This article 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.
Prepare your Appium test
Do the following to prepare your Appium test to run remotely in SRF:
1. 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. In the code that starts the session, add your SRF client ID and secret as capability code.
3. capabilities.SetCapability("SRF_CLIENT_ID", "<placeholder>");
3. Make your apps available for the test by uploading them to SRF.
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 scrollToExactmethods.||Instead, use a driver. execute command, for example,
5. Continue with Run your test.
Run your test
Run your test using the relevant steps for your testing tool:
To run your Appium test in Eclipse:
1. Open your project in Eclipse. Set the Appium capabilities as needed, including the server and device information.
2. Launch the test. Check the Eclipse console to ensure that your test is running properly.
To run your Appium test with Ant:
1. Download and install Apache Ant, and set the required environment variables.
2. Open a command dialog box and navigate to your Appium workspace path.
3. Run the command
ant <test_name>.java to start running your test.
Check the Ant console to ensure that your test is running properly.
To run your Appium test as a Jenkins job: (Terminology refers to Jenkins 2.00 and higher):
1. Download and install Apache Ant, and set the relevant environment variables.
2. Open the Jenkins dashboard and click New item.
3. Specify an Item name and click Freestyle project.
4. In the General tab, click Advanced.
5. Select Use custom workspace and enter your Appium workspace path.
6. In the Build section, select Invoke ant.
7. Click the Advanced button. Provide a target name and the full path to the build.xml file in the Build Filefield.
8. Click Save.
9. On the project page, click Build Now.
To run multiple Appium tests as a Jenkins job: (Terminology refers to Jenkins 2.00 and higher):
1. Prepare several single job freestyle jobs.
2. Click New item and specify a MultiJob project.
3. In the Build section, select MultiJob Phase from the Add build step drop down. Enter a phase name.
4. Click Add jobs and select the first job you want to add. Repeat this step for all of the jobs you want to include in this phase.
5. Select an option from the Job execution type drop down: sequentially or in parallel.
If you are executing multiple jobs, but only have one device, the jobs will be executed sequentially—not in parallel.
6. Optionally, select a continuation condition, for example: Always, Successful, or Completed.
7. On the project page, click Build Now.
Tip: The udid, name, and platformVersion capabilities are optional. You can use the platformNamecapability alone, to instruct the Appium test to look for the next available device.
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.
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.
HashMap<String, String> encoding= new HashMap<String, String>();
String logFileContents = (String) wd.executeScript(“mc-wd: downloadLogs”, encoding);