TestNG @dataprovider @factory order execution

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

TestNG @dataprovider @factory order execution

Fabio
Good morning,
I have a problem running my test case, using @dataprovider and @factory.
I read from an excel file (@dataprovider) of the data and with the @factory run various test methods, the problem that the order of execution does not respect the order of how the values are written inside the excel file, but it happens which performs the third value first, then the first and so on ...

is there any way to perform in order of how they are written in the excel file?

thanks

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/44480d45-4744-4ada-95b6-faf4122b4ac8n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: TestNG @dataprovider @factory order execution

⇜Krishnan Mahadevan⇝
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: TestNG @dataprovider @factory order execution

Fabio
Thanks for the answer, I don't think I'm using it ... I'm just trying my hand at it.

do you have any examples to follow?
my spartan code is this

Class Dataprovider read excel file
-------------------------------------------------------
public class InputDataProvider {

    @DataProvider(name = "DatiInput") //(name ="BCBEdata")
    public Object[][] excelDP(ITestContext context) throws IOException {
        String DataSheet=context.getCurrentXmlTest().getParameter("DataSheet");
        System.out.println("Lettura dati di configurazione "+context.getCurrentXmlTest().getParameter("DataSheet"));
        //We are creating an object from the excel sheet data by calling a method that reads data from the excel stored locally in our system
        InputDataProvider inputDataProvider = new InputDataProvider();

        Object[][] arrObj = inputDataProvider.getExcelData(System.getProperty("user.dir") + "\\config\\Pippo.xlsx"
                , Pippo);
        return arrObj;
    }

    //This method handles the excel - opens it and reads the data from the respective cells using a for-loop & returns it in the form of a string array
    public String[][] getExcelData(String fileName, String sheetName){
        String[][] data = null;
        try
        {
            FileInputStream fis = new FileInputStream(fileName);
            XSSFWorkbook wb = new XSSFWorkbook(fis);
            XSSFSheet sh = wb.getSheet(sheetName);
            XSSFRow row = sh.getRow(0);
            int noOfRows = sh.getPhysicalNumberOfRows();
            int noOfCols = row.getLastCellNum();
            Cell cell;
            data = new String[noOfRows-1][noOfCols];
            for(int i =1; i<noOfRows;i++){
                for(int j=0;j<noOfCols;j++){
                    row = sh.getRow(i);
                    cell= row.getCell(j);
                    DataFormatter formatter = new DataFormatter();
                    String cellLettura = formatter.formatCellValue(cell);
//                    String cellLettura = String.valueOf(cell.getStringCellValue());
                    data[i-1][j] = cellLettura;

                }
            }
        }
        catch (Exception e) {
            System.out.println("The exception is: " +e.getMessage());
        }
        return data;
    }

}
-------------------------------------------------------

class test @factory e multi @test

public class RicercaBenestareBCBEDataProvider extends BaseTest {

public String BCBE;
public String TEST1;
public String TEST2;
protected static ConfigurationProperties config;

protected static By versione = By.xpath("//div[@class='container-fluid']//strong[1]");
public static long IDSessione;

// public RicercaBenestareBCBEDataProvider(String BCBE,String TEST1) {
// this.BCBE=BCBE;
// this.TEST1=TEST1;
// }
public RicercaBenestareBCBEDataProvider(String BCBE,String TEST1,String TEST2) {
this.BCBE=BCBE;
this.TEST1=TEST1;
this.TEST2=TEST2;
}

@Factory(dataProvider = "DatiInput",dataProviderClass =  InputDataProvider.class)
static Object [] factorymethod (String BCBE,String TEST1,String TEST2)
{
BCBE=BCBE;
TEST1=TEST1;
TEST2=TEST2;
return new Object[] { new RicercaBenestareBCBEDataProvider(BCBE,TEST1,TEST2) } ;
}

@Test (groups = "windows.checkintest", description = "BenestareBCBE")
public void TestLetturaDati(ITestContext context) throws InterruptedException {
System.out.println(BCBE+" "+TEST1+" "+TEST2);
System.out.println(BrowserName);
System.out.println(System.currentTimeMillis());
IDSessione = System.currentTimeMillis();
System.out.println(IDSessione);
context.setAttribute("IdSessioneTest",IDSessione);
}

@Test (groups = "windows.checkintest" ,dependsOnMethods = "TestLetturaDati", description = "BenestareBCBE")
public void TestFindBCBE() throws InterruptedException {
System.out.println(IDSessione);
SeleniumBCBE = new SeleniumBCBE(driver);
config = new ConfigurationProperties();
SeleniumBCBE.ClickBenestare();
SeleniumBCBE.ClickRicercaBenestare();
//SeleniumBCBE.ClickCampoCodiceBCBE (config.getData("codiceBCBE2"));
SeleniumBCBE.ClickCampoCodiceBCBE(BCBE);
SeleniumBCBE.ClickSubmit();
}
@Test (groups = "windows.checkintest",dependsOnMethods = "TestFindBCBE", description = "VerificaBenestareBCBE")
public void TestVerifySearch () {
System.out.println(IDSessione);
SeleniumBCBERicercaBenestarePage = new SeleniumBCBERicercaBenestarePage(driver);
Assert.assertTrue(SeleniumBCBERicercaBenestarePage.VerificaTabella()>=1);
Assert.assertTrue(SeleniumBCBERicercaBenestarePage.VerificaNumeroBCBE(BCBE));
}

}


Thanks 

Il giorno martedì 23 marzo 2021 alle 14:32:19 UTC+1 Krishnan Mahadevan ha scritto:
Fabio,

Can you please check if you can use an implementation of org.testng.IDataProviderInterceptor to control the order of the instances in which they are instantiated ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


On Wed, Mar 17, 2021 at 2:18 PM Fabio Giusti <[hidden email]> wrote:
Good morning,
I have a problem running my test case, using @dataprovider and @factory.
I read from an excel file (@dataprovider) of the data and with the @factory run various test methods, the problem that the order of execution does not respect the order of how the values are written inside the excel file, but it happens which performs the third value first, then the first and so on ...

is there any way to perform in order of how they are written in the excel file?

thanks

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/44480d45-4744-4ada-95b6-faf4122b4ac8n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/1fb4a4e3-b8d8-40ec-b96f-a19103a167b8n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: TestNG @dataprovider @factory order execution

⇜Krishnan Mahadevan⇝
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: TestNG @dataprovider @factory order execution

Fabio
thanks for the answer and help

Il giorno lunedì 29 marzo 2021 alle 12:42:53 UTC+2 Krishnan Mahadevan ha scritto:
I spent some more time taking a closer look at this.

Unfortunately this is not a straight forward use case because:

  • TestNG uses a Directed Acyclic Graph to build the execution model.
  • Now within the DAG, TestNG always keeps trying to retrieve the next free node that can be picked up for execution.
  • In the case of a Factory driven by a data provider, each of the nodes would be a free node in the DAG and as such any of them can be retrieved to be executed next.
So in a nutshell, your use case is not something that TestNG supports at the moment, to the best of my knowledge.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

On Tue, Mar 23, 2021 at 7:40 PM Fabio Giusti <[hidden email]> wrote:
Thanks for the answer, I don't think I'm using it ... I'm just trying my hand at it.

do you have any examples to follow?
my spartan code is this

Class Dataprovider read excel file
-------------------------------------------------------
public class InputDataProvider {

    @DataProvider(name = "DatiInput") //(name ="BCBEdata")
    public Object[][] excelDP(ITestContext context) throws IOException {
        String DataSheet=context.getCurrentXmlTest().getParameter("DataSheet");
        System.out.println("Lettura dati di configurazione "+context.getCurrentXmlTest().getParameter("DataSheet"));
        //We are creating an object from the excel sheet data by calling a method that reads data from the excel stored locally in our system
        InputDataProvider inputDataProvider = new InputDataProvider();

        Object[][] arrObj = inputDataProvider.getExcelData(System.getProperty("user.dir") + "\\config\\Pippo.xlsx"
                , Pippo);
        return arrObj;
    }

    //This method handles the excel - opens it and reads the data from the respective cells using a for-loop & returns it in the form of a string array
    public String[][] getExcelData(String fileName, String sheetName){
        String[][] data = null;
        try
        {
            FileInputStream fis = new FileInputStream(fileName);
            XSSFWorkbook wb = new XSSFWorkbook(fis);
            XSSFSheet sh = wb.getSheet(sheetName);
            XSSFRow row = sh.getRow(0);
            int noOfRows = sh.getPhysicalNumberOfRows();
            int noOfCols = row.getLastCellNum();
            Cell cell;
            data = new String[noOfRows-1][noOfCols];
            for(int i =1; i<noOfRows;i++){
                for(int j=0;j<noOfCols;j++){
                    row = sh.getRow(i);
                    cell= row.getCell(j);
                    DataFormatter formatter = new DataFormatter();
                    String cellLettura = formatter.formatCellValue(cell);
//                    String cellLettura = String.valueOf(cell.getStringCellValue());
                    data[i-1][j] = cellLettura;

                }
            }
        }
        catch (Exception e) {
            System.out.println("The exception is: " +e.getMessage());
        }
        return data;
    }

}
-------------------------------------------------------

class test @factory e multi @test

public class RicercaBenestareBCBEDataProvider extends BaseTest {

public String BCBE;
public String TEST1;
public String TEST2;
protected static ConfigurationProperties config;

protected static By versione = By.xpath("//div[@class='container-fluid']//strong[1]");
public static long IDSessione;

// public RicercaBenestareBCBEDataProvider(String BCBE,String TEST1) {
// this.BCBE=BCBE;
// this.TEST1=TEST1;
// }
public RicercaBenestareBCBEDataProvider(String BCBE,String TEST1,String TEST2) {
this.BCBE=BCBE;
this.TEST1=TEST1;
this.TEST2=TEST2;
}

@Factory(dataProvider = "DatiInput",dataProviderClass =  InputDataProvider.class)
static Object [] factorymethod (String BCBE,String TEST1,String TEST2)
{
BCBE=BCBE;
TEST1=TEST1;
TEST2=TEST2;
return new Object[] { new RicercaBenestareBCBEDataProvider(BCBE,TEST1,TEST2) } ;
}

@Test (groups = "windows.checkintest", description = "BenestareBCBE")
public void TestLetturaDati(ITestContext context) throws InterruptedException {
System.out.println(BCBE+" "+TEST1+" "+TEST2);
System.out.println(BrowserName);
System.out.println(System.currentTimeMillis());
IDSessione = System.currentTimeMillis();
System.out.println(IDSessione);
context.setAttribute("IdSessioneTest",IDSessione);
}

@Test (groups = "windows.checkintest" ,dependsOnMethods = "TestLetturaDati", description = "BenestareBCBE")
public void TestFindBCBE() throws InterruptedException {
System.out.println(IDSessione);
SeleniumBCBE = new SeleniumBCBE(driver);
config = new ConfigurationProperties();
SeleniumBCBE.ClickBenestare();
SeleniumBCBE.ClickRicercaBenestare();
//SeleniumBCBE.ClickCampoCodiceBCBE (config.getData("codiceBCBE2"));
SeleniumBCBE.ClickCampoCodiceBCBE(BCBE);
SeleniumBCBE.ClickSubmit();
}
@Test (groups = "windows.checkintest",dependsOnMethods = "TestFindBCBE", description = "VerificaBenestareBCBE")
public void TestVerifySearch () {
System.out.println(IDSessione);
SeleniumBCBERicercaBenestarePage = new SeleniumBCBERicercaBenestarePage(driver);
Assert.assertTrue(SeleniumBCBERicercaBenestarePage.VerificaTabella()>=1);
Assert.assertTrue(SeleniumBCBERicercaBenestarePage.VerificaNumeroBCBE(BCBE));
}

}


Thanks 

Il giorno martedì 23 marzo 2021 alle 14:32:19 UTC+1 Krishnan Mahadevan ha scritto:
Fabio,

Can you please check if you can use an implementation of org.testng.IDataProviderInterceptor to control the order of the instances in which they are instantiated ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


On Wed, Mar 17, 2021 at 2:18 PM Fabio Giusti <[hidden email]> wrote:
Good morning,
I have a problem running my test case, using @dataprovider and @factory.
I read from an excel file (@dataprovider) of the data and with the @factory run various test methods, the problem that the order of execution does not respect the order of how the values are written inside the excel file, but it happens which performs the third value first, then the first and so on ...

is there any way to perform in order of how they are written in the excel file?

thanks

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/44480d45-4744-4ada-95b6-faf4122b4ac8n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/d3300b75-62c2-4a1d-bacf-887f23aaececn%40googlegroups.com.