[英]How to write test result(pass/fail) in excel sheet using selenium web driver and java without hard coding row_num and Col_num in my program
[英]How to read test data from excel sheet and provide into webpage and mark test case as pass or fail accordigly in selenium web script using POI
我试图实现的方案是将数据从excel工作表传递到我的网页并运行测试,并在同一excel工作表中将测试用例标记为通过或失败。 到目前为止,我已经成功地将数据从excel表传递到了wen页面,但是未能标记测试用例通过/失败。 我在JAVA和POI中使用硒。 我的excel工作表有3列,我希望第四列的结果是通过或失败。为了测试测试是通过还是失败,我将比较数据是否成功添加,否则通过(我可以这样做),但是im无法通过或失败写入我的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();
}
我认为我们无法实现,但是使用TestNG框架,在运行所有测试用例之后,它将自动生成报告。 通过TestNG,您可以一次运行所有测试用例,并且只能在以后的阶段中运行失败的测试用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.