Тёмный

TestNG Framework - Data Driven Testing using Apache POI - Excel 

QA University
Подписаться 2,3 тыс.
Просмотров 3,6 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 7   
@taken00071
@taken00071 4 года назад
thanks what i am looking for but i get null exception XSSFCell cell = row.getCell(j); (its print till the last row )
@taken00071
@taken00071 4 года назад
package AppConifiguration; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; import io.github.bonigarcia.wdm.WebDriverManager; public class datadynamic { public static FileInputStream fis; public static FileOutputStream fos; WebDriver driver; String url= "dc.designcollection.in/codecanyon/gsrf-google-sheet-registration-form/registration-from-5.html?ref=designcollection"; @Test public void br() { WebDriverManager.chromedriver().setup(); //WebDriverManager.firefoxdriver().setup(); driver = new ChromeDriver(); driver.manage().window().maximize(); //log.info("open project url"); driver.get(url); driver.findElement(By.xpath("//*[@id=\"testform\"]/div[1]/div[1]/div/input")); } @Test public void data_driven() throws IOException, InterruptedException { fis = new FileInputStream("E:\\book1.xlsx"); XSSFWorkbook wk = new XSSFWorkbook(fis); XSSFSheet sheet = wk.getSheet("Sheet1"); //row count int rownum = sheet.getLastRowNum() +1; //coulmn count int colnum = sheet.getRow(0).getLastCellNum(); // string array variable String [][] data = new String[rownum][colnum]; for (int i = 0; i < rownum; i++) { XSSFRow row = sheet.getRow(i); for (int j = 0; j < colnum; j++) { XSSFCell cell = row.getCell(j); String value= cell.toString(); data [i][j]= value; System.out.println("the value is" + " " + value); } } fos.flush(); fos.close(); } resultthe value is fulll name the value is last name the value is Company name the value is note the value is State the value is city the value is country the value is occupation the value is Email the value is Mobile number the value is DOB the value is Zip code the value is gender the value is are uexisitng customer the value is agree(Yes/No) the value is abc the value is labc the value is cabc the value is nabc the value is abc the value is labc the value is cabc the value is nabc the value is abc the value is labc the value is cabc the value is nabc the value is labc the value is cabc the value is nabc the value is abc 2 the value is abc 2l the value is abc 2C the value is abc 2n the value is abc the value is labc the value is cabc the value is nabc the value is abc the value is labc the value is cabc the value is nabc the value is labc the value is cabc the value is nabc the value is abc 3 the value is abc 2l the value is abc 2C the value is abc 2n the value is abc the value is labc the value is cabc the value is nabc the value is abc the value is labc the value is cabc the value is nabc the value is labc the value is cabc the value is nabc PASSED: br FAILED: data_driven java.lang.NullPointerException at AppConifiguration.datadynamic.data_driven(datadynamic.java:55)
@karthikmanoharan6794
@karthikmanoharan6794 7 лет назад
while running this script using testing framwork,. In the first iteration, value is taking as null null
@QAUniversity
@QAUniversity 7 лет назад
you can send the script, i will analyze and let you know!!
@karthikmanoharan6794
@karthikmanoharan6794 7 лет назад
package SeleniumScript; import java.io.File; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class Datadrivenng { public WebDriver driver; @BeforeMethod public void openbrowser(){ System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\SELENIUM WEBDRIVER\\Gecko\\geckodriver-v0.16.1-win64\\geckodriver.exe"); driver=new FirefoxDriver(); } @Test(dataProvider = "Testdata") public void login(String x, String y) { driver.get("www.facebook.com"); driver.findElement(By.id("email")).sendKeys(x); driver.findElement(By.id("pass")).sendKeys(y); driver.findElement(By.id("u_0_q")).click(); } @AfterMethod public void Close() { driver.quit(); } @DataProvider(name = "Testdata") public Object [][] ReadExcel() throws IOException { File f = new File("C:\\Users\\krith\\Desktop\\Selenium IDE\\Data.xls"); POIFSFileSystem fi = new POIFSFileSystem(f); HSSFWorkbook wb = new HSSFWorkbook(fi); HSSFSheet s= wb.getSheet("Sheet1"); int rownum = s.getLastRowNum()+1; int colnum = s.getRow(1).getLastCellNum(); String [][] data = new String [rownum][colnum]; for(int i=1;i
@karthikmanoharan6794
@karthikmanoharan6794 7 лет назад
package SeleniumScript; import java.io.File; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class Datadrivenng { public WebDriver driver; @BeforeMethod public void openbrowser(){ System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\SELENIUM WEBDRIVER\\Gecko\\geckodriver-v0.16.1-win64\\geckodriver.exe"); driver=new FirefoxDriver(); } @Test(dataProvider = "Testdata") public void login(String x, String y) { driver.get("www.facebook.com"); driver.findElement(By.id("email")).sendKeys(x); driver.findElement(By.id("pass")).sendKeys(y); driver.findElement(By.id("u_0_q")).click(); } @AfterMethod public void Close() { driver.quit(); } @DataProvider(name = "Testdata") public Object [][] ReadExcel() throws IOException { File f = new File("C:\\Users\\krith\\Desktop\\Selenium IDE\\Data.xls"); POIFSFileSystem fi = new POIFSFileSystem(f); HSSFWorkbook wb = new HSSFWorkbook(fi); HSSFSheet s= wb.getSheet("Sheet1"); int rownum = s.getLastRowNum()+1; int colnum = s.getRow(1).getLastCellNum(); String [][] data = new String [rownum][colnum]; for(int i=1;i
@karthikmanoharan6794
@karthikmanoharan6794 7 лет назад
is there any update
Далее
TestNG Failed Test cases re-execution in selenium
7:19
Страшная Тайна Светы Кемер !
33:04
Think Fast, Talk Smart: Communication Techniques
58:20
Mastering Chaos - A Netflix Guide to Microservices
53:14
Dynamic memory allocation
36:28
Просмотров 2,5 тыс.
Playwright Beginner Tutorial 4 | How to write 1st Test
24:54