UI Tests in Another Display in Linux

UI tests are delicate since when you run them, you must not interact with the computer, or you will disturb the tests, which will likely fail.

In Linux, you can use Xvfb, but windows will not have a title, which might break UI tests that rely on that. For example, Eclipse SWTBot tests work best if windows have titles.

The solution (I’m still talking about Linux) is to use Xephyr:

  • you start Xephyr by specifying a DISPLAY number
  • you start a Window manager on the same display
  • you run your UI tests on the same display

Now, you can interact with your computer without disturbing the UI tests. That’s very important if you need to debug the UI tests: if they don’t run in another display, the UI tests will likely fail if you switch to the debugger.

IMPORTANT: this works only when you’re on an X11 session (not Wayland).

The name of the package for Xephyr depends on your distribution. For example, in Arch Linux, you install it like that:

Now, from a terminal window, you can start Xephyr (in this example, using the DISPLAY 50) and run a Window manager inside, specifying that it must run with X11.

If you’re on Gnome, you use mutter:

If you’re on KDE, you use kwin:

This is an example in Gnome: I ran the above commands, and then, from the same terminal (where DISPLAY is set to “:50”), I started the Gnome Text Editor, which appears in the Xephyr window:

In the following screenshot, I’m running the Maven build of one of the examples of my TDD Book, which uses AssertJ Swing for the UI tests of a simple Java Swing application (I started another terminal, where I exported the DISPLAY environment variable set to “:50”):

The UI tests (see the “MyAppWindow”) are undisturbed in the Xephyr window, and I can interact with my computer without breaking them.

From Eclipse, e.g., for a SWTBot test, you have to tweak the run configuration in the “Environment” tab:

And these are a few SWTBot tests for my Eclipse project EMF Parsley, which started from Eclipse but running in the Xephyr window:

Happy UI testing! 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.