Skip to main content

Mobile Studio - Android - Build Your First Test

This tutorial shows you how to build or execute test cases on Android devices connected to the cloud using the Appium Driver or Continuous Testing Automation client.

To develop a test, you need to open a device in Automation Mode

Prepare Your Application

  1. Click on the Apps Manager button.

  2. Click Upload.

  3. Click Browse Files, then click the desired Application from your local hard drive.

  4. Click Upload. Once the application is uploaded, you see the application on the drawer.

  5. Select the application, then click Launch.

Open the Object Spy 

The Object Spy provides a visual representation of the application objects layout**.**

The object spy allows you to select an element and see its properties. You can either select an element by traversing through the Hierarchy tree on the left OR you can select a box from the image on the right.

To use the Object Spy:

  1. Select an element.
  2. Click Copy Unique XPathThe XPath is copied to the clipboard and also added to the filter box. 

Create a Project with a Java IDE 

You can either create a new Appium project, or create a Maven project.

Create a New Appium Project in Eclipse (Gradle \ Maven)

  1. Click File->New→ Other → Gradle Project.

  2. Select Create a simple project (skip archetype selection), then click Next.

  3. Open the newly created project.

  4. Open the build.gradle file.

  5. Replace the generated content with the following:

    build.gradle Expand source

    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'eclipse'

    repositories {

    maven { url "http://repo.experitest.com:8010/Maven2/" }
    /* Optional Use the Cloud server as a maven repository
    // maven { url "<Your Cloud URL>/download-file" }
    */
    maven { url "http://repo.maven.apache.org/maven2" }

    mavenCentral()
    }
    dependencies {
    compile group: 'com.experitest', name: 'appium', version:'4.1.2'
    }
  6. Run the clean, cleanEclipse, and Eclipse tasks to prepare your eclipse environment. 

Maven

  1. Click File->New->Other... → Maven Project.

  2. Select Create A simple project. **

    **

  3. Open the source of your project POM.xml file.**

    **

  4. Replace the content with this code:

pom.xml Expand source

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>Your.Group.Id</groupId>
<artifactId>Your.Artifact.Id</artifactId>
<version>Your.Version</version>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<id>Experitest.repo1</id>
<name>CloudRepository</name>
<url>http://repo.experitest.com:8010/Maven2/</url>
<layout>default</layout>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.experitest</groupId>
<artifactId>appium</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies>
</project>
 

Write Your First Test Class

Create a Test Class under src/test/java in your project. 

info

Replace <server> with the appropriate URL.

FirstTest Expand source

import java.net.MalformedURLException;
import java.net.URL;
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class FirstTest {

AndroidDriver driver;
@Before
public void setUp() throws MalformedURLException{
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.UDID, <DEIVCE_UDID>); //Place here the UDID of the device
dc.setCapability("username", <USERNAME>); //Your Continuous Testing Username
dc.setCapability("password", <PASSWORD>); //Your Continuous Testing Password
// If you wish to Continue with the current session, WITHOUT INSTALLING AND LAUNCHING THE APP, comment the line below
dc.setCapability(MobileCapabilityType.APP, "C:\\APPS\\eribank.apk");
driver = new AndroidDriver<>(new URL(<server>), dc);
}
@Test
public void exampleTest(){
driver.findElement(By.xpath("//*[@id='usernameTextField']")).sendKeys("company");
driver.findElement(By.xpath("//*[@id='passwordTextField']")).sendKeys("company");
driver.findElement(By.xpath("//*[@text='Login']")).click();
driver.findElement(By.xpath("//*[@text='Logout']")).click();
}

@After
public void tearDown(){
driver.quit();
}
}