1

UI Tests in Another Display in Linux

 1 year ago
source link: https://www.lorenzobettini.it/2022/12/ui-tests-in-another-display-in-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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:

sudo pacman -S xorg-server-xephyr

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:

Xephyr -screen 1024x768 :50 &
sleep 5
export DISPLAY=:50
mutter --x11 --sm-disable --replace 2> ~/tmp/metacity.err &

If you’re on KDE, you use kwin:

Xephyr -screen 1024x768 :50 &
sleep 5
export DISPLAY=:50
kwin_x11 --replace 2> ~/tmp/kwin.err &

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:

gnome-text-editor-in-xephyr.png?resize=625%2C306&ssl=1

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”):

example-xephyr-assertj-swing.png?resize=625%2C305&ssl=1

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:

swtbot-launch-in-another-display.png?resize=625%2C213&ssl=1

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

example-xephyr-swtbot.png?resize=625%2C326&ssl=1

Happy UI testing! 🙂

Like this:

Loading...

Related


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK