gpt4 book ai didi

java - iOS - 一段时间后,并行执行仅在两个设备之一中继续

转载 作者:行者123 更新时间:2023-11-29 13:56:34 24 4
gpt4 key购买 nike

我想在两个不同的 iOS 设备上并行执行我的 appium 测试用例。我面临的问题是在并行执行一些测试用例之后,一段时间后一个设备被卡住,只有另一个设备继续执行既适用于该设备又适用于另一个设备的测试用例并不断失败。

我正在创建 2 个 appium 服务器实例并通过 testng.xml 文件传递​​设备参数。

如有任何帮助,我们将不胜感激。

测试.xml

`
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite" verbose="3" parallel="tests" thread-
count="2">
<test name="Rapporter-1" preserve-order="true">
<!--<parameter name="testEnv" value="iOS Test Env"/>-->
<parameter name="platform" value="iOS 12.1.3"/>
<parameter name="udid" value="deviceudid"/>
<parameter name="deviceName" value="iPhone 8 Plus"/>
<parameter name="wdaLocalPort" value="8100"/>
<parameter name="url" value="http://0.0.0.0:4723/wd/hub"/>
<classes>
<!--Test classes with single login credentials-->
<class name="com.rapporter.test.AddEditDeleteCommentTest"/>
<!--other classes listed-->
</classes>
</test>
<test name="Rapporter-2" preserve-order="true">
<parameter name="platform" value="iOS 12.1.2"/>
<parameter name="udid" value="device2udid"/>
<parameter name="deviceName" value="iPhone XS Max"/>
<parameter name="wdaLocalPort" value="8101"/>
<parameter name="url" value="http://0.0.0.0:4734/wd/hub"/>
<classes>
<class name="com.rapporter.test.SearchTest"/>
<!--other classes listed-->
</classes>
</test>
<!-- Rapporter -->
</suite> <!-- Default Suite -->
`

所有被测类通用的前两个函数

`
@BeforeTest(alwaysRun = true)
@Parameters({"platform", "udid", "deviceName",
"wdaLocalPort","url"})
public void setup1(String platform, String udid, String
deviceName,
String wdaLocalPort,String url) throws Exception {

File file = new File("./app/App1.ipa");
String absolutePath = file.getAbsolutePath();
String[] platformInfo = platform.split(" ");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,
"XCUITest");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,
platformInfo[0]);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,
platformInfo[1]);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,
deviceName);
capabilities.setCapability(MobileCapabilityType.UDID, udid);
capabilities.setCapability("wdaLocalPort", wdaLocalPort);
capabilities.setCapability("app", absolutePath);
capabilities.setCapability("url",url);
capabilities.setCapability(MobileCapabilityType.ORIENTATION,
"PORTRAIT");
capabilities.setCapability(MobileCapabilityType.NO_RESET, false);
try {
driver = new IOSDriver(new URL(url),capabilities);
} catch (Exception e) {
System.out.println("Failed to setup Appium server");
}
}


@Parameters({"platform", "udid", "deviceName", "wdaLocalPort","url"})
@Test(priority = 1,
description = "GIVEN I am a Dubber app user <br/>"
+ "WHEN I launch the app and enter my login
credentials <br/> "
+ "THEN I should be successfully logged in and should
be navigated to Home screen")

public void loginWithValidCredentials(String platform, String udid,
String deviceName, String wdaLocalPort,String url) throws
InterruptedException, ParseException, java.text.ParseException,
IOException
{
String username = "appium" + apiMethods.randomCharacters(5) +
"@playback.com";
String firstname = apiMethods.randomCharacters(6);
apiMethods.postUserTrial(username,
firstname,platform,udid,deviceName,wdaLocalPort,url); //This goes to
Chrome browser and creates a new user
UtilityClass.loginWithValidCredentialsTrial(username,
Constants.Env.PASSWORD,platform,udid,deviceName,wdaLocalPort,url);
}
`

在此之后,应用程序启动(直到那时没有一个设备测试用例超过另一个或卡住的问题),然后我面临上述问题。

接下来的代码用于验证不同的 UI 元素。例如:

`
driver.findElementByAccessibilityId(LoginPage.appIcon);
driver.findElementByAccessibilityId(uname).clear();
driver.findElementByAccessibilityId(uname).sendKeys(username);
driver.findElementByAccessibilityId(psswd).clear();
driver.findElementByAccessibilityId(psswd).sendKeys(password);
driver.findElementByAccessibilityId(login).click();
Thread.sleep(5000);
if (AppiumSupportLibrary.isElementExists(driver, skipButton, 3,
2000)) {
AppiumSupportLibrary.tap(driver, skipButton, 5, 2000);
}
else
System.out.println("TouchId setup screen not found");
Thread.sleep(5000);
if (AppiumSupportLibrary.isElementExists(driver, skipButton, 3,
2000)) {
AppiumSupportLibrary.tap(driver, skipButton, 5, 2000);
}
else
System.out.println("OnboardScreen Tutorial not found");
`

最佳答案

我解决了我一直面临的问题。我在代码片段中引用的驱动程序

`
driver.findElementByAccessibilityId(LoginPage.appIcon);
driver.findElementByAccessibilityId(uname).clear();
driver.findElementByAccessibilityId(uname).sendKeys(username);
driver.findElementByAccessibilityId(psswd).clear();
driver.findElementByAccessibilityId(psswd).sendKeys(password);
driver.findElementByAccessibilityId(login).click();
Thread.sleep(5000);
if (AppiumSupportLibrary.isElementExists(driver, skipButton, 3,
2000)) {
AppiumSupportLibrary.tap(driver, skipButton, 5, 2000);
}
else
System.out.println("TouchId setup screen not found");
Thread.sleep(5000);
if (AppiumSupportLibrary.isElementExists(driver, skipButton, 3,
2000)) {
AppiumSupportLibrary.tap(driver, skipButton, 5, 2000);
}
else
System.out.println("OnboardScreen Tutorial not found");
`

被声明为静态的,这就是为什么我在 2 个设备中并行执行测试用例时遇到问题。在测试工作正常之前全局声明驱动程序并获取它的实例。

`
@BeforeTest(alwaysRun = true)
@Parameters({"platform", "udid", "deviceName", "wdaLocalPort","url"})
public void setup1(String platform, String udid, String deviceName, String wdaLocalPort,String url) throws Exception {

driver = GetDTrial.getInstance1().setDriverTrial(platform, udid, deviceName, wdaLocalPort, url);
homePage = new HomePage(driver);

}
`

关于java - iOS - 一段时间后,并行执行仅在两个设备之一中继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55351310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com