0

我正在使用 Selenium 和 TestNG 编写一些测试,其中,我有一个起点(登录屏幕),它分为不同的场景。例如以下测试

  • 登录测试
    • 主页测试
      • 选择选项 1
        • 选项 1 测试
      • 选择选项 2
        • 选项 2 测试

我遇到的问题是 TestNG 在运行“选择选项 1”的子测试之前运行“选择选项 1”然后“选择选项 2”。我想要的是 TestNG 以深度优先而不是广度优先的顺序运行测试。

登录测试NG.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");
  }
}
4

1 回答 1

0

编写(和使用)自定义方法拦截器是更好地控制执行顺序的方法。

于 2013-06-11T05:50:41.623 回答