运行 TestNG Selenium App 中的并行测试
Running parallel test in TestNG Appium Selenium
我有 windows 7,它连接到两个 android 设备,我正在使用 Selenium 和 Appium 来自动化应用程序,但无法同时在两个 运行 测试设备。下面是我使用的代码以及来自 testng.xml 的内容。让我知道我哪里错了。下面的代码 运行 没问题,但它将应用程序安装在第一台设备上,然后在第二台设备上,我想要实现的是同时在两台设备上安装应用程序。任何帮助表示赞赏。
包 ca.automation.com;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import io.appium.java_client.android.AndroidDriver;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Whosebug {
WebDriver driver1;
WebDriver driver2;
// ExtentReports report;
// ExtentTest logger;
// Boolean present;
File app = new File("App\app_US_IT_Ananta.apk");
@BeforeSuite
public void startReport(){
// report=new ExtentReports("C:\Anuj\MobileAppResults.html");
}
@Test (priority =0)
public void installapp() {
// logger=report.startTest("VerifyAppInstalltion");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("udid", "1015fadb1a274005");
// capabilities.setCapability("udid", "ee92ba92");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("autoAcceptAlerts", true);
capabilities.setCapability("app", app.getAbsolutePath());
try {
driver1 = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test (priority =0)
public void installapp1() {
DesiredCapabilities capabilities1 = new DesiredCapabilities();
capabilities1.setCapability("udid", "ee92ba92");
capabilities1.setCapability("deviceName","Android Emulator");
capabilities1.setCapability("platformVersion", "4.4");
capabilities1.setCapability("autoAcceptAlerts", true);
capabilities1.setCapability("app", app.getAbsolutePath());
try {
driver2 = new AndroidDriver(new URL("http://127.0.0.1:4730/wd/hub"), capabilities1);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
Testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="2">
<test name="Test">
<classes>
<class name="ca.automation.com.Whosebug"/>
</classes>
</test> <!-- Test -->
将 parallel="tests"
更改为 parallel="methods"
因为您必须并行执行这些方法,就像您的情况一样。
此外,运行 并行测试不会完全 100% 同时执行。两种设备的执行之间会有一些滞后。通过几个额外的步骤尝试一个完整的脚本。这样我们就可以很容易地看出测试是同时 运行。
我有 windows 7,它连接到两个 android 设备,我正在使用 Selenium 和 Appium 来自动化应用程序,但无法同时在两个 运行 测试设备。下面是我使用的代码以及来自 testng.xml 的内容。让我知道我哪里错了。下面的代码 运行 没问题,但它将应用程序安装在第一台设备上,然后在第二台设备上,我想要实现的是同时在两台设备上安装应用程序。任何帮助表示赞赏。
包 ca.automation.com;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import io.appium.java_client.android.AndroidDriver;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Whosebug {
WebDriver driver1;
WebDriver driver2;
// ExtentReports report;
// ExtentTest logger;
// Boolean present;
File app = new File("App\app_US_IT_Ananta.apk");
@BeforeSuite
public void startReport(){
// report=new ExtentReports("C:\Anuj\MobileAppResults.html");
}
@Test (priority =0)
public void installapp() {
// logger=report.startTest("VerifyAppInstalltion");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("udid", "1015fadb1a274005");
// capabilities.setCapability("udid", "ee92ba92");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("autoAcceptAlerts", true);
capabilities.setCapability("app", app.getAbsolutePath());
try {
driver1 = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test (priority =0)
public void installapp1() {
DesiredCapabilities capabilities1 = new DesiredCapabilities();
capabilities1.setCapability("udid", "ee92ba92");
capabilities1.setCapability("deviceName","Android Emulator");
capabilities1.setCapability("platformVersion", "4.4");
capabilities1.setCapability("autoAcceptAlerts", true);
capabilities1.setCapability("app", app.getAbsolutePath());
try {
driver2 = new AndroidDriver(new URL("http://127.0.0.1:4730/wd/hub"), capabilities1);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
Testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="2">
<test name="Test">
<classes>
<class name="ca.automation.com.Whosebug"/>
</classes>
</test> <!-- Test -->
将 parallel="tests"
更改为 parallel="methods"
因为您必须并行执行这些方法,就像您的情况一样。
此外,运行 并行测试不会完全 100% 同时执行。两种设备的执行之间会有一些滞后。通过几个额外的步骤尝试一个完整的脚本。这样我们就可以很容易地看出测试是同时 运行。