0

I have written the following testcase using TestNG but it is skipping the MakemyTrip test case. I have no clue why.There are no dependencies and the test data is kept at the right path.

Why TestNG is not executing it?

public class Secattempt {
    static FileInputStream fis;
    static XSSFWorkbook workbook;
    static XSSFSheet sheet;
    static XSSFRow row;
    static XSSFCell cell;

    @Test(dataProvider = "getData")
    public void MakemytripHome(String departCity, String destCity, String browser) throws AWTException {
        Robot robo = new Robot();
        WebDriver driver;

        if (browser.equals("firefox")) {
            driver = new FirefoxDriver();
        } else {
            System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver_win32\\chromedriver.exe");
            driver = new ChromeDriver();
        }

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("http://www.makemytrip.com/");

        WebElement Depart = driver.findElement(By.id("from_typeahead1"));
        WebElement Dest = driver.findElement(By.id("to_typeahead1"));
        Depart.clear();
        Depart.sendKeys(departCity);
        robo.keyPress(KeyEvent.VK_ENTER);
        Dest.sendKeys(destCity);
        robo.keyPress(KeyEvent.VK_ENTER);
        driver.findElement(By.id("flights_submit")).click();
    }

    @SuppressWarnings("null")
    @DataProvider
    public Object[][] getData() throws IOException {
        Object data[][] = null;
        fis = new FileInputStream("D:\\selenium\\data.xlsx");
        workbook = new XSSFWorkbook(fis);
        sheet = workbook.getSheetAt(0);
        row = sheet.getRow(1);

        int rowcount = sheet.getLastRowNum() - sheet.getFirstRowNum() + 1;
        int colcount = row.getLastCellNum();

        for (int rnum = 2; rnum <= rowcount; rnum++) {
            row = sheet.getRow(rnum);
            for (int cnum = 0; cnum < colcount; cnum++) {
                cell = row.getCell(cnum);
                data[rnum - 2][cnum] = cell.getStringCellValue();
            }
        }

        return data;
    }
}
Andrew Regan
  • 5,087
  • 6
  • 37
  • 73

2 Answers2

0

I am expecting this is because you are not initialized the data object. that is the reason data is null. Use below one before for loop

  data=new Object[rowcount][colcount];

Please remove this @SuppressWarnings("null"), it will show data as null without above code. rather than suppressing, good to figure it out the issue.

Thank You, Murali

murali selenium
  • 3,847
  • 2
  • 11
  • 20
0

You are trying to return Null from the dataprovider as data[][] is not initialized to anything. You need to use below code:

Object data[][] = null;
        fis = new FileInputStream("D:\\selenium\\data.xlsx");
        workbook = new XSSFWorkbook(fis);
        sheet = workbook.getSheetAt(0);
        row = sheet.getRow(1);

        int rowcount = sheet.getLastRowNum() - sheet.getFirstRowNum() + 1;
        int colcount = row.getLastCellNum();
        data=new Object[rowcount][colcount];
        for (int rnum = 2; rnum <= rowcount; rnum++) {
            row = sheet.getRow(rnum);
            for (int cnum = 0; cnum < colcount; cnum++) {
                cell = row.getCell(cnum);
                data[rnum - 2][cnum] = cell.getStringCellValue();
            }
        }

        return data;

Observe the line data=new Object[rowcount][colcount]; This should get you to run that tests

Mrunal Gosar
  • 4,595
  • 13
  • 48
  • 71