Skip to content

Commit 3386f64

Browse files
committed
Avoid using a temporary file to store screenshot after a test failure
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.
1 parent a30323d commit 3386f64

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/main/java/org/jenkinsci/test/acceptance/junit/DiagnosticRule.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.jenkinsci.test.acceptance.junit;
22

33
import jakarta.inject.Inject;
4-
import java.io.File;
54
import java.io.IOException;
5+
import java.nio.file.Files;
66
import java.util.logging.Logger;
7-
import org.apache.commons.io.FileUtils;
87
import org.jenkinsci.test.acceptance.controller.JenkinsController;
98
import org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl;
109
import org.junit.rules.TestWatcher;
@@ -44,10 +43,9 @@ protected void failed(Throwable t, Description description) {
4443

4544
private void takeScreenshot() {
4645
try {
47-
File file = diagnostics.touch("screenshot.png");
48-
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
49-
FileUtils.copyFile(screenshot, file);
50-
46+
Files.write(
47+
diagnostics.touch("screenshot.png").toPath(),
48+
((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES));
5149
} catch (IOException e) {
5250
logger.warning("An error occurred when taking screenshot");
5351
throw new Error(e);

0 commit comments

Comments
 (0)