Versions Compared

Key

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

...

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

Description

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


Info
titlePlease note

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

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 having Android iOS SDK.

No Format
appium

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

 

Code Block
languagejs
titlepom.xml
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<!-- based on
https://github.com/appium/appium/blob/2fe7ea7b098ba2145e3c7b4cc31276a3e26921ec/sample-code/examples/java/junit/pom.xml
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>appium</groupId>
  <artifactId>tutorial_android</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>appium_tutorial_android</name>
  <description>JUnit Android examples</description>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>io.appium</groupId>
      <artifactId>java-client</artifactId>
      <version>2.0.0</version>
    </dependency>
    <dependency>
      <!-- Must use 1.0.15 or better otherwise upload file will have cookie warnings
      https://github.com/saucelabs/saucerest-java/commit/99bce5b108354ad086ac31e06c1e3ab092000490
      -->
      <groupId>com.saucelabs</groupId>
      <artifactId>saucerest</artifactId>
      <version>1.0.16</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.googlecode.json-simple</groupId>
      <artifactId>json-simple</artifactId>
      <version>1.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
      <scope>test</scope>
    </dependency>
    <!--
     Sauce JUnit is contained in saucelabs/sauce-java
     https://github.com/saucelabs/sauce-java/tree/master/junit
    -->
    <dependency>
      <groupId>com.saucelabs</groupId>
      <artifactId>sauce_junit</artifactId>
      <version>2.1.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.2.4</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
        <version>3.1</version>
      </plugin>

    </plugins>
  </build>

  <repositories>
    <repository>
      <id>saucelabs-repository</id>
      <url>https://repository-saucelabs.forge.cloudbees.com/release</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>

</project>


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.

...