Skip to content

Commit 2327c38

Browse files
authored
Merge pull request #34 from eficode/development
Development
2 parents 33e87f9 + ab45331 commit 2327c38

File tree

85 files changed

+1169
-706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1169
-706
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ report-images
99

1010
# temporary pom file by shade plugin
1111
dependency-reduced-pom.xml
12+
13+
# TODO: put logs to some other location, e.g. under target that gets cleaned
14+
# docker demo environment robot reports
15+
src/test/robotframework/results/

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +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://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.5.3/javafxlibrary-0.5.3.html).
10+
See keyword [documentation](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.5.4/javafxlibrary-0.5.4.html).
1111

12-
For editors (IDEs) keyword documentation can be obtained from [here](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.5.3/javafxlibrary-0.5.3.xml).
12+
For editors (IDEs) keyword documentation can be obtained from [here](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.5.4/javafxlibrary-0.5.4.xml).
1313

1414
## Taking the library into use
1515
### As a local library
@@ -46,7 +46,7 @@ To use JavaFXLibrary on macOS Mojave you must enable the accessibility features
4646
- Enable accessibility features by checking the box: :white_check_mark: Terminal
4747

4848
## Identifying JavaFX UI objects
49-
[Scenic View](http://fxexperience.com/scenic-view/) is a tool that allows you to inspect the JavaFX application scenegraph. This can be useful especially when you do not have access to the source code.
49+
[Scenic View](https://github.com/JonathanGiles/scenic-view) is a tool that allows you to inspect the JavaFX application scenegraph. This can be useful especially when you do not have access to the source code.
5050

5151
See [keyword documentation](https://eficode.github.io/JavaFXLibrary/javafxlibrary.html#3.%20Locating%20JavaFX%20Nodes) for detailed information about handling UI elements with the library.
5252

docs/javafxlibrary.html

+1-1
Large diffs are not rendered by default.

pom.xml

+23-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<groupId>org.robotframework</groupId>
2222
<artifactId>javafxlibrary</artifactId>
2323
<packaging>jar</packaging>
24-
<version>0.5.3</version>
24+
<version>0.5.4</version>
2525
<properties>
2626
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2727
<jmockit.version>1.44</jmockit.version>
@@ -165,6 +165,22 @@
165165
</distributionManagement>
166166

167167
<build>
168+
<resources>
169+
<resource>
170+
<directory>src/main/resources</directory>
171+
<filtering>true</filtering>
172+
<includes>
173+
<include>**/*.properties</include>
174+
</includes>
175+
</resource>
176+
<resource>
177+
<directory>src/main/resources</directory>
178+
<filtering>false</filtering>
179+
<excludes>
180+
<exclude>**/*.properties</exclude>
181+
</excludes>
182+
</resource>
183+
</resources>
168184
<plugins>
169185
<plugin>
170186
<groupId>org.apache.maven.plugins</groupId>
@@ -251,7 +267,6 @@
251267
<configuration>
252268
<includes>
253269
<include>smoke</include>
254-
<!-- <include>set-datepicker</include>-->
255270
</includes>
256271
<excludes>
257272
<exclude>not-ready</exclude>
@@ -377,7 +392,7 @@
377392
<dependency>
378393
<groupId>org.robotframework</groupId>
379394
<artifactId>javalib-core</artifactId>
380-
<version>1.2.1</version>
395+
<version>2.0.3</version>
381396
</dependency>
382397
<dependency>
383398
<groupId>org.robotframework</groupId>
@@ -394,11 +409,11 @@
394409
<artifactId>guava</artifactId>
395410
<version>28.1-jre</version>
396411
</dependency>
397-
<dependency>
398-
<groupId>com.github.ombre42</groupId>
399-
<artifactId>jrobotremoteserver</artifactId>
400-
<version>3.0</version>
401-
</dependency>
412+
<dependency>
413+
<groupId>org.robotframework</groupId>
414+
<artifactId>jrobotremoteserver</artifactId>
415+
<version>4.0.0</version>
416+
</dependency>
402417
<dependency>
403418
<groupId>org.apache.commons</groupId>
404419
<artifactId>commons-lang3</artifactId>

src/main/java/JavaFXLibrary.java

+93-11
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@
3737
import org.python.google.common.base.Throwables;
3838
import org.robotframework.javalib.annotation.Autowired;
3939
import org.robotframework.javalib.library.AnnotationLibrary;
40-
import org.robotframework.remoteserver.RemoteServer;
41-
import org.testfx.util.WaitForAsyncUtils;
4240

4341
import javax.script.ScriptEngine;
4442
import javax.script.ScriptEngineManager;
4543
import javax.script.ScriptException;
4644
import static javafxlibrary.utils.HelperFunctions.*;
4745
import static org.testfx.util.WaitForAsyncUtils.waitFor;
46+
import java.util.ResourceBundle;
4847

4948
public class JavaFXLibrary extends AnnotationLibrary {
5049

@@ -78,15 +77,93 @@ public JavaFXLibrary(boolean headless) {
7877
}
7978
}
8079

80+
public static String loadRobotLibraryVersion() {
81+
try {
82+
return ResourceBundle.getBundle(JavaFXLibrary.class.getCanonicalName().replace(".", File.separator))
83+
.getString("version");
84+
} catch (RuntimeException e) {
85+
return "unknown";
86+
}
87+
}
88+
8189
@Autowired
8290
protected RunOnFailure runOnFailure;
8391

92+
@Override
93+
public Object runKeyword(String keywordName, List args, Map kwargs) {
94+
95+
if (kwargs == null) {
96+
kwargs = new HashMap();
97+
}
98+
99+
List finalArgs;
100+
Map finalKwargs;
101+
102+
// JavalibCore changes arguments of Call Method keywords to Strings after this check, so they need to handle their own objectMapping
103+
if (!(keywordName.equals("callObjectMethod") || keywordName.equals("callObjectMethodInFxApplicationThread"))) {
104+
finalArgs = HelperFunctions.useMappedObjects(args);
105+
finalKwargs = HelperFunctions.useMappedObjects(kwargs);
106+
} else {
107+
finalArgs = args;
108+
finalKwargs = kwargs;
109+
}
110+
111+
112+
AtomicReference<Object> retval = new AtomicReference<>();
113+
AtomicReference<RuntimeException> retExcep = new AtomicReference<>();
114+
115+
try {
116+
RobotLog.ignoreDuplicates();
117+
// timeout + 500 ms so that underlying timeout has a chance to expire first
118+
waitFor(getWaitUntilTimeout(TimeUnit.MILLISECONDS) + 500, TimeUnit.MILLISECONDS, () -> {
119+
120+
try {
121+
retval.set(super.runKeyword(keywordName, finalArgs, finalKwargs));
122+
return true;
123+
124+
} catch (JavaFXLibraryTimeoutException jfxte){
125+
// timeout already expired, catch exception and jump out
126+
retExcep.set(jfxte);
127+
throw jfxte;
128+
129+
} catch (RuntimeException e){
130+
// catch exception and continue trying
131+
retExcep.set(e);
132+
return false;
133+
}
134+
});
135+
} catch (TimeoutException te) {
136+
RobotLog.reset();
137+
RuntimeException e = retExcep.get();
138+
runOnFailure.runOnFailure();
139+
140+
if (e.getCause() instanceof JavaFXLibraryFatalException) {
141+
RobotLog.trace("JavaFXLibrary: Caught JavaFXLibrary FATAL exception: \n" + Throwables.getStackTraceAsString(e));
142+
throw e;
143+
} else if (e.getCause() instanceof JavaFXLibraryNonFatalException) {
144+
RobotLog.trace("JavaFXLibrary: Caught JavaFXLibrary NON-FATAL exception: \n" + Throwables.getStackTraceAsString(e));
145+
throw e;
146+
} else {
147+
RobotLog.trace("JavaFXLibrary: Caught JavaFXLibrary RUNTIME exception: \n" + Throwables.getStackTraceAsString(e));
148+
throw e;
149+
}
150+
} catch (JavaFXLibraryTimeoutException jfxte) {
151+
RobotLog.reset();
152+
RobotLog.trace("JavaFXLibrary: Caught JavaFXLibrary TIMEOUT exception: \n" + Throwables.getStackTraceAsString(jfxte));
153+
throw jfxte;
154+
}
155+
RobotLog.reset();
156+
return retval.get();
157+
}
158+
84159
// overriding the run method to catch the control in case of failure, so that desired runOnFailureKeyword
85160
// can be executed in controlled manner.
86161
@Override
87-
public Object runKeyword(String keywordName, Object[] args) {
162+
public Object runKeyword(String keywordName, List args) {
163+
// TODO: Check if this is ever called anymore
164+
RobotLog.info("runKeyword called with args ONLY");
88165

89-
Object[] finalArgs;
166+
List finalArgs;
90167
// JavalibCore changes arguments of Call Method keywords to Strings after this check, so they need to handle their own objectMapping
91168
if (!(keywordName.equals("callObjectMethod") || keywordName.equals("callObjectMethodInFxApplicationThread")))
92169
finalArgs = HelperFunctions.useMappedObjects(args);
@@ -181,22 +258,23 @@ public static JavaFXLibrary getLibraryInstance() throws ScriptException {
181258
}
182259

183260
public static void main(String[] args) throws Exception {
184-
JavaFXLibraryRemoteServer.configureLogging();
185-
System.out.println("---------------------------= JavaFXLibrary =---------------------------- ");
186-
RemoteServer server = new JavaFXLibraryRemoteServer();
187-
server.putLibrary("/RPC2", new JavaFXLibrary());
188261
int port = 8270;
189262
InetAddress ipAddr = InetAddress.getLocalHost();
190263

191264
try {
192-
if (args.length > 0)
265+
JavaFXLibraryRemoteServer.configureLogging();
266+
System.out.println("----------------------------= JavaFXLibrary =-----------------------------");
267+
if (args.length > 0) {
193268
port = Integer.parseInt(args[0]);
194-
else
269+
}
270+
else {
195271
System.out.println("RemoteServer for JavaFXLibrary will be started at default port of: " + port + ".\n" +
196272
"If you wish to use another port, restart the library and give port number\n" +
197273
"as an argument.");
274+
}
198275

199-
server.setPort(port);
276+
JavaFXLibraryRemoteServer server = new JavaFXLibraryRemoteServer(port);
277+
server.putLibrary("/RPC2", new JavaFXLibrary());
200278
server.start();
201279
System.out.println("\n JavaFXLibrary " + ROBOT_LIBRARY_VERSION + " is now available at: " +
202280
ipAddr.getHostAddress() + ":" + port + "\n");
@@ -210,6 +288,10 @@ public static void main(String[] args) throws Exception {
210288
} catch (BindException be) {
211289
System.out.println("\n Error! " + be.getMessage() + ": " + ipAddr.getHostAddress() + ":" + port + "\n");
212290
System.exit(1);
291+
} catch (IOException ioe) {
292+
System.out.println("\n Error! " + ioe.getMessage() + ": " + ipAddr.getHostAddress() + ":" + port + "\n");
293+
System.exit(1);
213294
}
214295
}
215296
}
297+

src/main/java/JavaFXLibraryRemoteServer.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,27 @@
1717

1818
import org.apache.commons.logging.Log;
1919
import org.apache.commons.logging.LogFactory;
20-
import org.apache.log4j.BasicConfigurator;
21-
import org.apache.log4j.Level;
22-
import org.apache.log4j.Logger;
20+
import org.apache.logging.log4j.Level;
21+
import org.apache.logging.log4j.core.config.Configurator;
22+
import org.apache.logging.log4j.core.config.DefaultConfiguration;
2323
import org.robotframework.remoteserver.RemoteServer;
2424
import org.robotframework.remoteserver.logging.Jetty2Log4J;
2525

2626
public class JavaFXLibraryRemoteServer extends RemoteServer {
2727

28+
public JavaFXLibraryRemoteServer(int port) {
29+
super(port);
30+
}
31+
2832
private static Log log = LogFactory.getLog(RemoteServer.class);
2933

3034
public static void configureLogging() {
31-
Logger root = Logger.getRootLogger();
32-
root.removeAllAppenders();
33-
BasicConfigurator.configure();
34-
root.setLevel(Level.FATAL);
35+
Configurator.initialize(new DefaultConfiguration());
36+
Configurator.setRootLevel(Level.FATAL);
3537
org.eclipse.jetty.util.log.Log.setLog(new Jetty2Log4J());
3638
LogFactory.releaseAll();
3739
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
3840
"org.apache.commons.logging.impl.Log4JLogger");
3941
log = LogFactory.getLog(RemoteServer.class);
4042
}
41-
}
43+
}

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

+12
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,23 @@ public void clearObjectMap() {
235235

236236

237237
@RobotKeyword("Returns the class name of currently active JavaFX Application")
238+
public String getCurrentApplication() {
239+
try {
240+
return getCurrentSessionApplicationName();
241+
} catch (Exception e) {
242+
throw new JavaFXLibraryNonFatalException("Problem getting current application name.", e);
243+
}
244+
}
245+
246+
@Deprecated
247+
@RobotKeyword("*DEPRECATED in version 0.6.0!* Use `Get Current Application` keyword instead.\n\n"
248+
+ "Returns the class name of currently active JavaFX Application\n")
238249
public String currentApplication() {
239250
try {
240251
return getCurrentSessionApplicationName();
241252
} catch (Exception e) {
242253
throw new JavaFXLibraryNonFatalException("Problem getting current application name.", e);
243254
}
244255
}
256+
245257
}

0 commit comments

Comments
 (0)