I am using testNG framework and tried to import data from excel sheet in my local. If I run the code as simple java application then its running but with testNG its not
public class NewTest {
public String strFirstName ="";
public String strLastName="";
public String strEmail="";
@BeforeSuite
public static void main (String args[]) throws InterruptedException{
try {
// Open the Excel file
// Access the required test data sheet
FileInputStream fi = new FileInputStream("E:/som/Book2.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fi);
XSSFSheet sheet = workbook.getSheetAt(0);
// Loop through all rows in the sheet
// Start at row 1 as row 0 is our header row
for(int count = 0;count<=sheet.getLastRowNum();count++){
XSSFRow row = sheet.getRow(count);
System.out.println("Running test case " + row.getCell(0).toString());
// Run the test for the current test data row
runtest(row.getCell(0).toString(),row.getCell(1).toString(),
row.getCell(2).toString());
}
fi.close();
} catch (IOException e) {
System.out.println("Test data file not found");
}
}
@Test
public static void runtest(String strFirstName, String strLastName,
String strEmail) throws InterruptedException {
System.setProperty("webdriver.chrome.driver",
"E:/som/chromedriver/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://<code>192.168.1.33:8081</code>/serosoft-academia-testing/");
System.out.println("Page title is: " + driver.getTitle());
driver.findElement(By.id("button-1055-btnIconEl")).click();
driver.findElement(By.id("ext-comp-1079-btnInnerEl")).click();
driver.findElement(By.id("button-1089-btnIconEl")).click();
driver.findElement(By.id("ext-gen1804")).click(); // Enquiry Type
Thread.sleep(1000);
driver.findElement(By.xpath(".//*[@id='boundlist-1534-
listEl']/ul/li[1]")).click();
Thread.sleep(2000);
driver.findElement(By.id("ext-gen1812")).click(); // Referer type
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[@id='boundlist-
1536']/div/ul/li[1]")).click();
Thread.sleep(2000);
driver.findElement(By.id("ext-gen1822")).click(); // Enquiry Registered
// by
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[@id='boundlist-
1538']/div/ul/li[1]")).click();
Thread.sleep(2000);
driver.findElement(By.id("textfield-1482-inputEl")).sendKeys(strFirstName); // Enquirer
// first
// name
driver.findElement(By.id("textfield-1485-inputEl")).sendKeys(strLastName); // enquirer
// last
// name
driver.findElement(By.id("ext-gen1825")).click(); // country
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[@id='boundlist-1540']/div/ul/li[1]")).click();
Thread.sleep(2000);
driver.findElement(By.id("ext-gen1827")).click(); // city
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[@id='boundlist-1542']/div/ul/li[1]")).click();
driver.findElement(By.id("textfield-1497-inputEl")).sendKeys(strEmail); // email
And here is the error I am getting: