[英]TestNG : Go to the next test after one iteration of dataProvider
So I have 2 Tests, one that check the sign up test01_signIn
, if its a PASS, it goes to the the second test test02_CheckNewsStandElements
, which checks the visibility of an element of the homepage, the only issue is that the first Test has a DataProvider like the following:所以我有2个测试,一个检查注册
test01_signIn
,如果它通过,它会进入第二个测试test02_CheckNewsStandElements
,它检查主页元素的可见性,唯一的问题是第一个测试有一个 DataProvider如下所示:
@Test(dataProvider = "Data")
public void test01_signIn(String idMedia, String nomMedia, String idSSO, String mdpSSO, String lien) {
//Test
}
@Test
public void test02_CheckNewsStandElements(){
WebDriverWait wait = new WebDriverWait(driver,5);
WebElement modalCloseButton = null;
modalCloseButton = nsp.modalCloseButton(driver);
try{
wait.until(ExpectedConditions.visibilityOf(modalCloseButton));
}catch(TimeoutException e){
System.out.println("The Element isn't visible");
}
}
@DataProvider(name="Data")
public Object [][] getLists() throws IOException, GeneralSecurityException {
Object [][] objects = newEDLI.importData().clone();
return objects;
}
The results I get are more like:我得到的结果更像:
Test1
Test1
Test1
...
Test2
Test2
Test2
While I'm looking for a result like this:虽然我正在寻找这样的结果:
Test1 Test2 Test1 Test2
When you inject data into the test method using @DataProvider
TestNg will run this method in a row as many times as many data you have.当您使用
@DataProvider
TestNg 将数据注入到测试方法中时,该方法将连续运行该方法的次数是您拥有的数据的两倍。 Also, there are no dependencies between your test methods.此外,您的测试方法之间没有依赖关系。 Hence, your
test01_signIn
executes independently from test02_CheckNewsStandElements
.因此,您的
test01_signIn
独立于test02_CheckNewsStandElements
执行。
You may consider using @Factory
to organize the execution order.您可以考虑使用
@Factory
来组织执行顺序。 In this case, you inject data into the test class constructor (data provider should be static), and you are able to manage the order of your test methods execution:在这种情况下,您将数据注入测试 class 构造函数(数据提供者应该是静态的),并且您可以管理测试方法的执行顺序:
public class FactoryTest {
private String idMedia;
private String nomMedia;
// .. rest of your data
@Factory(dataProvider = "Data")
public FactoryTest(String idMedia, String nomMedia, ...) {
this.idMedia = idMedia;
this.nomMedia = nomMedia;
// set the rest of your fields
}
@DataProvider(name = "Data")
public static Object[] getList() {
return newEDLI.importData().clone();
}
@Test
public void test01_signIn() {
// use data from class members
}
@Test(dependsOnMethods = "test01_signIn")
public void test02_CheckNewsStandElements() {
WebDriverWait wait = new WebDriverWait(driver,5);
WebElement modalCloseButton = null;
modalCloseButton = nsp.modalCloseButton(driver);
try{
wait.until(ExpectedConditions.visibilityOf(modalCloseButton));
}catch(TimeoutException e){
System.out.println("The Element isn't visible");
}
}
}
Note: although the tests will be executed in the correct order, in the test report they will still be grouped and sorted.注意:虽然测试会以正确的顺序执行,但在测试报告中它们仍然会被分组和排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.