使用Test NG对每次迭代的序列中的每个测试运行不同的数据集

时间:2017-12-06 04:31:19

标签: java selenium-webdriver testng

预期行为

我希望这里的重点是为每次迭代按顺序迭代每个测试的数据集,这样所有的测试都应该用第一组数据运行,然后是第二组,直到第二组为止。结束

public class SampleFactory {
DataGenerators dataGen;

@Factory(dataProvider="dp")
public Object[] createInstances(String country, String email, String firstName, String securityQuestion, String title, String ccyFrom, String ccyTo) {
    return new Object[] {new PersonalRegoTest(country, email, firstName, securityQuestion, title, ccyFrom, ccyTo)};
}

@DataProvider(name="dp")
public static Object[][] dataProvider() {
   // dataGen = new DataGenerators();

    Object[][] dataArray = {
            {"country1", "test@testmail.com","abc", "Model", "Mr", "AUD", "USD"},
            {"country2", "test1@testmail.com","abcd", "Model", "Mr", "USD", "NZD"}
    };
    return dataArray;
}
}

我的PersonalRegoTest如下

public class PersonalRegoTest extends Appium {
PersonalRego personalRego;
DataGenerators dataGen;
String country="";
String email="";
String firstName="";
String securityQuestion="";
String title="";
String ccyFrom="";
String ccyTo="";`

PersonalRegoTest(String country, String email, String firstName, String 
securityQuestion, String title, String ccyFrom, String ccyTo) {
    super();
    this.country = country;
    this.email = email;
    this.firstName = firstName;
    this.securityQuestion = securityQuestion;
    this.title = title;
    this.ccyFrom = ccyFrom;
    this.ccyTo = ccyTo;
}
@BeforeClass(alwaysRun = true)
public void initialize() throws IOException {
    personalRego = new PersonalRego(driver, System.getProperty("platform"));
    dataGen = new DataGenerators();
}
@Test(priority = 1, alwaysRun=true, description="select of Personal Rego form", groups="personalRego")
public void verifyPersonalRegoPageWindow() {
    personalRego.isPersonalRegoWindowDisplayed();
}
@Test(priority = 2, alwaysRun=true, description = "fill step 1 of Personal Rego form", groups="personalRego")
public void validateAndCompletePersonalRegoForm_FirstPage() {
    ...
}
@Test(priority = 3, alwaysRun=true, description = "fill step 2 of Personal Rego form", groups="personalRego", dependsOnMethods = "validateAndCompletePersonalRegoForm_FirstPage")
public void validateAndCompletePersonalRegoForm_SecondPage() {
    ...
}
@Test(priority = 4, alwaysRun=true, description = "fill step 3 of Personal Rego form", groups="personalRego", dependsOnMethods = {"validateAndCompletePersonalRegoForm_FirstPage", "validateAndCompletePersonalRegoForm_SecondPage"})
public void validateAndSubmitPersonalRegoForm_ThirdPage() {
   ...
}
@Test(priority = 5, alwaysRun=true, description = "Last step of Personal Rego form to reset app", groups="personalRego", dependsOnMethods = {"validateAndSubmitPersonalRegoForm_ThirdPage"})
public void resetApplication(String reset) {
    System.out.println("reset application ");
    ..
}

PFA与之前的结果相似。如果我现在做错了,请告诉我

当前问题: 我的测试运行如下

verifyPersonalRegoPageWindow
verifyPersonalRegoPageWindow(1)
validateAndCompletePersonalRegoForm_FirstPage
validateAndCompletePersonalRegoForm_FirstPage(1)
validateAndCompletePersonalRegoForm_SecondPage
validateAndCompletePersonalRegoForm_SecondPage(1)
.. 

预期结果

Iteration - 1
verifyPersonalRegoPageWindow
validateAndCompletePersonalRegoForm_FirstPage
validateAndCompletePersonalRegoForm_SecondPage
..

Iteration - 2
verifyPersonalRegoPageWindow
validateAndCompletePersonalRegoForm_FirstPage
validateAndCompletePersonalRegoForm_SecondPage
..

当我被击中时,有人可以提出建议吗?

1 个答案:

答案 0 :(得分:0)

这是针对所选国家的E2E测试。所需要的只是删除每个测试中的优先级,只需dependOnMethods即可解决此问题。