Skip to content

Commit

Permalink
Merge pull request #1855 from Vlatombe/avoid-temporary-file-for-scree…
Browse files Browse the repository at this point in the history
…nshot

Avoid using a temporary file to store screenshot after a test failure
  • Loading branch information
jglick authored Dec 4, 2024
2 parents 5d9a9ce + 3386f64 commit ad3e0ee
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 ad3e0ee

Please # to comment.