JavaApp自动化测试系列[v1.0.0][Appium并行测试]

tech2022-08-06  146

并行测试

Appium提供了一种方式以在一台设备上自动操作多个会话,也就是采用多个标识符的方式启动多个Appium服务器端从而实现测试并行执行,例如启动两个Appium服务器,第一个服务器Server Port设置为4723,Bootstrap Port设置为4724;第二个服务器Server Port设置为4725,Bootstrap Port设置为4726

提取Desired Capabilities

package org.davieyang; public class Constants { public class RedMi3{ public static final String deviceName = "Redmi3"; public static final String udid = "claeae297d72"; public static final String platformVersion = "5.1.1"; public static final String platformName = "Android"; public static final String appPackage = "io.selendroid.testapp"; public static final String appActivity = ".HomeScreenActivity"; public static final String unicodeKeyboard = "True"; public static final String noSign = "True"; } public class RedMi4{ public static final String deviceName = "Redmi4"; public static final String udid = "claeae297d73"; public static final String platformVersion = "6.1.1"; public static final String platformName = "Android"; public static final String appPackage = "io.selendroid.testapp"; public static final String appActivity = ".HomeScreenActivity"; public static final String unicodeKeyboard = "True"; public static final String noSign = "True"; } }

测试代码

package org.davieyang.testscripts; import java.net.URL; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; import org.testng.Assert; import org.davieyang.Constants; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class TestParallelRunDemo1 { AndroidDriver<AndroidElement> driver; @BeforeMethod @Parameters({"device_ID", "port"}) public void setUp() throws Exception{ // Desired Capabilities; // Define driver } @Test public void testWebApp(){ System.out.println("TestScripts"); } @AfterMethod public void TearDown(){ driver.quit(); } }
package org.davieyang.testscripts; import java.net.URL; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; import org.testng.Assert; import org.davieyang.Constants; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.NoSuchElementException; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Parameters; import org.testng.annotations.Test; import org.openqa.selenium.By; public class TestParallelrundemo2 { AndroidDriver<AndroidElement> driver; @BeforeMethod @Parameters({"device_ID", "port"}) public void setUp() throws Exception{ // Desired Capabilities; // Define driver } @Test public void testWebApp(){ System.out.println("TestScripts"); } @AfterMethod public void TearDown(){ driver.quit(); } }

配置testng.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="All Test Suite" parallel="tests" thread-count="2"> <test verbose="2" preserve-order="true" name="parallelRunDemo1"> <parameter name="device_ID" value="127.0.0.1"/> <parameter name="port" value="4723"/> <classes> <class name="org.davieyang.testscripts.TestParallelRunDemo1"> <methods> <include name="testWebApp"/> </methods> </class> </classes> </test> <test verbose="2" preserve-order="true" name="parallelRunDemo2"> <parameter name="device_ID" value="127.0.0.1"/> <parameter name="port" value="4725"/> <classes> <class name="org.davieyang.testscripts.TestParallelrundemo2"> <methods> <include name="testWebApp"/> </methods> </class> </classes> </test> </suite>
最新回复(0)