我在黄瓜特征文件中执行了一步,以验证状态。如果状态不匹配,则应该使测试脚本失败。在我的代码中,该脚本通过了。
我尝试返回布尔值。但仍然没有运气
然后验证检索日志
@Then("^Validate Retrieving logs$")
public boolean validateRetrievingLogsState() throws IOException {
FileInputStream inputStream = new FileInputStream(file);
wb = new XSSFWorkbook(inputStream);
Sheet sheet = wb.getSheet("Validation");
System.out.println("My required value is : " +
sheet.getRow(1).getCell(2).getStringCellValue());
String ExpectedResult = sheet.getRow(1).getCell(2).getStringCellValue();
if (con.validateStatus(ExpectedResult) != true) {
System.out.println("Here");
return false;
} else {
return true;
}
}
public boolean validateStatus(String ExpectedResult) {
WebElement verifyStatus1 = driver.findElement(By.xpath("//*[@id=\"LRAList:Locomotive_Status\"]/div[3]/table/tbody/tr"));
String verifyStatus = verifyStatus1.getText();
System.out.println("status is" + verifyStatus);
if (verifyStatus.contains(ExpectedResult)) {
System.out.println("We have verified status");
return true;
} else {
reportFailure("We did not verify status pls check the script");
return false;
}
}
结果显示已通过1个方案(已通过1个) 7个步骤(已通过7个步骤)。插入后应显示为失败
答案 0 :(得分:0)
@Then("^Validate Retrieving logs$")
public void validateRetrievingLogsState() throws IOException {
FileInputStream inputStream = new FileInputStream(file);
wb = new XSSFWorkbook(inputStream);
Sheet sheet = wb.getSheet("Validation");
System.out.println("My required value is : " +
sheet.getRow(1).getCell(2).getStringCellValue());
String ExpectedResult = sheet.getRow(1).getCell(2).getStringCellValue();
String ActualResult = con.validateStatus(ExpectedResult);
assertEquals(ExpectedResult, ActualResult);
}
public String validateStatus(String ExpectedResult) {
WebElement verifyStatus1 =
driver.findElement(By.xpath("//*id=\"\"]/div[3]/table/tbody/tr/td[8]"));
String verifyStatus = verifyStatus1.getText();
System.out.println("status is" + verifyStatus);
if (verifyStatus.contains(ExpectedResult)) {
System.out.println("We have verified status");
return verifyStatus;
// return true;
} else {
reportFailure("We did not verify status pls check the script");
return verifyStatus;
}
}