Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用apache poi selenium webdriver java将excel中的两个或多个值与li中的值进行比较,并报告同一excel中的通过或失败_Java_Excel_Selenium_Apache Poi - Fatal编程技术网

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

如何使用apache poi selenium webdriver java将excel中的两个或多个值与li中的值进行比较,并报告同一excel中的通过或失败,java,excel,selenium,apache-poi,Java,Excel,Selenium,Apache Poi,我需要从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 ro

我需要从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中的值进行比较,li1中的值是abc,并且say pass,对于i1 for loop,li2的值是xyz,但cellvalue仍然是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();


}


}

您是否将excel值与网站值进行比较?或者这两个值都在excel的不同列中?我正在比较excel值和网站值,但我需要从excel中获取2个值,所以我使用案例1:案例2:因为li有2个值,应该与excel文件中的2个值进行比较,但为什么不使用1个单元格进行1个li比较?是的,它应该使用1个单元格进行1个li,使用第二个单元格进行第二个li,并显示结果通过/失败,如果第一个失败,则不应比较第二个值,它应从机箱中制动并转到下一个控制OK,那么问题出在哪里?与Excel相比,还是写EXCEL?请考虑包含一些关于您的答案的信息,而不是简单地发布代码。我们努力提供的不仅仅是“修复”,而是帮助人们学习。您应该解释原始代码中的错误,您做了哪些不同的事情,以及为什么更改有效。