【发布时间】:2016-10-22 08:50:01
【问题描述】:
我正在尝试创建一个 testNG 套件,用于在多个设备上同时使用 Appium 运行测试。我目前正在使用@BeforeSuite 为每个设备设置服务器/驱动程序,然后使用@BeforeMethod 和@AfterMethod 函数将连接分配给测试方法。我有一个主套件 .xml,它调用与我的每个测试类关联的不同子 .xml 文件。每个测试类都与一个@Factory 相关联,它允许我并行运行实例(在运行时根据连接设备的数量决定)。
家长
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
<parameter name="other" value="@SOMETHING@"></parameter>
<suite-files>
<suite-file path="src/first.xml" />
<suite-file path="src/second.xml" />
</suite-files>
</suite>
儿童
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="first" parallel="instances">
<test name="android">
<classes>
<class name="TestFactory" />
</classes>
</test>
</suite>
工厂
public class TestFactory {
@Factory
public Object[] initial() {
int numDevices = DeviceManager.getNumAttachedDevices();
Object[] result = new Object[numDevices];
for (int i = 0; i < numDevices; i++) {
result[i] = new StartupTest();
}
return result;
}
}
我绝对不想这样做。我需要为我想要的每个测试类创建一个新的@Factory 类,这似乎很荒谬。我最近发现我可以在@DataProvider 中使用parallel=true,它可以与paralell="methods" 和invocationCount 的注释转换器一起使用,以获得类似的结果(一个方法为每个附加的设备)。
我不确定我的 @BeforeMethod 和 @AfterMethod 调用如何用于在正确的设备上进行所需的设置和清理(它们会丢失设备名称)。有没有其他推荐的方法来做到这一点?或者这是我最好的选择?
【问题讨论】:
标签: parallel-processing structure testng appium