1

Can we follow the below method to initialise the test data? There are 2 points I want to implement.

  1. Need to initialise/load the test data once from the file and use the same test data in all dataproviders.Thought to implement test data loader in @beforesuite class.
  2. Need data from dataprovider and a parameter from testNG file at the same time in @test method.

    @BeforeSuite
    @Parameters(value = { "test_data_file" })
    public static synchronized void init(String test_data_file) {
        TestDataFactory.load(test_data_file);       
    }    
    @Test(dataProvider="dp_dummy",dataProviderClass = DP_1.class)
    public void testDummyAPI(TestData test_data,ITestContext context){
        String param = context.getCurrentXmlTest().getParameter("param");
    }        
    @DataProvider(name = "dp_dummy")
    public Object[][] getDataFromDataprovider(ITestContext context) {    
        List<TestData> test_data_collection = TestDataFactory.getTestData(targated_test_data);
        Object[][] test_data_set = new Object[test_data_collection.size()][1];    
        for(TestData test_data : test_data_collection)
            test_data_set[i++][0] = test_data;    
         return test_data_set;}
    
Naveen
  • 1,441
  • 2
  • 16
  • 41
gurchet
  • 11
  • 2

1 Answers1

0

Assuming you are creating your test_data_set correctly you can achieve your second point like this

 @Test(dataProvider="dp_dummy",dataProviderClass = DP_1.class)
    public void testDummyAPI( String p, Object[][] ob){
      System.out.println(p);      
      System.out.println(ob[0][0]);

    }   

    @DataProvider(name = "dp_dummy")
    public Object[][] getDataFromDataprovider(ITestContext context) {    
        List<TestData> test_data_collection = TestDataFactory.getTestData(targated_test_data);
        Object[][] test_data_set = new Object[test_data_collection.size()][1];    
        for(TestData test_data : test_data_collection)
            test_data_set[i++][0] = test_data;    
          String param = context.getCurrentXmlTest().getParameter("param");

           return new Object[][] {

               { param,  test_data_set}
           };
    }
user1207289
  • 3,060
  • 6
  • 30
  • 66