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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 30 additions & 3 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 31 additions & 5 deletions
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

Lines changed: 19 additions & 14 deletions
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

Lines changed: 12 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 1 deletion
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 ===
Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

0 commit comments

Comments
 (0)