如何解决ExtentReport-仅在找不到webelement的情况下捕获屏幕截图
@Beforemethod
public static String getScreenshot(WebDriver driver,String screenshotName) {
String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
TakesScreenshot ts = (TakesScreenshot) driver;
File src = ts.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+ "/FailedTestsScreenshots/"+ screenshotName + dateName + ".png";
File destination = new File(path);
try {
FileUtils.copyFile(src,destination);
}
catch(IOException e){
System.out.println("Capture Failed" +e.getMessage());
}
return path;
}
@Test
public void openWeb() throws IOException,InterruptedException {
fis = new FileInputStream(System.getProperty("user.dir")+"\\resources\\config.properties");
property = new Properties();
property.load(fis);
WebElement UsernameField = driver.findElement(By.name(property.getProperty("username_fieldName")));
WebElement PasswordField = driver.findElement(By.name(property.getProperty("password_fieldName")));
WebElement SubmitButton = driver.findElement(By.xpath(property.getProperty("submit_ButtonXpath")));
//Test case 1 TC_1.01 - opening the login page of the release page
boolean usrfield = UsernameField.isdisplayed();
boolean passfield = PasswordField.isdisplayed();
extentTest = extent.startTest("TC_1.01 - Open the Login screen of the Release page for Admin");
if(usrfield == true && passfield == true) {
extentTest.log(LogStatus.PASS,"Login screen of the Release Page open for Admin");
//extentTest.log(Status.PASS,MarkupHelper.createLabel("Login screen of the Release Page open for Admin",ExtentColor.GREEN));
}
else {
extentTest.log(LogStatus.FAIL,"Login screen of the Release Page is not open for Admin");
}
Thread.sleep(2000);
//Test case 2 TC_1.02 - Check for the language options
//Saving element of language drop down using its name
WebElement Lang_Dropdown = driver.findElement(By.name(property.getProperty("language_DropDownName")));
Lang_Dropdown.click();
Lang_Dropdown.click();
boolean Lang_list = Lang_Dropdown.isdisplayed();
extentTest = extent.startTest("TC_1.02 - Check for the language options");
if(Lang_list == true) {
extentTest.log(LogStatus.PASS,"Dropdown list of multiple Languages display");
}
else {
extentTest.log(LogStatus.FAIL,"Dropdown list of multiple Languages is not display");
}
Thread.sleep(2000);
//Test case 3 TC_1.03 - Verify the Selection of a Language
Select Lang = new Select(driver.findElement(By.name(property.getProperty("language_DropDownName"))));
Lang.selectByVisibleText("SPA");
//language is not getting selected by below line.
//driver.findElement(By.xpath(property.getProperty("languageDropdown_ListXpath"))).click();
extentTest = extent.startTest("TC_1.03 - Verify the selection of a language from the dropdown list");
if(Lang_Dropdown.getText().contains("SPA")) {
extentTest.log(LogStatus.PASS,"Selected language display in the dropdown field");
}
else {
extentTest.log(LogStatus.FAIL,"Selected language is not display in the dropdown field");
}
@AfterMethod
public void tearDown(ITestResult result) {
if(result.getStatus() == ITestResult.FAILURE) {
extentTest.log(LogStatus.FAIL,"Test case Failed" + result.getName());
extentTest.log(LogStatus.FAIL,"Test case Failed" + result.getThrowable());
String screenshotPath = TestCycle1.getScreenshot(driver,result.getName());
extentTest.log(LogStatus.FAIL,extentTest.addScreenCapture(screenshotPath));
}
else if(result.getStatus() == ITestResult.SKIP) {
extentTest.log(LogStatus.SKIP,"Test case skipped" + result.getName());
}
else if(result.getStatus() == ITestResult.SUCCESS) {
extentTest.log(LogStatus.PASS,"Test case Passed" + result.getName());
}
extent.endTest(extentTest);
driver.quit();
}
@AfterTest
public void endReport() {
extent.flush();
//extent.close();
}
执行上面的代码时,我没有收到任何错误,测试成功运行,由于实现的条件,测试用例出现了一些失败,但是我的范围报告中没有任何截图。当测试用例由于网页上找不到元素而失败时,范围报告中仅显示一个屏幕截图。 那么,由于某些条件或由于找不到元素,如何获取所有失败的测试用例的所有屏幕截图??? 任何建议将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。