Screenshot in TestNG Report
Code Here :
public class ff extends SeleneseTestBase {
public WebDriver driver;
StringBuffer verificationErrors=new StringBuffer();
@Test
public void test2() throws InterruptedException {
try{
driver.findElement(By.xpath("//*[@id='containerrrr']/div[2]/h2"));
}catch(Throwable t)
{
verificationErrors.append(t.getMessage());
Reporter.log("object not found"+"<br>");
//Take screen shot and give path in the report
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("C:\\1.jpg"));
Reporter.log("<a href=\"" +"file:///C:/1.jpg" + "\">Screenshot</a>"); // give path in the report
}
//System.out.println(driver.findElement(By.id("gbqfba")).isDisplayed());
clearVerificationErrors();
if (!"".equals(verificationErrors.toString()))
fail(verificationErrors.toString());
}
}
No comments:
Post a Comment