Table of contents
2. Connect two Android devices or start two virtual machines
3. Create two new testng.xml under the project path
Foreword:
Appium is a popular automated testing tool for mobile applications, which can be used to test Android applications. TestNG is a powerful testing framework that provides rich features and flexible configuration options to help testers write and execute test cases.
1. Test class
package com.testerhome;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
public class Suite1 {
public String port;
public String udid;
private AndroidDriver driver;
@Test
public void switches() throws InterruptedException {
WebElement sound = driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Sound\")");
sound.click();
System.out.println("checked");
Thread.sleep(2000);
System.out.println(Thread.currentThread());
}
@BeforeSuite
@Parameters({ "port", "udid" })
public void beforeSuite(String port, String udid) {
this.port = port;
this.udid = udid;
}
@BeforeClass
public void beforeClass() throws MalformedURLException{
System.out.println(“port is ” + port + “, udid is " + udid);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","device");
capabilities.setCapability("automationName","Appium");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("udid", udid);
capabilities.setCapability("appPackage", "com.android.settings");
capabilities.setCapability("appActivity", ".Settings");
driver = new AndroidDriver(new URL("http://127.0.0.1:" + port + "/wd/hub"), capabilities);
}
@AfterClass
public void afterClass() {
driver.quit();
}
}
2. Connect two Android devices or start two virtual machines
adb devices
Get udid using
3. Create two new testng.xml under the project path
testng1.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite1">
<parameter name = "port" value = "4723"/>
<parameter name = "udid" value = "emulator-5554"/>
<test name="Test">
<classes>
<class name="com.testerhome.Suite1"/>
</classes>
</test>
</suite>
testng2.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite2">
<parameter name = "port" value = "4725"/>
<parameter name = "udid" value = "emulator-5556"/>
<test name="Test">
<classes>
<class name="com.testerhome.Suite1"/>
</classes>
</test>
</suite>
4. Open two appium servers
If the command line starts with parametersappium -p 4723 -bp 4724
appium -p 4725 -bp 4726
If it is a graphical interface, modify:
first:
Port in General Settings, change to 4723
Bootstrap Port in Android Settings, change to 4724
The second one:
Port in General Settings, changed to 4725
Bootstrap Port in Android Settings, changed to 4726
5. Export dependencies
Because it is created with a maven project, first export the dependencies to the lib folder under the project pathmvn dependency:copy-dependencies -DoutputDirectory=lib
6. Execute the test
First execute it serially with Maven to compile the Class file mvn clean test
and then java -classpath ".\target\test-classes" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml
if the TestNG environment variable is not configuredjava -classpath ".\target\test-classes;D:\Programs\testng-6.8\testng-6.8.jar" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml
Seven, view the report
The default test-output folder under the project path
As someone who has been here, I also hope that everyone will avoid some detours
Here I will share with you some necessities of the way forward in automated testing, hoping to help you.
(software testing related materials, automated testing related materials, technical questions and answers, etc.)
I believe it can make you better progress!
Click on the small card below