如何比较Excel中的两个或两个以上的值与值中的李和报告通过或失败在同一个Excel中使用Apache poi selenium webdriver Java

我需要从Excel中导入2个或更多的值,并比较我在我的里面的值,我使用的代码是

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中的值没有得到增加,也就是说,如果从Excel中的第一个值是abc和abc与li1中的值是比较abc,说通过,并为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(); } }