Этот код для захвата скриншота, но этот код не получает желаемого результата. Я не могу сделать скриншот правильного окна. Мой код инициализирует новый драйвер Chrome, но не получает снимок экрана с этим окном, что мне и требуется.
/----------------------------------take screenshot class--------------------------------/
public class ScreenCapture {
SendMailUsingAuthentication SMUA = new SendMailUsingAuthentication ();
public void takeScreenShot() throws IOException, MessagingException {
String timeStamp;
File screenShotName;
WebDriver driver = new ChromeDriver();
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//The below method will save the screen shot in d drive with name "screenshot.png"
timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
screenShotName = new File("D:\\Manzelinc\\SNST_test_Auto\\Manzel"+timeStamp+".png");
try {
FileUtils.copyFile(scrFile, screenShotName);
SMUA.postMail(SendMailUsingAuthentication.emailList, SendMailUsingAuthentication.emailSubjectTxt, SendMailUsingAuthentication.emailMsgTxt, SendMailUsingAuthentication.emailFromAddress);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/----------------------------Listener class---------------------------------------------------------/
public class ReportGeneration implements ITestListener, IReporter {
WebDriver driver;
SendMailUsingAuthentication SMUA = new SendMailUsingAuthentication ();
public void onStart(ITestContext arg0) {
System.out.println("Start Of Execution(TEST)->"+arg0.getName());
}
public void onTestStart(ITestResult arg0) {
System.out.println("Test Started->"+arg0.getName());
}
public void onTestSuccess(ITestResult arg0) {
System.out.println("Test Pass->"+arg0.getName());
}
public void onTestFailure(ITestResult arg0) {
System.out.println("Test Failed->"+arg0.getName());
//take Screenshot------------------------
ScreenCapture SC = new ScreenCapture();
try {
SC.takeScreenShot();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Reporter.log("<br> <img src=.\\screenshots\\Untitled.png /> <br>");
Reporter.setCurrentTestResult(null);
}