Mute testing with JavaFx and TestFx

I have a simple JavaFx application (Java 8) that has a unit test using TestFx. However, when the test starts, the application window starts and the mouse moves to perform any action in my test. Can these tests run so that the application doesn’t pop up, and I can still use my mouse for other things, since the automatic build and tests run?

+5
source share
3 answers

Update:

I found this blog post that gives me a solution to this problem. As the author suggests, you need to add the following dependency to your assembly:

testRuntime 'org.testfx:openjfx-monocle:1.8.0_20' 

Then you will need to include the following somewhere before calling registerPrimaryStage() , in my case, in the method marked @BeforeClass , since I am using JUnit:

 System.setProperty("testfx.robot", "glass"); System.setProperty("testfx.headless", "true"); System.setProperty("prism.order", "sw"); System.setProperty("prism.text", "t2k"); 

I would also add that it is useful to include System.setProperty("java.awt.headless", "true") to ensure that you do not rely on anything from AWT (in my case, they called me to find out the screen size, which caused problems). I also followed the advice of the blog author to add a switch to turn headless mode on and off. This gives the final method as follows:

 @BeforeClass public static void setupSpec() throws Exception { if (Boolean.getBoolean("headless")) { System.setProperty("testfx.robot", "glass"); System.setProperty("testfx.headless", "true"); System.setProperty("prism.order", "sw"); System.setProperty("prism.text", "t2k"); System.setProperty("java.awt.headless", "true"); } registerPrimaryStage(); } 

You can see the solution in context here

Original answer:

If you are using Linux, you can use xvfb for this. On a Debian based system, you can install xvfb as follows:

 $ sudo apt-get install xvfb 

With xvfb installed, run the following tests before running the tests:

 $ Xvfb :99 &>/dev/null & $ export DISPLAY=:99 

If you run your tests in the same console, TestFX will use a frame buffer instead of your main display. This way the tests will run, but you will not worry about opening windows and moving the mouse pointer.

+2
source

I agree with KDK to use Monocle, as it works like a charm with Jenkins. I could not get a reliable result from Hvbb on Jenkins. Below are the steps that I have taken and works for me.

Prepare monocle

You want to download Monocle from Monocle Github . There seems to be an api change, so you'll want to edit MonocleView.java with the method below added after loading. I'm not sure what I should use in the method, but found that it works without its implementation.

 @Override protected int _getNativeFrameBuffer(long ptr) { // TODO Auto-generated method stub return 0; } 

Install monocle

Create a Monocle jug and put the jar in the JRE (under jre / lib / ext path)

Run monocle with glass lib

Below is my maven command used in jenkins, you will have interest in the java runtime version part.

 $ mvn clean install -Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw 
0
source

Yes, you can perform silently testing JavaFx2 applications. You will need Monocle (part of OpenJFX). More details here: https://github.com/TestFX/Monocle

-1
source

Source: https://habr.com/ru/post/959027/


All Articles