1

I need to write automated GUI tests for apps built with and running on OpenJDK 14 (Swing & JFX) on Catalina.

This is easy, but when the tests are running the windows pop up on my screen, taking focus and interrupting my work.

On Linux I use xvfb to create a new virtual display (say 99) and run my tests with the environment variable DISPLAY=:99 and all is good.

However, OpenJDK on OS/X no longer has X11 bindings, so it is not possible to target an X11 environment.

Is there a way to do the equivalent on OS/X? I was wondering about scripting the creation of a new Desktop, without making it the currently displayed one, and ensuring that it is used as the Desktop on which to launch the app, but I haven't worked out how.

Prior research: No answer to Is there a Mac-native equivalent of xvfb for running on a headless Mac server?

  • Would a virtual machine or a docker container running Linux be an option? VirtualBox is free so a good place to start. – Thorbjørn Ravn Andersen May 06 '20 at 13:37
  • I run the full build in a docker container, so it's not a problem there, I just use xvfb. But it's substantially slower than running locally, so I like to do a quick gw check so that I get quicker feedback if I've broken a unit test or upset my linter.

    I can probably work around it by skipping the gui tests locally, but it would be nice if they ran.

    – Robert Elliot May 06 '20 at 13:58
  • If it is much slower it may have too little memory – Thorbjørn Ravn Andersen May 06 '20 at 14:02
  • Docker has access to 6g, and I've given gradle 2g. It's 19 seconds locally, 45 as a docker build; for me that's a big difference.

    (It's actually a bit more as I separate downloading dependencies in the dockerfile from doing the build, so that the build can be done offline, which adds another 14 seconds.)

    – Robert Elliot May 06 '20 at 15:14
  • Actually more like 11 seconds locally using the gradle daemon. – Robert Elliot May 06 '20 at 15:23
  • Do you run on the volume mounted from the host? That is slow. – Thorbjørn Ravn Andersen May 06 '20 at 18:44
  • I run it in the Dockerfile, as part of a multistage build. I'm using the experimental buildkit features to cache the ~/.gradle directory, otherwise it would have to redownload gradle & all the dependencies, which takes minutes. – Robert Elliot May 06 '20 at 18:51
  • It's not an answer, but I've given up & just disabled the tests unless the JVM reports the graphics device is X11 and the display is :99, or they are not running as part of the gradle build.

    This means they run as part of the docker build, and they run if I run the test directly in the IDE, but are skipped when I do a local build, so no unexpected windows popping up and grabbing focus.

    – Robert Elliot May 15 '20 at 20:07
  • What about installing XQuartz for an X11 environment so you can test in the manner you're used to. Disclaimer I haven't tested XQuartz on Catalina yet so YMMV. – Allan Aug 03 '20 at 17:32
  • Modern JVMs don't use X11 on Mac – Robert Elliot Aug 03 '20 at 17:32

0 Answers0