如何从excel表中读取测试数据并使用POI

时间:2015-08-11 22:31:02

标签: java selenium-webdriver apache-poi

我想要实现的方案是将excel表中的数据传递到我的网页并运行测试,并在相同的Excel工作表中将测试用例标记为通过或失败。 到目前为止,我已经成功地将excel表中的数据传递到了wen页面,但未能将testcase标记为pass / fail。我正在使用含有JAVA和POI的硒。我的excel表有3列,我想要第四列,结果是通过或失败。为了测试测试是通过还是失败,我将比较数据是否成功添加其通过其他失败(我可以做)但我即时通讯无法通过或失败写入我的Excel工作表。 我的脚本是

WebDriverWait wait = new WebDriverWait (driver, 400);
FileInputStream IPLinkProFile = new FileInputStream(new File("C:\\Selenium\\Input_Data\\IPLProImport.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(IPLProFile);
XSSFSheet sheet = workbook.getSheet("IPLPro");
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
    {
        String projectName = null;
        Row row = rowIterator.next();
        wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("ctl00_InsertButton")));
        driver.findElement(By.id("ctl00InsertButton")).click();
        wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("ctl00_pname1")));
        driver.findElement(By.id("ctl00_Arrow")).click();
        driver.findElement(By.xpath("//form[@id='form1']//div/ul/li[2]")).click();
        Iterator <Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext())
        {

            Cell cell = cellIterator.next();
            if(cell.getColumnIndex()==0)
            {
                driver.findElement (By.id("ctl00_pname1")).clear();
                driver.findElement (By.id("ctl00_pname1")).sendKeys(cell.getStringCellValue());
            }else if(cell.getColumnIndex()==1)
            {
                driver.findElement(By.id("ctl00_gvhost1")).clear();
                driver.findElement(By.id("ctl00_gvhost1")).sendKeys(cell.getStringCellValue());
            }else if(cell.getColumnIndex()==2)
            {
                driver.findElement(By.id("ctl00_username1")).clear();
                driver.findElement(By.id("ctl00_username1")).sendKeys(cell.getStringCellValue());
            }


            else if(cell.getColumnIndex()==3)
            {
                driver.findElement(By.id("ctl00_gcpass1")).clear();
                driver.findElement(By.id("ctl00_gcpass1")).sendKeys(cell.getStringCellValue());
            }
            else
            {
                break; 
            }

        }
        driver.findElement(By.id("ctl00_btnUpdateImport")).click();
        Thread.sleep(50000);
        driver.switchTo().frame("ImportTest");
        driver.findElement(By.id("form1"));
        driver.findElement(By.id("btnClose")).click();
        }

1 个答案:

答案 0 :(得分:0)

我不认为我们可以实现它,但使用TestNG框架,在运行所有测试用例后,它将自动生成报告。通过TestNG,您可以一次运行所有测试用例,通过它您只能在后期运行失败的测试用例

相关问题