|
44 | 44 | @RobotKeywords
|
45 | 45 | public class ScreenCapturing extends TestFxAdapter {
|
46 | 46 |
|
47 |
| - @RobotKeyword("Sets whether to log images into the log.html file or not.\n\n" |
48 |
| - + "Argument ``value`` is a string. Accepted values are \"on\" and \"off\". They can be given in uppercase as well. \n\n" |
| 47 | + @RobotKeyword("Sets whether to embed log images directly into the log.html file or as a link to a file on local disk.\n\n" |
| 48 | + + "Argument ``value`` is a string. Accepted values are ``embedded`` (initial value) and ``diskonly``. They can be given in uppercase as well. \n\n" |
49 | 49 | + "\nExample:\n"
|
50 |
| - + "| Set Image Logging | OFF |\n") |
| 50 | + + "| Set Image Logging | DISKONLY |\n") |
51 | 51 | @ArgumentNames({ "value" })
|
52 | 52 | public void setImageLogging(String value) {
|
53 |
| - if (value.toLowerCase().equals("on")) |
54 |
| - TestFxAdapter.logImages = true; |
55 |
| - else if (value.toLowerCase().equals("off")) |
56 |
| - TestFxAdapter.logImages = false; |
| 53 | + if (value.toLowerCase().equals("embedded")) |
| 54 | + TestFxAdapter.logImages = "embedded"; |
| 55 | + else if (value.toLowerCase().equals("diskonly")) |
| 56 | + TestFxAdapter.logImages = "diskonly"; |
57 | 57 | else
|
58 | 58 | throw new JavaFXLibraryNonFatalException("Value \"" + value + "\" is not supported! Value must be either " +
|
59 |
| - "\"ON\" or \"OFF\""); |
| 59 | + "\"EMBEDDED\" or \"DISKONLY\""); |
60 | 60 | }
|
61 | 61 |
|
62 | 62 | @RobotKeywordOverload
|
63 | 63 | public Object captureImage(Object locator){
|
64 |
| - return captureImage(locator, TestFxAdapter.logImages); |
| 64 | + return captureImage(locator, true); |
65 | 65 | }
|
66 | 66 |
|
67 | 67 | @RobotKeyword("Returns a screenshot of the given locator.\n\n"
|
@@ -89,17 +89,24 @@ public Object captureImage(Object locator, boolean logImage){
|
89 | 89 | robotContext.getCaptureSupport().saveImage(image, path);
|
90 | 90 |
|
91 | 91 | if (logImage) {
|
92 |
| - Image resizedImage = resizeImage(image, path); |
93 |
| - Path tempPath = Paths.get(getCurrentSessionScreenshotDirectory(), "temp.png"); |
94 |
| - robotContext.getCaptureSupport().saveImage(resizedImage, tempPath); |
| 92 | + Double printSize = targetBounds.getWidth() > 800 ? 800 : targetBounds.getWidth(); |
95 | 93 |
|
96 |
| - File imageFile = convertToJpeg(tempPath); |
97 |
| - byte[] imageBytes = IOUtils.toByteArray(new FileInputStream(imageFile)); |
98 |
| - String encodedImage = Base64.getEncoder().encodeToString(imageBytes); |
99 |
| - imageFile.delete(); |
| 94 | + if(TestFxAdapter.logImages.toLowerCase().equals("embedded")) { |
| 95 | + Image resizedImage = resizeImage(image, path); |
| 96 | + Path tempPath = Paths.get(getCurrentSessionScreenshotDirectory(), "temp.png"); |
| 97 | + robotContext.getCaptureSupport().saveImage(resizedImage, tempPath); |
100 | 98 |
|
101 |
| - Double printSize = targetBounds.getWidth() > 800 ? 800 : targetBounds.getWidth(); |
102 |
| - System.out.println("*HTML* <img src=\"data:image/png;base64," + encodedImage + "\" width=\"" + printSize + "px\">"); |
| 99 | + File imageFile = convertToJpeg(tempPath); |
| 100 | + byte[] imageBytes = IOUtils.toByteArray(new FileInputStream(imageFile)); |
| 101 | + String encodedImage = Base64.getEncoder().encodeToString(imageBytes); |
| 102 | + imageFile.delete(); |
| 103 | + |
| 104 | + RobotLog.html("<img src=\"data:image/png;base64," + encodedImage + "\" width=\"" + printSize + "px\">"); |
| 105 | + |
| 106 | + } else { |
| 107 | + // diskonly option |
| 108 | + RobotLog.html("<img src=\"" + path + "\" width=\"" + printSize + "px\">"); |
| 109 | + } |
103 | 110 | }
|
104 | 111 | return mapObject(image);
|
105 | 112 |
|
@@ -181,7 +188,7 @@ private static Image resizeImage(Image image, Path path) {
|
181 | 188 | if (width < 800)
|
182 | 189 | return image;
|
183 | 190 |
|
184 |
| - RobotLog.info("Full resolution image can be found at " + path); |
| 191 | + RobotLog.html("Full resolution image can be found from <a href=" + path + " >" + path + "</a>."); |
185 | 192 | double multiplier = width / 800;
|
186 | 193 | try {
|
187 | 194 | String url = path.toUri().toURL().toString();
|
|
0 commit comments