I have a test case that is looping 400+ times with different inputs from the excel spreadsheet. Currently, this is one big test case and I want to make different test cases with the same loop.

Is this possible? I want that loop to have 400 different results for each time it goes in the loop. How would this be possible?

  • 2
    Why are you looping 400+ times using UI tests? If you're just changing input values, this would be better ran as unit tests. It would run faster.
    – Lee Jensen
    Commented Aug 10, 2020 at 17:48

2 Answers 2


Whatever the reason - if you check for 400 things in a loop you can only find 1 defect at a time because your test will throw an assertion error.

I suggest using something like DataProvider from TestNG:

@DataProvider Marks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.

This means that your test case will run as many times as it is necessary, based on the returned data from data provider and failures will be logged for every occurrence, not just once.


you can use TestNG annotation @dataprovider (It will keep running your @test with different set of Test-Data).

Please find the below code snippet:

    public Object[][] loginData() {
        Object[][] arrayObject = getExcelData("D:/sampledoc.xls","Sheet1");
        return arrayObject;

Utility to read the data from excel Using Apache poi:-

public String[][] getExcelData (String excelPath, String sheetName) 
        String[][] arrayExcelData = null;
            fis=new FileInputStream(excelPath);

            workbook=new XSSFWorkbook(fis);


            int totalNoOfCols = sheet.getRow(1).getLastCellNum();

            int totalNoOfRows = sheet.getLastRowNum();

            arrayExcelData = new String[totalNoOfRows-1][totalNoOfCols];

            for (int i= 1 ; i < totalNoOfRows; i++) {

                for (int j=0; j < totalNoOfCols; j++) {

                arrayExcelData[i-1][j] =sheet.getCell(j,i).getContents();
} catch (FileNotFoundException e) {
        } catch (IOException e) {

        return arrayExcelData;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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