我正在使用Selenium和TestNG编写一些测试,其中有一个起点(登录屏幕)可以分析不同的场景。例如以下测试
我遇到的问题是TestNG在运行“选择选项1”的子测试之前运行“选择选项1”然后“选择选项2”。我想要的是TestNG以深度优先顺序而不是宽度优先运行测试。
LoginTestNG.java
@ContextConfiguration(value = {"classpath:selenium-test.xml"})
public class LoginTestNG extends AbstractTestNGSpringContextTests {
@Test(groups = {"connect"})
public void connect(ITestContext context) {
System.out.println("Connect to URL");
}
@Test(groups = {LOGIN_FAILURE_GROUP}, dependsOnGroups = {"connect"}, priority = 0)
public void loginFailure(ITestContext context) {
System.out.println("Login failure");
}
@Test(groups = {LOGIN_SUCCESS_GROUP}, dependsOnGroups = {"connect"}, priority = 1)
public void loginSuccess(ITestContext context) {
System.out.println("Login Succes");
}
}
Option1TestNG.java(Option2TestNG.java目前是Option1TestNG.java的副本,数字已更改)
@ContextConfiguration(value = {"classpath:selenium-test.xml"})
public class Option1TestNG extends AbstractTestNGSpringContextTests {
@Test(groups = { "OPTION_1_GROUP" }, dependsOnGroups = { LoginTestNG.LOGIN_SUCCESS_GROUP })
public void selectOption1(ITestContext context) {
System.out.println("Option 1");
}
@Test(groups = { APPLICANT_FAILURE}, dependsOnGroups = {CREDIT_REPORTS_GROUP}, priority = 0)
public void submitApplicantWithoutSettingFields(ITestContext context) {
System.out.println("Option 1 submit applicant no fields set");
}
@Test(groups = { APPLICANT_SUCCESS}, dependsOnGroups = {CREDIT_REPORTS_GROUP}, priority = 1)
public void submitApplicantSettingFields(ITestContext context) {
System.out.println("Option 1 submit applicant success");
System.out.println("Go back to home page");
}
}