Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4602e7

Browse files
authored
Merge pull request #16 from Hi-Fi/experimentalHeadless
Experimental headless
2 parents 599c6df + e2c774a commit a4602e7

14 files changed

+123
-30
lines changed

BUILD.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ JavaFXLibrary uses Apache Maven as a build tool.
1616
are being used by both JavaFXLibrary and the AUT. It's not uncommon that a specific version is needed for AUT and another
1717
version of the same dependency is required for JavaFXLibrary(e.g. TestFX dependency for Google Guava). Not always are these
1818
dependencies backwards compatible and therefore JavaFXLibrary has adopted Apache Maven Shade Plugin to cope with this issue.
19-
Currently the package com.google.common has been renamed in JavaFXLibrary as shaded.com.google.common to avoid version
20-
mismatches with Google Guava dependencies. See https://maven.apache.org/plugins/maven-shade-plugin/ for more info.
19+
Currently the package com.google.common has been renamed in JavaFXLibrary as shaded.com.google.common and org.apache.commons as shaded.org.apache.commons to avoid version
20+
mismatches with dependencies in AUT and internally. See https://maven.apache.org/plugins/maven-shade-plugin/ for more info.
2121

2222

2323
## Releasing

README.md

+30-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ JavaFXLibrary works with both Jython (local and remote use) and Python (remote o
77
JavaFXLibrary is tested to work with Robot Framework 3.0.2 or later.
88

99
## Keyword documentation
10-
See keyword [documentation](https://eficode.github.io/JavaFXLibrary/javafxlibrary.html).
10+
See keyword [documentation](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.5.2/javafxlibrary-0.5.2.html).
11+
12+
For editors (IDEs) keyword documentation can be obtained from [here](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.5.2/javafxlibrary-0.5.2.xml).
1113

1214
## Taking the library into use
1315
### As a local library
@@ -17,7 +19,7 @@ See keyword [documentation](https://eficode.github.io/JavaFXLibrary/javafxlibrar
1719
*** Settings ***
1820
Library JavaFXLibrary
1921
```
20-
3. Add library jar to Jython [module search path](http://robotframework.org/robotframework/3.0b1/RobotFrameworkUserGuide.html#configuring-where-to-search-libraries-and-other-extensions) and run your tests:
22+
3. Add library jar to Jython [module search path](http://robotframework.org/robotframework/3.0.4/RobotFrameworkUserGuide.html#configuring-where-to-search-libraries-and-other-extensions) and run your tests:
2123
```
2224
jython -J-cp javafxlibrary-<version>.jar -m robot.run tests.robot
2325
```
@@ -70,4 +72,29 @@ Library's acceptance test suite can be used as a JavaFXLibrary demo. Running the
7072

7173
Executing _test.sh_ runs the acceptance suite twice: first using JavaFXLibrary as a local Robot Framework library on Jython, and after that using the library in remote mode executing the same tests on python version of Robot Framework.
7274

73-
If you want the suite to run only once, you can define which type of library to use by including **local** or **remote** as an argument. For example command `test.sh remote` will execute the suite only in remote mode.
75+
If you want the suite to run only once, you can define which type of library to use by including **local** or **remote** as an argument. For example command `test.sh remote` will execute the suite only in remote mode.
76+
77+
## Experimental: Headless support
78+
Library supports headless operation utilizing [Monocle](https://wiki.openjdk.java.net/display/OpenJFX/Monocle). The support for this is still at experimental level.
79+
80+
### Main issues with headless function
81+
* Scrolling doesn't work same way as with screen
82+
* "Tick" (amount of scrolling) is much smaller in headless than normally
83+
* Vertical (left/right) scrolling is not working
84+
* Separate app windows' can't be closed (unless app offers that functionality itself)
85+
* Swing applications can't be tested in headless mode.
86+
87+
### Enabling headless mode
88+
Headless mode can be enabled by setting first library initialization to "True".
89+
90+
Locally:
91+
```
92+
*** Settings ***
93+
Library JavaFXLibrary ${True}
94+
```
95+
96+
Remote:
97+
```
98+
*** Settings ***
99+
Library Remote http://127.0.0.1:8270 ${True} WITH NAME JavaFXLibrary
100+
```

pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@
255255
<excludes>
256256
<exclude>not-ready</exclude>
257257
</excludes>
258+
<nonCriticalTags>
259+
<nonCriticalTag>monocle-issue</nonCriticalTag>
260+
</nonCriticalTags>
258261
<logLevel>TRACE:INFO</logLevel>
259262
<dryrun>false</dryrun>
260263
<variables>
@@ -369,7 +372,6 @@
369372
<groupId>org.testfx</groupId>
370373
<artifactId>openjfx-monocle</artifactId>
371374
<version>8u76-b04</version>
372-
<scope>test</scope>
373375
</dependency>
374376
<dependency>
375377
<groupId>org.robotframework</groupId>

src/main/java/JavaFXLibrary.java

+31-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javafxlibrary.keywords.AdditionalKeywords.RunOnFailure;
3232
import javafxlibrary.utils.HelperFunctions;
3333
import javafxlibrary.utils.RobotLog;
34+
import javafxlibrary.utils.TestFxAdapter;
3435
import javafxlibrary.utils.TestListener;
3536
import org.apache.commons.io.FileUtils;
3637
import org.python.google.common.base.Throwables;
@@ -58,12 +59,24 @@ public class JavaFXLibrary extends AnnotationLibrary {
5859
}};
5960

6061
public JavaFXLibrary() {
62+
this(false);
63+
}
64+
65+
public JavaFXLibrary(boolean headless) {
6166
super(includePatterns);
6267
deleteScreenshotsFrom("report-images/imagecomparison");
63-
//v4.0.15-alpha sets default robot as glass, which breaks rolling
64-
//Forcing usage of awt robot as previous versions
65-
System.setProperty("testfx.robot", "awt");
66-
}
68+
if (headless) {
69+
System.setProperty("testfx.robot", "glass");
70+
System.setProperty("testfx.headless", "true");
71+
System.setProperty("prism.order", "sw");
72+
System.setProperty("prism.text", "t2k");
73+
TestFxAdapter.isHeadless = true;
74+
} else {
75+
//v4.0.15-alpha sets default robot as glass, which breaks rolling
76+
//Forcing usage of awt robot as previous versions
77+
System.setProperty("testfx.robot", "awt");
78+
}
79+
}
6780

6881
@Autowired
6982
protected RunOnFailure runOnFailure;
@@ -136,8 +149,21 @@ public String getKeywordDocumentation(String keywordName) {
136149
e.printStackTrace();
137150
return "IOException occured while reading the documentation file!";
138151
}
152+
} else if (keywordName.equals("__init__")) {
153+
try {
154+
return FileUtils.readFileToString(new File("./src/main/java/libdoc-init-documentation.txt"), "utf-8");
155+
} catch (IOException e) {
156+
e.printStackTrace();
157+
return "IOException occured while reading the init documentation file!";
158+
}
159+
} else {
160+
try {
161+
return super.getKeywordDocumentation(keywordName);
162+
}
163+
catch (Exception e) {
164+
return keywordName;
165+
}
139166
}
140-
return super.getKeywordDocumentation(keywordName);
141167
}
142168

143169
/**

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

+19-14
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,25 @@ public FxRobotInterface write(String text) {
183183
+ "| Write Fast | Robot Framework | \n")
184184
@ArgumentNames({ "text" })
185185
public void writeFast(String text) {
186-
try {
187-
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
188-
StringSelection testData = new StringSelection(text);
189-
c.setContents(testData, testData);
190-
191-
if(isMac())
192-
robot.push(KeyCode.META, KeyCode.V).sleep(100);
193-
else
194-
robot.push(KeyCode.CONTROL, KeyCode.V).sleep(100);
195-
} catch (Exception e) {
196-
if(e instanceof JavaFXLibraryNonFatalException)
197-
throw e;
198-
throw new JavaFXLibraryNonFatalException("Unable to write text using copy/paste method.", e);
199-
}
186+
if (TestFxAdapter.isHeadless) {
187+
RobotLog.info("Fast write not working in headless mode. Writing text normally");
188+
this.write(text);
189+
} else {
190+
try {
191+
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
192+
StringSelection testData = new StringSelection(text);
193+
c.setContents(testData, testData);
194+
195+
if(isMac())
196+
robot.push(KeyCode.META, KeyCode.V).sleep(100);
197+
else
198+
robot.push(KeyCode.CONTROL, KeyCode.V).sleep(100);
199+
} catch (Exception e) {
200+
if(e instanceof JavaFXLibraryNonFatalException)
201+
throw e;
202+
throw new JavaFXLibraryNonFatalException("Unable to write text using copy/paste method.", e);
203+
}
204+
}
200205
}
201206

202207
@RobotKeyword("Writes a given text characters one after the other to given locator.\n\n"

src/main/java/javafxlibrary/utils/HelperFunctions.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javafx.stage.Window;
3030
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
3131
import javafxlibrary.exceptions.JavaFXLibraryTimeoutException;
32+
import javafxlibrary.keywords.AdditionalKeywords.ConvenienceKeywords;
3233
import javafxlibrary.matchers.ProgressBarMatchers;
3334
import javafxlibrary.utils.finder.Finder;
3435
import org.apache.commons.lang3.StringUtils;
@@ -438,13 +439,22 @@ public static void checkClickLocation(Object object) {
438439
}
439440
RobotLog.trace("Target location checks out OK, it is within active window");
440441
}
442+
443+
public static void verifyClickLocationOnFront(Object object) {
444+
try {
445+
new ConvenienceKeywords().bringStageToFront((Stage) objectToNode(object).getScene().getWindow());
446+
} catch (Exception e) {
447+
RobotLog.trace("Node's window wasn't castable to Stage. Tried with object: "+object);
448+
}
449+
}
441450

442451
public static Object checkClickTarget(Object target) {
443452
try {
444453

445-
if (target instanceof String || target instanceof Node)
454+
if (target instanceof String || target instanceof Node) {
446455
target = waitUntilEnabled(waitUntilVisible(target, waitUntilTimeout), waitUntilTimeout);
447-
456+
verifyClickLocationOnFront(target);
457+
}
448458
checkClickLocation(target);
449459
return target;
450460

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

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
public class TestFxAdapter {
3030

31+
public static boolean isHeadless = false;
3132
// current robot instance in use
3233
protected static FxRobotInterface robot;
3334
public static void setRobot(FxRobotInterface robot) {

src/main/java/libdoc-documentation.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ First, the JavaFXLibrary needs to be taken into use in the settings table.
2121
| *Settings* | *Value* |
2222
| Library | JavaFXLibrary |
2323

24+
Experimental headless mode can be activated at the import time by setting first argument to ${True}
25+
| *Settings* | *Value* |
26+
| Library | JavaFXLibrary | ${True} |
2427

2528
=== 2.2 Usage in remote mode(Jython & Python) ===
2629
When using the test library in remote mode, the library needs to be started at the remote end first. This can be done as follows:
@@ -40,7 +43,9 @@ Multiple JavaFXLibraries in remote mode:
4043
| Library | Remote | ip_address:8270 | WITH NAME | my_application |
4144
| Library | Remote | ip_address:8271 | WITH NAME | my_other_application |
4245

43-
46+
Experimental headless mode can be activated in remote mode at the import time by setting first argument to ${True}
47+
| *Settings* | *Value* |
48+
| Library | Remote | http://localhost:8270 | ${True} | WITH NAME | JavaFXLibrary |
4449

4550
== 3. Locating JavaFX Nodes ==
4651
=== 3.1 Locator syntax ===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
JavaFXLibrary can be imported with one optional arguments.
2+
3+
- ``headless``: Determines if tests will be run in headless mode using [https://wiki.openjdk.java.net/display/OpenJFX/Monocle|Monocle]. Default value is ``false``.

src/test/robotframework/acceptance/ScrollRobotTest.robot

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Scroll Right
6969
*** Keywords ***
7070
Setup all tests
7171
Import JavaFXLibrary
72+
Run Keyword If ${headless} Set Tags monocle-issue
7273
Launch Javafx Application ${TEST_APPLICATION}
7374
Set Screenshot Directory ${OUTPUT_DIR}${/}report-images
7475
Set Variables

src/test/robotframework/acceptance/ScrollRobotTest2.robot

+8
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@ ${TEST_APPLICATION} javafxlibrary.testapps.TestScrollRobot2
1313
*** Test Cases ***
1414
Scroll down
1515
[Tags] smoke demo-set
16+
Verify String Should Not Match id=verticalScrollLocation max
1617
Scroll Vertically DOWN 50
1718
Verify String id=verticalScrollLocation max
1819
1920
Scroll up
2021
[Tags] smoke demo-set
22+
Verify String Should Not Match id=verticalScrollLocation min
2123
Scroll Vertically UP 50
2224
Verify String id=verticalScrollLocation min
2325
2426
Scroll right
2527
[Tags] smoke demo-set
2628
Skip Test On Linux
29+
Verify String Should Not Match id=horizontalScrollLocation max
2730
Scroll Horizontally RIGHT 50
2831
Verify String id=horizontalScrollLocation max
2932
3033
Scroll left
3134
[Tags] smoke demo-set
3235
Skip Test On Linux
36+
Verify String Should Not Match id=horizontalScrollLocation min
3337
Scroll Horizontally LEFT 50
3438
Verify String id=horizontalScrollLocation min
3539
@@ -41,24 +45,28 @@ Scroll down once
4145
4246
Scroll up once
4347
[Tags] smoke
48+
Verify String Should Not Match id=verticalScrollLocation min
4449
Scroll Vertically UP 1
4550
Verify String id=verticalScrollLocation min
4651
4752
Scroll Right Once
4853
[Tags] smoke
4954
Skip Test On Linux
55+
Verify String id=horizontalScrollLocation min
5056
Scroll Horizontally RIGHT 1
5157
Verify String Should Not Match id=horizontalScrollLocation min
5258
5359
Scroll Left Once
5460
[Tags] smoke
5561
Skip Test On Linux
62+
Verify String Should Not Match id=horizontalScrollLocation min
5663
Scroll Horizontally LEFT 1
5764
Verify String id=horizontalScrollLocation min
5865
5966
*** Keywords ***
6067
Setup all tests
6168
Import JavaFXLibrary
69+
Run Keyword If ${headless} Set Tags monocle-issue
6270
Launch Javafx Application ${TEST_APPLICATION}
6371
Set Screenshot Directory ${OUTPUT_DIR}${/}report-images
6472
Move To id=scrollPane

src/test/robotframework/acceptance/SwingApplicationWrapperTest.robot

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Test Teardown Teardown Test Case
99
*** Testcases ***
1010
Swing Embedded JavaFX Click Test
1111
[Tags] smoke demo-set
12+
Run Keyword If ${headless} Set Tags monocle-issue
1213
Launch Swing Application javafxlibrary.testapps.SwingApplication
1314
Wait Until Keyword Succeeds 15 sec 250ms Find css=.button failIfNotFound=True
1415
${colors} Create List 0xdc143cff 0x00fa9aff 0xee82eeff 0xffff00ff 0x00ffffff
@@ -19,13 +20,15 @@ Swing Embedded JavaFX Click Test
1920

2021
Swing Embedded JavaFX Type Test
2122
[Tags] smoke
23+
Run Keyword If ${headless} Set Tags monocle-issue
2224
Launch Swing Application javafxlibrary.testapps.SwingApplication
2325
Wait Until Keyword Succeeds 15 sec 250ms Find id=textField failIfNotFound=True
2426
Write To id=textField JavaFXLibrary
2527
Wait Until Keyword Succeeds 3 sec 250ms Text Value Should Be JavaFXLibrary
2628

2729
Launch Swing Application Using External Wrapper Class
2830
[Tags] smoke
31+
Run Keyword If ${headless} Set Tags monocle-issue
2932
Launch Javafx Application javafxlibrary.testapps.SwingApplicationWrapper
3033
Wait Until Keyword Succeeds 15 sec 250ms Find id=textField failIfNotFound=True
3134
Write To id=textField JavaFXLibrary

src/test/robotframework/acceptance/WindowLookupTest.robot

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Bring Stage To Front
9191
# Keyword is located in TypeRobot
9292
Close Current Window
9393
[Tags] smoke set-todo
94+
Run Keyword If ${headless} Set Tags monocle-issue
9495
${START} List Windows
9596
Activate window @{START}[0]
9697
Close Current Window

src/test/robotframework/resource.robot

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
*** Variables ***
22
${appJar} javafxlibrary-*-tests.jar
3+
${headless} ${False}
34
45
*** Keywords ***
56
Import JavaFXLibrary
6-
Run Keyword If sys.platform.startswith('java') Import Library JavaFXLibrary
7-
... ELSE Import Library Remote http://javafxcompile:8270 WITH NAME RemoteJavaFXLibrary
7+
Run Keyword If sys.platform.startswith('java') Import Library JavaFXLibrary ${headless}
8+
... ELSE Import Library Remote http://javafxcompile:8270 ${headless} WITH NAME RemoteJavaFXLibrary
89
Set To Classpath ${appJar}
910
1011
Disable Embedded Image Logging For Negative Tests

0 commit comments

Comments
 (0)