Reputation: 64
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 :
@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
Upvotes: 0
Views: 420
Reputation: 1099
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. Also, there are no dependencies between your test methods. Hence, your test01_signIn
executes independently from test02_CheckNewsStandElements
.
You may consider using @Factory
to organize the execution order. 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:
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.
Upvotes: 1