0

テストケースが失敗するたびに、スクリーンショットを追加しようとしています。ただし、Windows 環境では成功しましたが、docker/linux 環境では達成できません。

スクリーンショットのコード:

public void testFailure(Failure failure) throws java.lang.Exception 
 {
    Random rand = new Random();
    //Scenario scenario;
     System.out.println("Execution Failure : ");

      try {
            //String screenshotName = failure.getTestHeader().toString();
            int num = rand.nextInt(10000000);
            String screenshotName = "Screenshot"+num;

            /*File sourcePath = ((TakesScreenshot)Homepage.driver).getScreenshotAs(OutputType.FILE);
            File destinationPath = new File(System.getProperty("user.dir") + "/target/CucumberExtentReport/Screenshots/" + screenshotName +".jpeg");
            Files.copy(sourcePath, destinationPath);
            Reporter.addScreenCaptureFromPath(destinationPath.toString());
            */
            final byte[] screenshot = ((TakesScreenshot)Homepage.driver).getScreenshotAs(OutputType.BYTES); 
            File destinationPath = new File(System.getProperty("user.dir") + "/target/CucumberExtentReport/Screenshots/" + screenshotName +".jpeg");
            FileUtils.writeByteArrayToFile(destinationPath, screenshot);
            //Files.copy(sourcePath, destinationPath);
            Reporter.addScreenCaptureFromPath(destinationPath.toString());

        } 
        catch (Exception e) 
        {
            System.out.println(e.toString());
        }
 }

注: 失敗したテストケースのスクリーンショットを追加するために範囲レポートを使用しました...

4

0 に答える 0