Run Appium Test on Android Virtual Machine
Run Appium Test on Android Virtual Machine
In this tutorial, you will write and run a sample Appium Test on an Android Virtual machine. We need some dependencies to set up the test project.
Android Studio
Android Studio is Google’s official Android Integrated Development Environment (IDE). It provides tools to help developers create, test, and debug Android applications.
Appium Server
Appium is an open-source tool for automating mobile applications on iOS and Android platforms. It supports native, hybrid, and mobile web applications and provides a unified API to write tests across different devices and operating systems.
Launch the Appium server.
https://www.testingdocs.com/install-appium-desktop-server/
Appium Architecture
Android Virtual Machines
Android Virtual Machine is a software-based emulation of an Android device that runs on your computer. It allows developers to test and debug Android applications in a controlled environment without needing a physical Android device.
Create an Android Virtual machine. You must create a virtual machine using the AVD manager to run the test on it.
Steps to create a virtual device can be found at:
Maven Project
Maven is a build automation tool used for Java projects. It simplifies the build process by managing dependencies, building projects, and generating documentation using a pom.xml configuration XML file.
Create a Maven project.
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:
The error trace shows that the test could not find the Chromedriver.exe to run the test on the virtual machine. Download the compatible Chrome driver file and add it to the project.
Appium Tutorials
Appium Tutorials