1

i have a scenario where in im calling a method(which has code to create workflow - defined in pages POM framework), i have written a generic method to get the data from excel file using dataProvider in testNG

Now i have a @Test method which perform the action of creating the workflow as below

@DataProvider(name="wf")
public static String[][] getExcelData() throws Exception{

    ExcelReader read = new ExcelReader();
        String filePath = "path of excelfile";
      return read.getCellData(filePath, "Sheet1");
    }

@Test(dataProviderClass = ExcelReader.class, dataProvider="wf")
        public void testing(String workflow, String type, String unit){

            System.out.println("-------------Test case started -------------");
            System.out.println("Call to login to the application");
            System.out.println("Navigating to Some Page");
            System.out.println("Navigating to WorkflowPage");

            SampleClass s = new SampleClass();
            s.createWorkflow(workflow,type,unit);

            System.out.println("-----'--------Test case Ended ----------------");
            System.out.println();   

        }

public void createWorkflow(String wf, String wf, String unit){

        System.out.println("Creating WF");

        System.out.println(wf);
        System.out.println(type);
        System.out.println(unit);

        System.out.println("CREATED wf");
    }

now if i run the @Test fails after creating the 1st workflow, becoz the @test method is run again from beginning instead of creating multiple workflow's, for 'createWorkflow method.

Can you let me know how can i achieve this or a better solution.

Grasshopper
  • 8,908
  • 2
  • 17
  • 32
Raghu Hoskote
  • 117
  • 2
  • 14
  • Move the navigation code to a BeforeClass or BeforeTest method to run once. Any code to run afterwards move to AfterClass or AfterTest... – Grasshopper Apr 16 '18 at 13:57
  • @Grasshopper.....Thanks, it worked. Just want to check if this the right way of using the dataProvider. – Raghu Hoskote Apr 17 '18 at 12:52

1 Answers1

0
      @BeforeMethod
       public void beforeMethod(){
           System.out.println("Call to login to the application");
           System.out.println("Navigating to Some Page");
           System.out.println("Navigating to WorkflowPage");
      }

    @Test(dataProviderClass = ExcelReader.class, dataProvider="wf")
    public void testing(String workflow, String type, String unit){

        System.out.println("-------------Test case started -------------");

        SampleClass s = new SampleClass();
        s.createWorkflow(workflow,type,unit);

        System.out.println("-----'--------Test case Ended ----------------");
        System.out.println();   

    }

public void createWorkflow(String wf, String wf, String unit){

    System.out.println("Creating WF");

    System.out.println(wf);
    System.out.println(type);
    System.out.println(unit);

    System.out.println("CREATED wf");
}
Pritam Maske
  • 2,670
  • 2
  • 22
  • 29