Исключение нулевого указателя при создании снимка экрана в PMS селена с отчетом по экстенту - PullRequest
0 голосов
/ 24 апреля 2019

Возникает исключение нулевого указателя при попытке сделать снимок экрана при сбое сценария.У меня есть класс действий, в котором я осквернил метод скриншота захвата.

public static String capture(WebDriver driver) throws NullPointerException, IOException {
    File scrFile;
    scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    File Dest = new File("D:\\Dinu\\SeleniumReports\\Test" + System.currentTimeMillis() + ".jpeg");
    String filepath = Dest.getAbsolutePath();
    org.openqa.selenium.io.FileHandler.copy(scrFile, Dest);
    return filepath;
}

Отчеты по экстентам реализованы с использованием интерфейса Itestlisterner.Ниже приведен код, для которого реализуется метод скриншота, приведенный ниже:

public synchronized void onTestFailure(ITestResult result) {
    System.out.println((result.getMethod().getMethodName() + " failed!"));
    test.get().fail(result.getThrowable());
    try {
        String screenshotPath = actions.capture(driver);
        test.get().addScreenCaptureFromPath(screenshotPath);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

И я получаю приведенную ниже ошибку: Пожалуйста, помогите в решении той же.enter image description here

1 Ответ

0 голосов
/ 24 апреля 2019
public static String getScreenhot(WebDriver driver, String screenshotName) throws Exception {
 String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
 TakesScreenshot ts = (TakesScreenshot) driver;
 File source = ts.getScreenshotAs(OutputType.FILE);
                //after execution, you could see a folder "FailedTestsScreenshots" under src folder
 String destination = System.getProperty("user.dir") + "/FailedTestsScreenshots/"+screenshotName+dateName+".png";
 File finalDestination = new File(destination);
 FileUtils.copyFile(source, finalDestination);
 return destination;
 }


@AfterMethod
     public void getResult(ITestResult result) throws IOException{
     if(result.getStatus() == ITestResult.FAILURE){
     logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getName());
     logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getThrowable());
     //To capture screenshot path and store the path of the screenshot in the string "screenshotPath"
                            //We do pass the path captured by this mehtod in to the extent reports using "logger.addScreenCapture" method. 
                            String screenshotPath = ExtentReportsClass.getScreenshot(driver, result.getName());
     //To add it in the extent report 
     logger.log(LogStatus.FAIL, logger.addScreenCapture(screenshotPath));
     }else if(result.getStatus() == ITestResult.SKIP){
     logger.log(LogStatus.SKIP, "Test Case Skipped is "+result.getName());
     }
     // ending test
     //endTest(logger) : It ends the current test and prepares to create HTML report
     extent.endTest(logger);
     }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...