Skip to content

Commit dc9ca79

Browse files
committed
refactored image logging
1 parent 5bed94d commit dc9ca79

23 files changed

+59
-50
lines changed

src/main/java/javafxlibrary/keywords/AdditionalKeywords/RunOnFailure.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,15 @@ public void runOnFailure() {
5555

5656
runningOnFailureRoutine = true;
5757

58+
RobotLog.info("JavaFXLibrary keyword has failed!");
5859
if (robot == null) {
5960
RobotLog.error("FxRobot not initialized, launch test application with the library");
60-
} else if (TestFxAdapter.logImages) {
61-
RobotLog.info("JavaFxLibrary keyword has failed! Below a screenshot from erroneous situation:");
62-
if (robot.targetWindow() != null) {
63-
new ScreenCapturing().captureImage(robot.targetWindow());
64-
} else
65-
new ScreenCapturing().captureImage(Screen.getPrimary().getBounds());
61+
}
62+
63+
if (robot.targetWindow() != null) {
64+
new ScreenCapturing().captureImage(robot.targetWindow());
6665
} else {
67-
RobotLog.info("JavaFXLibrary keyword has failed!");
68-
RobotLog.info("Not taking a screenshot since Set Image Logging is set to off. To enable screenshots " +
69-
"on failed keywords, use keyword 'Set Image Logging ON'");
66+
new ScreenCapturing().captureImage(Screen.getPrimary().getBounds());
7067
}
7168

7269
runningOnFailureRoutine = false;

src/main/java/javafxlibrary/keywords/Keywords/ScreenCapturing.java

+26-19
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@
4444
@RobotKeywords
4545
public class ScreenCapturing extends TestFxAdapter {
4646

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"
4949
+ "\nExample:\n"
50-
+ "| Set Image Logging | OFF |\n")
50+
+ "| Set Image Logging | DISKONLY |\n")
5151
@ArgumentNames({ "value" })
5252
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";
5757
else
5858
throw new JavaFXLibraryNonFatalException("Value \"" + value + "\" is not supported! Value must be either " +
59-
"\"ON\" or \"OFF\"");
59+
"\"EMBEDDED\" or \"DISKONLY\"");
6060
}
6161

6262
@RobotKeywordOverload
6363
public Object captureImage(Object locator){
64-
return captureImage(locator, TestFxAdapter.logImages);
64+
return captureImage(locator, true);
6565
}
6666

6767
@RobotKeyword("Returns a screenshot of the given locator.\n\n"
@@ -89,17 +89,24 @@ public Object captureImage(Object locator, boolean logImage){
8989
robotContext.getCaptureSupport().saveImage(image, path);
9090

9191
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();
9593

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);
10098

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+
}
103110
}
104111
return mapObject(image);
105112

@@ -181,7 +188,7 @@ private static Image resizeImage(Image image, Path path) {
181188
if (width < 800)
182189
return image;
183190

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>.");
185192
double multiplier = width / 800;
186193
try {
187194
String url = path.toUri().toURL().toString();

src/main/java/javafxlibrary/utils/RobotLog.java

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public static void info(String message) {
2222
System.out.println("*INFO* " + message);
2323
}
2424

25+
public static void html(String message) {
26+
if (shouldLogMessage(message))
27+
System.out.println("*HTML* " + message);
28+
}
29+
2530
public static void debug(String message) {
2631
if (shouldLogMessage(message))
2732
System.out.println("*DEBUG* " + message);

src/main/java/javafxlibrary/utils/TestFxAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void setRobotContext(FxRobotContext context) {
4444
// TODO: consider adding support for multiple sessions
4545
private static Session activeSession = null;
4646

47-
protected static boolean logImages = true;
47+
protected static String logImages = "embedded";
4848

4949
// internal book keeping for objects
5050
public static HashMap objectMap = new HashMap();

src/test/robotframework/acceptance/0_ClickRobotTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Setup all tests
266266
267267
Setup test case
268268
Reset Counters
269-
Disable Image Logging For Negative Tests
269+
Disable Embedded Image Logging For Negative Tests
270270
271271
Teardown all tests
272272
Close Javafx Application

src/test/robotframework/acceptance/BoundsLocationTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.BoundsLocation related
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-boundslocation
99

src/test/robotframework/acceptance/DatePickerTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test DatePicker related keywords
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Teardown test case
88
Force Tags set-datepicker
99

src/test/robotframework/acceptance/DragRobotTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.DragRobot related keywo
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force tags set-dragrobot
99

src/test/robotframework/acceptance/FindTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.AdditionalKeywords.Find
33
Resource ../resource.robot
44
Suite Setup Setup All Tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-find
99

src/test/robotframework/acceptance/KeyboardRobotTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.KeyboardRobot related k
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-keyboardrobot
99

src/test/robotframework/acceptance/MenuAppTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary keywords
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-menuapp
99

src/test/robotframework/acceptance/MiscTests.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Library Collections
55
Library String
66
Suite Setup Setup All Tests
77
Suite Teardown Close Javafx Application
8-
Test Setup Disable Image Logging For Negative Tests
8+
Test Setup Disable Embedded Image Logging For Negative Tests
99
Test Teardown Enable Image Logging
1010

1111
*** Variables ***

src/test/robotframework/acceptance/MoveRobotTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Setup all tests
9696
9797
Setup test case
9898
Move To Top Left Corner
99-
Disable Image Logging For Negative Tests
99+
Disable Embedded Image Logging For Negative Tests
100100
101101
Teardown all tests
102102
Close Javafx Application

src/test/robotframework/acceptance/NodeLookupTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.NodeLookup related keyw
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-nodelookup
99

src/test/robotframework/acceptance/PointLocationTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.PointLocation and Point
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-pointlocation set-pointoffset
99

src/test/robotframework/acceptance/ScreenCapturingTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Library String
44
Resource ../resource.robot
55
Suite Setup Setup all tests
66
Suite Teardown Teardown all tests
7-
Test Setup Disable Image Logging For Negative Tests
7+
Test Setup Disable Embedded Image Logging For Negative Tests
88
Test Teardown Enable Image Logging
99
Force Tags set-screencapturing
1010

src/test/robotframework/acceptance/ScrollRobotTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.ScrollRobot related key
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-scrollrobot
99

src/test/robotframework/acceptance/ScrollRobotTest2.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.ScrollRobot related key
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-scrollrobot
99

src/test/robotframework/acceptance/SwingApplicationWrapperTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests for handling Swing embedded JavaFX nodes
33
Resource ../resource.robot
44
Force Tags set-embedded
55
Suite Setup Import JavaFXLibrary
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Teardown Test Case
88

99
*** Testcases ***

src/test/robotframework/acceptance/WindowLookupTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.WindowLookup related ke
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-windowlookup
99

src/test/robotframework/acceptance/WindowManagementTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests for Window Management
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-windowmanagement
99

src/test/robotframework/acceptance/WindowTargetingTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Documentation Tests to test javafxlibrary.keywords.WindowTargeting related
33
Resource ../resource.robot
44
Suite Setup Setup all tests
55
Suite Teardown Teardown all tests
6-
Test Setup Disable Image Logging For Negative Tests
6+
Test Setup Disable Embedded Image Logging For Negative Tests
77
Test Teardown Enable Image Logging
88
Force Tags set-windowtargeting
99

src/test/robotframework/resource.robot

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Import JavaFXLibrary
33
Run Keyword If sys.platform.startswith('java') Import Library JavaFXLibrary
44
... ELSE Import Library Remote http://javafxcompile:8270 WITH NAME RemoteJavaFXLibrary
55
6-
Disable Image Logging For Negative Tests
6+
Disable Embedded Image Logging For Negative Tests
77
:FOR ${tag} IN @{TEST TAGS}
8-
\ Run Keyword If '${tag}' == 'negative' Set Image Logging OFF
8+
\ Run Keyword If '${tag}' == 'negative' Set Image Logging DISKONLY
99
1010
Enable Image Logging
11-
Set Image Logging ON
11+
Set Image Logging EMBEDDED

0 commit comments

Comments
 (0)