I run “web tests” on a remote server. I use Selenium to act like a person interacting with a website, viewing and entering data. Selenium is pretty awesome, it can drive a real web browser like Firefox.
Even better is to have these web tests run automatically every time I commit code. I use Jenkins for this. Jenkins even fires up a headless desktop so Selenium can run Firefox.
When a web test breaks (especially in some way I can’t reproduce on my local desktop), sometimes it helps to actually see what Jenkins sees as it runs the test. Here’s a quick guide for doing so on an Ubuntu GNU/Linux server.
- Connect to the remote server using SSH. Install VNC server:
sudo apt-get install vnc4-server
- On the remote server, become the user tests run as. For example:
sudo su - ci
- Set a password for the VNC server using the
vncpasswdcommand. - Start headless X server by running
vncserver. Note the given display. Ifexample.com:1is included in the output ofvncserver, the display is:1. -
Figure out which port the VNC server is using. I usually do something like
sudo netstat -nape | grep '^tcp.*LISTEN.*vnc.*'
Here’s some example output:
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 107 3099855 13233/Xvnc4 tcp6 0 0 :::5901 :::* LISTEN 107 3099858 13233/Xvnc4
By trial and error, I figured out that 5901 was the port I should use.
-
Port-forward VNC to your local machine.
- Disconnect from the server.
- Reconnect, including
-L10000:localhost:5901on your SSH command line. - Leave this connection open.
-
On your local machine, connect a VNC client to localhost:10000. An X terminal should be displayed.
-
In the X terminal, run your web tests.
- When finished debugging, kill the X server using the display noted earlier.
vncserver -kill :1
