Skip to content

Commit

Permalink
Avoid using a temporary file to store screenshot after a test failure
Browse files Browse the repository at this point in the history
Temporary files are created with 600, differing from defined umask.
For the screenshot file that is later attached as diagnostic, this can cause permission issues in some environments.
  • Loading branch information
Vlatombe committed Dec 3, 2024
1 parent a30323d commit 3386f64
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.jenkinsci.test.acceptance.junit;

import jakarta.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.test.acceptance.controller.JenkinsController;
import org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl;
import org.junit.rules.TestWatcher;
Expand Down Expand Up @@ -44,10 +43,9 @@ protected void failed(Throwable t, Description description) {

private void takeScreenshot() {
try {
File file = diagnostics.touch("screenshot.png");
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, file);

Files.write(
diagnostics.touch("screenshot.png").toPath(),
((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES));
} catch (IOException e) {
logger.warning("An error occurred when taking screenshot");
throw new Error(e);
Expand Down

0 comments on commit 3386f64

Please sign in to comment.