0

So I have two tests, one that check the sign up "test01_signIn", if it's 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.
(only one iteration of Test2)

While I'm looking for a result like this:
Test1
Test2
Test1
Test2

0

You can do it with @Factory annotation and group-by-instances parameter in TestNG;

@Factory(dataProvider="dp")
public Object[] createDataProviderInstances(int id) {
    return new Object[] {new TestClass(id)};
}

And in the testng xml file;

< !DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="LocalSuite" verbose="1">
    <test name="NameOfTest" group-by-instances="true">
        <classes>
            <class name="package.name.TestClass"></class>
        </classes>
    </test>
</suite>

Find the detailed example in here

| improve this answer | |
  • Thank you for your answer, but i have one issue with it, it keeps opening multiple chrome windows for each test, i have 170 lines in my data sheet, which means 170 window, this will cook my pc, is there a way i can open them in the same window ? – Xerox9000 May 17 at 14:46
  • Why do you run same test01_signIn() for each test02_CheckNewsStandElements()? Are the signed in credentials different in each test? Chrome driver intitated for each test in data sheet means; driver inititation is done inside the test01_signIn(). **To run all tests in a single browser instance; ** 1. Remove driver inititation from the test01_signIn() and put inside a new method. Add BeforeSuite annotation to it. 2. Then create a sign out method and add AfterClass annotation – kaweesha May 17 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.