Site icon TestingDocs.com

Run Appium Test on Android Virtual Machine

Overview

In this tutorial, we will write a sample Appium Test and run the test on the Android Virtual machine. To set up the Test project we need some dependencies that are listed on this page.

Android Studio

https://www.testingdocs.com/installing-android-studio-on-windows/

Appium Server

Launch the Appium server.

https://www.testingdocs.com/install-appium-desktop-server/

Appium Architecture

https://www.testingdocs.com/appium-architecture/

Android Virtual Machines

Create an Android Virtual machine.

To run the Test on Android Virtual Machine, we need to create virtual machine using the AVD manager.

 

Steps to create virtual device can be found at:

https://www.testingdocs.com/creating-android-virtual-device-with-avd-manager/

 

Maven Project

Create a Maven project.

https://www.testingdocs.com/create-quickstart-maven-project-in-eclipse-ide/

Sample Appium Test

package com.testingdocs.appium.quickstart.AppiumProject;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

/**
 * Sample Appium Test.
 */
public class SampleTest {
  public static AppiumDriver<?> mDriver;

  @BeforeTest
  public void setup( ) throws MalformedURLException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome"); 
    caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.0"); 
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); 
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Androidemulator"); 
    caps.setCapability("avd","Nexus_5X_API_29_x86");
    mDriver = new AppiumDriver<> (new URL("http://127.0.0.1:4723/wd/hub"), caps);
    mDriver.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS);  
  }

  @Test
  public static void titleTest(){
    mDriver.get("https://www.testingdocs.com/");
    Assert.assertEquals(mDriver.getTitle(), "Home | TestingDocs", "Check Title");
  }

  @AfterTest
  public void tearDown( ){
    mDriver.quit();
  }
}

Run the Test

Run As >> TestNG Test

or

Run as  >> Maven test

Test running on the Android virtual machine.

 

Test Logs in Appium Server

 

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>com.testingdocs.appium.quickstart</groupId>
  <artifactId>AppiumProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>AppiumProject</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
  <groupId>io.appium</groupId>
  <artifactId>java-client</artifactId>
  <version>7.3.0</version>
</dependency>
<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>7.1.0</version>
</dependency>
  </dependencies>
</project>

 

Common Error

An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome

Fix:

As shown in the error trace, the test could not find the Chromedriver.exe to run the test on the virtual machine.

 

Appium Tutorials:
https://www.testingdocs.com/appium-tutorials/

For more information on Appium Tool:
http://appium.io/

Exit mobile version