Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

In this tutorial, we will create a JUnit Test Case in Java, using the Appium library for automation of Android applications.

Description

The following automated test is taken from the tutorials for Android provided by Appium, in this case for Android


Info
titlePlease note

This example may be example is found in the public github repo Github repository in https://github.com/appium/tutorial/tree/master/projects/java_android. The repo  It also provides examples for other languages.

Requirements

  • The Android emulator should be started with a compatible virtual device.
No Format
emulator @Nexus_5_API_25


  • Appium must be running in the machine

...

  • with Android SDK.
No Format
appium


We will make a simple update to the pom.xml file in order to generate a JUnit xml report.

...

The class implementing the automated tests need to be updated also in order to properly setup set up 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.is one of them:

Code Block
languagejava
titleAutomatingASimpleActionTest.java
package appium.tutorial.android;

import appium.tutorial.android.util.AppiumTest;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

import static appium.tutorial.android.util.Helpers.*;

public class AutomatingASimpleActionTest extends AppiumTest {

    @org.junit.Test
    public void one() throws Exception {
        text("Accessibility").click();
        text_exact("Accessibility Node Provider");
    }

    @org.junit.Test
    public void two() throws Exception {
        wait(for_text("Accessibility")).click();
        wait(for_text_exact("Accessibility Node Provider"));
    }

    @org.junit.Test
    public void three() throws Exception {
        wait(for_text(2)).click();
        find("Custom Evaluator");
    }

  @org.junit.Test
    public void four() throws Exception {
        setWait(0);

        List<String> cell_names = new ArrayList<String>();

        for (WebElement cell : tags("android.widget.TextView")) {
            cell_names.add(cell.getAttribute("name"));
        }

        // delete title cell
        cell_names.remove(0);

        for (String cell_name : cell_names) {
            scroll_to_exact(cell_name).click();
            waitInvisible(for_text_exact(cell_name));
            back();
            wait(for_find("Accessibility"));
            wait(for_find("Animation"));
        }

        setWait(30); // restore old implicit wait
    }
}



Tests can be run by using Maven.

No Format
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.

No Format
junit-merge  -o results.xml -d target/surefire-reports/

After successfully 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 "the Import Execution Results" action within the Test Execution).

Each JUnit's Test Case is mapped to a Generic Test in JIRAJira, 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

...