[英]how to compare two or more values in excel with values in li and report pass or fail in same excel using apache poi selenium webdriver java
I need to import 2 or more values from excel and compare the value which i have in my li's , the code i have used is 我需要从excel导入2个或更多值,并比较我在li的值中,我使用的代码是
FileInputStream input=new FileInputStream(new File("TestCase.xls"));
HSSFWorkbook workbook=new HSSFWorkbook(input);
HSSFSheet sheet=workbook.getSheet("KeywordFramework");
System.out.println("i am in");
int rowNum = sheet.getLastRowNum() + 1;
System.out.println(rowNum);
int colNum = sheet.getRow(0).getLastCellNum();
System.out.println(colNum);
String data [][] = new String[rowNum][colNum];
for(int i =1 ; i< rowNum;i++)
{
System.out.println("1");
HSSFRow row = sheet.getRow(i);
for(int j = 0; j<= colNum;j++)
{
System.out.println("2");
HSSFCell cell = row.getCell(j);
String Cellvalue = cellToString(cell);
System.out.println("cellvalue === "+Cellvalue);
switch(j)
{
`case 1:
case 2:
ExpectedOP=Cellvalue;
System.out.println("Expected output (value to be compared) = "+ExpectedOP);
int LastRow = 1;
List <WebElement> we = driver.findElements(By.xpath(".//*[@id='stepList']/li"));//Getting list of elements in steplist ul
for(int i1=2;i1<=we.size();i1++)
{
String sr [] =new String [10];
sr [i1]=driver.findElement(By.xpath(".//*[@id='stepList']/li["+i1+"]")).getText().trim();//Getting required li text data (example : abc)
for (String j1:sr)
{
if(j1 != null)
{
String [] parts = sr [i1].split("/");//Spliting to get the required data
String parta = parts [0].trim();//Triming the whitespaces
System.out.println("Step value = "+parta);
if(ExpectedOP.equals(parta))//Comparing value in Excel with value got in excel
{
System.out.println("compare pass");
String status="PASS";
[Write into excel];
break;
}
else
{
System.out.println("compare pass");
String status="Fail";
[Write into excel];
break;
}//Close else
}//Close if j1 null
}//Close for j1
}//Close i1 for loop
}//Close Switch(j)
}}}//Close the rest`
The value of Excel is not getting incremented once i get the next value , ie, say if the first value from excel was abc and abc is compared with the value in li1 which is abc and say pass , and for i1 for loop gets li2 value as xyz but still the cellvalue will be abc , i want the cell value to be xyz so that i can compare xyz value of cell with value in li2 一旦我获得下一个值,Excel的值就不会增加,即说是否来自excel的第一个值是abc,并且将abc与li1中的值abc并说pass进行比较,并且对于i1 for循环获取li2值作为xyz,但单元格值仍为abc,我希望单元格值为xyz,以便我可以将单元格的xyz值与li2中的值进行比较
Please refer below sample program to compare value from excel with site console output : 请参考下面的示例程序,以将excel中的值与站点控制台输出进行比较:
//CALL FIREFOX DRIVER TO OPEN IT
WebDriver driver = new FirefoxDriver();
driver.get("http://en.wikipedia.org/wiki/Software_testing");
String title = driver.getTitle();
System.out.println(title);
FileInputStream input = new FileInputStream("D:\\sel.xls");
int count=0;
HSSFWorkbook wb = new HSSFWorkbook(input);
HSSFSheet sh = wb.getSheet("sheet1");
HSSFRow row = sh.getRow(count);
String data = row.getCell(1).toString();
System.out.println(data);
FileOutputStream webdata = new FileOutputStream ("D:\\sel.xls");
if(title.equals(data))
{
row.createCell(10).setCellValue("TRUE");
wb.write(webdata);
}
else
{
row.createCell(11).setCellValue("FALSE");
wb.write(webdata);
}
driver.close();
wb.close();
input.close();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.