1

in the provided test I need to read the data from the cell in Excel and it works. I would also like to add the functionality to store the price of the product in another cell in the Excel. I've splited that into 2 data providers ("readData" and "writeData"), however I am unable to add the second data provider to the test or I don't how to do that.

Could you please advise how to combine both of them in 1 test? Thank you in advance.

TEST:

public class StandardProductPricingTest{

@BeforeTest
public void setUp() {
    Page.initConfigurationAndLogin();
}

@Test(dataProviderClass = Utilities.class,dataProvider = "readData")
public void standardProductPricingTest(String product) throws InterruptedException, IOException {
    HomePageActions home = new HomePageActions();
    GalleryPageActions galleryPage = new GalleryPageActions();
    PDPageActions pdPage = new PDPageActions();

    home.searchProduct(product);
    galleryPage.clickOnThePicture();
    String price = pdPage.readPrice();
    }
}

DATA PROVIDER:

public class Utilities extends Page {

@DataProvider(name = "readData")
public Object[] getData() {


    String data = excel.ReadCellData(1, 0);


    return new Object[] {data};

}
@DataProvider(name="writeData")
public Object[] writeData(String price){

    String sheetName = "standardproduct";
    String data = excel.getCellData(sheetName, 0, 2);
    System.out.println(data);

    int rowCount = excel.getRowCount(sheetName);
    System.out.println("total rows: " + rowCount);

    excel.setCellData(sheetName, "PDP Price", 2, price);

    return new Object[] {price};
}

}

1
  • 2
    A data provider is aimed at providing test data, only one can be set for each @Test. Why don't you add a call to this writeData function at the end of the test or on the teardown method? – João Farias Jul 22 '20 at 12:41
2

Data Providers are use to pass the Test-Data into the @test .Please create a java member function to write the excel and call directly to your @test instead of using it in /as data provider

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.