I am writing a TestFX test case to cover a Java desktop application. One of the interactions calls showDocument() to display an html document using the browser. When running the test locally using Gradle, my test works correctly. But when I run it on Jenkins (using a MacOS agent) the test fails.
14:55:10 java.awt.HeadlessException
14:55:10 at java.desktop/java.awt.Desktop.getDesktop(Desktop.java:301)
14:55:10 at javafx.graphics/com.sun.javafx.application.HostServicesDelegate$StandaloneHostService.showDocument(HostServicesDelegate.java:133)
14:55:10 at javafx.graphics/javafx.application.HostServices.showDocument(HostServices.java:115)
The problem is caused when Desktop checks GraphicsEnvironment.isHeadless()
Why is this error happening? I read that a HeadlessException occurs when there is not a GUI to use (Display, Keyboard, Mouse) but my agent indeed has a GUI. This test works correctly on Windows agents but not on MacOS. How can I avoid this error and execute the automated test on Jenkins?