Testing Applications with Xnee

Is your clicking finger sore from testing your GUI program? Script your regression tests with Xnee.
Xnee Installation

Xnee is a GNU package, and the sources can be found at the Xnee home page. Download the latest source; as of this writing, the latest version is 1.0.6. Extract the package, and then configure, build and install it:

tar zxvf xnee-1.0.6.tar.gz
cd xnee-1.0.6
./configure
make
make install

RPM packages are available at the home page, and Xnee also is available in the FreeBSD ports tree. Xnee comes with a user manual and a developer manual in various formats. The TeX sources to the manuals are distributed with Xnee and covered under GNU FDL. Instead of building the documents yourself, you can download the format of your choice (PDF, HTML, INFO and TXT) from the Xnee home page. As of this writing, the Xnee documentation version is 1.0.4. Extract the documents:

tar zxvf xnee-doc-1.0.4.tar.gz

When running Xnee, make sure the RECORD extension is enabled. On XFree86 make sure the RECORD module is loaded. Open the XFree86 configuration file, typically /etc/X11/XF86Config-4, and look in the Module section. The following line should be included:

Load  "record"

See the Xnee FAQ for more information about this.

Simple Usage Examples

We don't go into any details about Xnee in this section, but rather begin slowly with a simple example. Start Xnee with the --all-events option. This sets up the recording of a few events. The option is not useful when doing serious Xneeing. It is intended to simplify your introduction to using Xnee:

xnee --all-events

When moving the mouse or pressing the buttons or keys, Xnee prints information about the action. We move on to record a simple session that we replay immediately. To record 20 mouse motions, start Xnee like this:

xnee --record --out session1.xnr \
--device-event-range MotionNotify --loops 20

The options on the command line mean use recording mode (--record), save output in a file called session1.xnr (--out session1.xnr), record the device-event MotionNotify (--device-event-range MotionNotify) and record 20 events (--loops 20).

To replay this event, start Xnee like this:

xnee --replay --file session1.xnr

The options on the command line mean use replay mode (--replay), and read data to replay from file session1.xnr (--file session1.xnr).

Setting Up Recording Ranges

Xnee uses ranges to explain what is to be recorded. Ranges have a start value and a stop value. The following data can be recorded: core-requests, device-event, delivered-event, error, reply, extension requests and extension replies. We don't describe the above data in this article. If you want to read more, see the RECORD extension documents. When, for example, you want to record the device event MotionNotify, use:

--device-event-range MotionNotify

To record the events from KeyPress up to MotionNotify and CreateNotify, use:

--device-event-range KeyPress-MotionNotify,\
CreateNotify

You can use the number corresponding to the event name instead of the name itself if you want shorter command lines. To find the number for the data you want to record, use Xnee's --print-data-name option:

xnee --print-data-name

Stopping Xnee

You can stop recording by setting the number of the data to record (--loops option), or you can interrupt Xnee by sending a TERM signal (pressing Ctrl-C in the terminal window where you started Xnee). Alternatively, you can dedicate a modifier and key combination that won't be used to do anything else during recording. Setting the modifier and key is done with the --stop-key option. To set up Xnee so it stops recording when Ctrl-Alt-A are pressed, add the following to the command-line option:

--stop-key Control+Alt,a

Synchronize

But why even bother to record data other than device events when you can't replay it? Xnee uses that other data to synchronize, which is where things get complicated. Think of recording a session when using Galeon or any other Web browser. When recording, everything goes well and the network is up and running. But when replaying the Galeon session, you can't reach the Internet. If not for synchronization, Xnee might replay user events such as clicking on a link on the Web page. If Galeon could not load the page, it is not useful to continue the replay until the network is up and the page can be loaded.

When recording other data, we can use it to synchronize the session. For example, if we record the data sent when displaying the Web page in the Galeon window, we can wait for the same data to be sent when replaying. This ensures that the Web page is loaded before we go on and replay the coming events. In this example, we skip a lot of the X protocol data sent when recording in order to keep it simple (see Table 1). When replaying this simple session, Xnee uses the same events (see Table 2).

Table 1. X Events at the Start of a Galeon Test

Protocol Data NameUser or Client Action
MotionNotifyThe user moves the pointer to the Galeon launch icon.
ButtonPressThe user presses the button and Galeon starts.
CreateNotifyGaleon is started and the window is created.
VisibilityNotifyThe start page is loaded and visible to the user.
MotionNotifyThe user moves the pointer to a link on the loaded page.
ButtonPressThe user clicks on the link.
VisibilityNotifyThe new page is loaded and visible to the user.

Table 2. How Xnee Replays a Test Session

Protocol Data NameXnee Action
MotionNotifyXnee moves the pointer to the Galeon launch icon.
ButtonPressXnee presses the button and Galeon starts.
CreateNotifyXnee waits for this event to be sent. When Xnee receives a CreateNotify notice, it continues with the next event in the file.
VisibilityNotifyXnee waits for this event to be sent. Because the network is down and the page can't be loaded, this event isn't sent. Xnee continues to wait. Eventually the event is sent and Xnee can continue.
MotionNotifyXnee moves the pointer to a link on the loaded page.
ButtonPressXnee clicks on this link.
VisibilityNotifyThe new page is loaded and visible.
______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

how to log mouse clicks

diana's picture

Hi,

How can i record mouse clicks in addition to mouse motions with cnee?

i am using this command but it it is only recording mouse motions:

$cnee --record --mouse --events-to-record -1 --device-event-range ButtonPress-MotionNotify

Regards,

diana

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix