For UI part please click here For excel sheet click hereUnable to provide row-wise data in test cases. I have tried below code. Data provider used for fetching the data from excel. Unlimited Data can be under excel sheet.
@DataProvider
public static Object[][] ReadVariant() throws IOException
{
FileInputStream fileInputStream= new
FileInputStream(file_location);
//Excel sheet file location get mentioned here
workbook = new XSSFWorkbook (fileInputStream); //get my workbook
worksheet=workbook.getSheetAt(0);// get my sheet from workbook
XSSFRow Row=worksheet.getRow(0);//get my Row which start from 0
SheetName= worksheet.getSheetName();
int RowNum = worksheet.getPhysicalNumberOfRows();
c1 = RowNum-1;
str2 = Integer.toString(c1);
System.out.println("Total Row available:" +RowNum);
// count my number of Rows
int ColNum= Row.getLastCellNum(); // get last ColNum
Object Data[][]= new Object[RowNum-1][ColNum]; // pass my count data
in array
for(int i=0; i<RowNum-1; i++)
//Loop work for Rows
{
XSSFRow row= worksheet.getRow(i+1);
for (int j=0; j<ColNum; j++) //Loop work for colNum
{
if(row==null)
Data[i][j]= "";
else
{
XSSFCell cell= row.getCell(j);
if(cell==null)
Data[i][j]= ""; //if it get Null value it pass no data
else
{
String value=formatter.formatCellValue(cell);
Data[i][j]=value;
This formatter get my all values as string i.e integer, float all type data value
}
}
}
}
return Data;
}
Mentioned about the test that needs to perform.
@Test //Test method
(dataProvider="ReadVariant") //It get values from ReadVariant function
method
//Here my all parameters from the excel sheet are mentioned.
public void AddVariants(String Qty, String ProductName, String Price)
throws Exception
{
//For the first row
driver.findElement(By.id("s2id_form_inventory_item_id")).click();
Thread.sleep(1000);
driver.findElement(By.id("s2id_autogen3_search")).sendKeys(ProductName
+Keys.ENTER);
Product name entered
Thread.sleep(1000);
driver.findElement(By.id("form_quantity")).sendKeys(Qty);
Thread.sleep(1000);
driver.findElement(By.id("form_price")).sendKeys(Price);
//All values entered in first row
Thread.sleep(3000);
//For second row
driver.findElement(By.id("s2id_form_inventory_item_id1")).click();
Thread.sleep(1000);
driver.findElement(By.id("s2id_autogen4_search")).sendKeys(ProductName
+Keys.ENTER);
Thread.sleep(1000);
driver.findElement(By.id("form_quantity1")).sendKeys(Qty);
Thread.sleep(1000);
driver.findElement(By.id("form_price1")).sendKeys(Price);
able to enter the first UI row but unable to enter the second-row data in second UI rows.
So please suggest how to deal with this.