我正在尝试第一次将 TestNG 与 @Factory 一起使用,但对我来说不起作用,我会告诉你为什么。
我有一个名为 Extend 的类,其中我有一些测试,“启动站点”,“登录”,“检查用户是否在他自己的仪表板中”等等,我希望对于从工厂传递的所有数据,这些命令测试总是相同的“启动站点”>>“登录”>>“检查用户在他的仪表板中”>>“注销”好吗?所以我有以下extend.xml 文件和类:
<suite name="ExtendFactory" group-by-instances="true">
<test name="Factory" preserve-order="true" group-by-instances="true">
<classes>
<class name="net.whaooo.ExtendFactory">
<methods>
<include name="launchSite"></include>
<include name="loginTest" />
<include name="userIsInHisOwnDashboardTest" />
<include name="logoutTest" />
</methods>
</class>
</classes>
</test>
</suite>
扩展类:
public class Extend extends BaseTest{
protected static FirefoxDriver driver;
private String a_driver;
private String password;
public Extend(String a_driver, String pwd){
this.a_driver = a_driver;
this.password = pwd;
}
@BeforeTest
public void stDriver() {
DesiredCapabilities caps = DesiredCapabilities.firefox(); caps.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new FirefoxDriver(caps);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterTest
public void stopDriver() {
driver.close();
}
@Test
public void launch() {
launchSite(driver);
}
@Test (description = "Enter a valid login as driver")
public void loginTest() {
login(driver, a_driver, password);
}
@Test (description = "Check the driver is in his own dashboard")
public void userIsInHisOwnDashboardTest(){
userIsInHisOwnDashboardTest(driver, a_driver, password);
}
@Test(description="logout")
public void logout(){
logoutTest(driver);
}
}
简化工厂:
public class ExtendFactory {
@Factory
public Object[] createInstances() {
Object[] result = new Object[2];
result[0] = new Extend("test1@test.com","tester");
result[1] = new Extend("test2@test.com","tester");
return result;
}
}
但我的问题是,即使我插入子句 preserve-order="true" group-by-instances="true",启动测试的顺序也不遵循 xml 文件中指定的顺序,我也试过了使用 order-by-instances="true"。谁能帮我?