gpt4 book ai didi

java - 如何使用 apache poi selenium webdriver java 将 excel 中的两个或多个值与 li 中的值进行比较并报告同一 excel 中的通过或失败

转载 作者:太空宇宙 更新时间:2023-11-04 14:19:28 24 4
gpt4 key购买 nike

我需要从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`

一旦我得到下一个值,Excel的值就不会增加,也就是说,如果Excel中的第一个值是abc,并且abc与li1中的值(即abc)进行比较,并说pass,并且for i1 for循环获取 li2 值作为 xyz 但单元格值仍然是 abc ,我希望单元格值为 xyz ,以便我可以将单元格的 xyz 值与 li2 中的值进行比较

最佳答案

请引用下面的示例程序来比较 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();


}


}

关于java - 如何使用 apache poi selenium webdriver java 将 excel 中的两个或多个值与 li 中的值进行比较并报告同一 excel 中的通过或失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27356139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com