Overview
In this tutorial, we will create a JUnit Test Case in Java, using Appium library for automation of iOS applications.
Description
The following automated test is taken from the tutorials provided by Appium, in this case for iOS.
Please note
This example may be found in the public github repo in https://github.com/appium/tutorial/tree/master/projects/java_ios. The repo also provides examples for other languages.
Appium must be running in the machine having iOS SDK.
appium
The class implementing the automated tests need to be updated also in order to properly setup the IP of the Appium server along with the required Android version.
The sample project contains two classes with the automated Tests. Below you can find one, as an example.
package appium.tutorial.ios; import appium.tutorial.ios.util.AppiumTest; import org.openqa.selenium.WebElement; import java.util.ArrayList; import java.util.List; import static appium.tutorial.ios.util.Helpers.*; public class AutomatingASimpleActionTest extends AppiumTest { @org.junit.Test public void one() throws Exception { text("Various uses of UIButton").click(); text_exact("Buttons"); } @org.junit.Test public void two() throws Exception { wait(for_text("Various uses of UIButton")).click(); wait(for_text_exact("Buttons")); } @org.junit.Test public void three() throws Exception { WebElement cell_1 = wait(for_text(2)); String page_title = cell_1.getAttribute("name").split(",")[0]; cell_1.click(); wait(for_text_exact(page_title)); } @org.junit.Test public void four() throws Exception { List<String> cell_names = new ArrayList<String>(); for (WebElement cell : tags("TableCell")) { cell_names.add(cell.getAttribute("name")); } for (String name : cell_names) { wait(for_text_exact(name)).click(); wait(for_text_exact(name.split(",")[0])); back(); } } }
In fact the above class and other ones, such as Helpers.java, had to be changed due to changes introduced by Apple in the automation API with XCUITest.
Tests can be run by using Maven.
mvn clean test
Since the previous command generates multiple JUnit XML files, we may need to merge them in single XML file so it can be submitted into a Test Execution more easily. That can be achieved by using the junit-merge utility, for example.
junit-merge -o results.xml -d target/surefire-reports/
After running successfuly the Test cases and generating the aggregated JUnit XML report (e.g. results.xml), it can be imported to Xray (either by the REST API or through "Import Execution Results" action within the Test Execution).
Each JUnit's Test Case is mapped to a Generic Test in JIRA, and the "Generic Test Definition" field contains the name of the package, the class and the method name that implements the Test Case. The summary of each Test issue is filled out from the name of the method corresponding to the JUnit Test.
The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the Test Case class, including its namespace.
References
- https://github.com/appium/tutorial/tree/master/projects/java_ios
- http://appium.io
- https://www.npmjs.com/package/junit-merge