How to test JavaFX 2 in a headless environment?
Asked Answered
H

2

11

I am trying to automate testing for a JavaFX 2 application running on Java 7u6 with the integrated JavaFX 2.2. To that end, I have built and integrated Jemmy3 and JemmyFX into my build environment. A simple smoke test runs on all relevant OSs.

As a next step, I want to run the tests as part of the continuous deployment process. Since the current CI server runs on OpenSUSE, which is not officially supported by JavaFX, I have set up an Ubuntu Server installation in a virtual machine and installed gtk2.
To remedy the lack of a fully fledged windowing system, I have tried running the tests on both Xvnc and Xvfb, but to no avail.

On Xvnc, the tests fail with

Prism ES2 Error - nInitialize: glXChooseFBConfig failed

whereas on Xvfb, they give me

Xlib:  extension "RANDR" missing on display ":10".

A blog post suggested to install gtk-engines-pixbuf to alleviate the second problem, but this only changed the number of the display in the error message.

Now, I summon the JavaFX knowledge of StackOverflow and ask

  • Do you know how to solve the above errors?
  • Did you successfully run a JavaFX 2 test or Robot interaction on a (headless) CI server?
  • How did you configure that system to get it to work?
Hindorff answered 30/8, 2012 at 10:6 Comment(2)
I'm guessing that support for (headless) CI server testing of JavaFX is not available until JavaFX 8 (based on these jiras). Maybe Sergey from the JavaFX QA team might know more, he reviews this Q/A site sometimes.Ricard
Unless Sergey shows up with some totally different answer, I'd be willing to accept this as fact, if you submit it as an answer.Hindorff
R
7

Support for (headless) CI server testing of JavaFX is not available until JavaFX 8.

Answer based on information in these JavaFX issue tracking records:

  • JDK-8088651 "Headless Glass toolkit needs to be connected to Quantum and Prism unit tests"
  • JDK-8091286 "Quantum needs headless and headful tests").

Update Jan 8, 2015

The linked JavaFX issue tracking records were not implemented for Java 8 and have been reassigned to Java 9.

Java 8 source code currently includes a minimal rendering engine named Monocle which provides Headless rendering (and rendering for various other target platforms) for JavaFX components. I have never used Monocle and cannot provide detailed instructions on how to use it for headless rendering. I believe to use Monocle, you currently need to perform a custom build of JavaFX from source (as I think Monocle is usually only shipped in embedded JavaFX versions, which is not the standard JavaFX version which ships with the desktop Java runtime and JDK environments).

Information on Monocle is available on the JavaFX wiki.

Although, headless rendering is provided by Monocle, I do not think that using Monocle to perform headless rendering is officially supported by Oracle (though i don't think headless rendering of JavaFX in any form is officially supported, so I guess if Monocle works well for you, by all means use it).

The headless rendering in Monocle is a software rendering implementation so execution of some graphic primitives may be slower than the standard hardware accelerated operation of JavaFX in a desktop environment.

There may be other methods of allowing JavaFX to run in a headless environment that I am not aware of.

If in doubt, ask the JavaFX developers on the openjfx-dev mailing list.

If you are running under Linux, using Xvfb as suggested by Jan Zarnikov's answer is probably a good solution and is likely preferable to using Monocle.

Ricard answered 1/9, 2012 at 18:5 Comment(2)
Updated answer to provide the current information as I know it.Ricard
This answer suggests Monocle is available as an additional dependency.Rival
B
12

I had a similar problem - running JUnit tests in a headless environment with Maven.

We don't use JemmyFX. We have just very simple tests that use a JUnit Rule similar to this one: https://gist.github.com/andytill/3835914 (this is required for code that uses Platform.runLater(...))

Current version of JavaFX (supplied with JDK 1.7.0-21) seems to be working in Xvfb on Ubuntu 12.04 without a running Xserver:

  1. Xvfb :99
  2. DISPLAY=:99 mvn clean install
Bratislava answered 23/5, 2013 at 10:52 Comment(0)
R
7

Support for (headless) CI server testing of JavaFX is not available until JavaFX 8.

Answer based on information in these JavaFX issue tracking records:

  • JDK-8088651 "Headless Glass toolkit needs to be connected to Quantum and Prism unit tests"
  • JDK-8091286 "Quantum needs headless and headful tests").

Update Jan 8, 2015

The linked JavaFX issue tracking records were not implemented for Java 8 and have been reassigned to Java 9.

Java 8 source code currently includes a minimal rendering engine named Monocle which provides Headless rendering (and rendering for various other target platforms) for JavaFX components. I have never used Monocle and cannot provide detailed instructions on how to use it for headless rendering. I believe to use Monocle, you currently need to perform a custom build of JavaFX from source (as I think Monocle is usually only shipped in embedded JavaFX versions, which is not the standard JavaFX version which ships with the desktop Java runtime and JDK environments).

Information on Monocle is available on the JavaFX wiki.

Although, headless rendering is provided by Monocle, I do not think that using Monocle to perform headless rendering is officially supported by Oracle (though i don't think headless rendering of JavaFX in any form is officially supported, so I guess if Monocle works well for you, by all means use it).

The headless rendering in Monocle is a software rendering implementation so execution of some graphic primitives may be slower than the standard hardware accelerated operation of JavaFX in a desktop environment.

There may be other methods of allowing JavaFX to run in a headless environment that I am not aware of.

If in doubt, ask the JavaFX developers on the openjfx-dev mailing list.

If you are running under Linux, using Xvfb as suggested by Jan Zarnikov's answer is probably a good solution and is likely preferable to using Monocle.

Ricard answered 1/9, 2012 at 18:5 Comment(2)
Updated answer to provide the current information as I know it.Ricard
This answer suggests Monocle is available as an additional dependency.Rival

© 2022 - 2024 — McMap. All rights reserved.