How to test JavaFX 2 in a headless environment?

↘锁芯ラ 提交于 2019-12-18 01:16:55

问题


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?

回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/12194436/how-to-test-javafx-2-in-a-headless-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!