Xnee allows the recording and replaying of X protocol data. http://www.gnu.org/software/xnee/
To record data for Xnee, I'm currently using something like;
xnee -ae -o test-interaction.xnee -l -1
Which basically translates to capture all events ( -ae ) , output ( -o ) to test-interaction.xnee and keep capturing for ever ( -l -1 ). I stop capture with ctrl-c.
To then replay the data ( as in test-interaction.sh ), use;
xnee -rep -f test-interaction.xnee
I'm using xnee 1.07.