简体   繁体   English

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

[英]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.

相关问题 如何使用 apache poi 和 selenium webdriver 在 excel 文件中写入使用 List 和 Iterator 获得的值 - how to write values obtained using List and Iterator in a excel file using apache poi and selenium webdriver 如何使用java中的selenium webdriver中的apache poi在excel文件中创建新工作表 - How to create a new sheet in an excel file using apache poi in selenium webdriver with java 在Java Apache POI中读取Excel复选框值 - Reading Excel checkbox values in Java Apache POI 使用Apache poi从Java导出后,Excel中没有值 - No values in Excel after exporting from Java using Apache poi 硒webdriver不使用Apache POI将数据写入Excel工作表 - selenium webdriver not writing data into excel sheet using apache poi 无法写入Excel(Selenium WebDriver)-Apache POI - Unable to write to an excel (Selenium WebDriver) - Apache POI 如何使用 Java 中的 Apache POI 在 Excel 的折线图中添加两个以上的 y 轴(垂直)? - How to add more than two y-axis (verticals) to the Line Chart in Excel using Apache POI in Java? Selenium Webdriver-Java-尝试使用Apache POI在Excel中写入数据时出现异常 - Selenium Webdriver - Java - Exception on trying to write data in Excel using Apache POI 使用 Selenium Apache POI Java webdriver 在 setCellValue() 的数据表 excel 中未打印值 - Value is not getting printed in Datasheet excel for setCellValue() using Selenium Apache POI Java webdriver 如何使用Apache POI强制Excel在西班牙语语言环境中显示值 - How to force Excel to display values in Spanish locale using Apache POI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM