Basically you need to have program you can run at the command line that GoCD can call for you as part of a test task/job/stage.
Then you need a GoCD agent with all the necessary software installed, and run that command. (Or have a docker image with all the necessary software, and run the tests in that command).
One common problem is that selenium automates browsers, and browsers tend to want to have a display environment, and GoCD tends to run on servers without any GUI.
On Linux, there's a tool called Xvfb
that provides a virtual X server which tricks the browser into thinking there is a GUI.
This is a small bash script that we run before starting the Selenium tests:
#!/bin/bash
DISPLAY=":99"
# The last one wins
killall -q Xvfb
# Start virtual x-server.
Xvfb -ac :99 -screen 0 1280x1024x16 > x11.log 2>&1 &
XSERVER_PID=$!
sleep 5
kill -0 $XSERVER_PID
if [ $? -gt 0 ]; then
echo "cannot start Xvfb"
exit 1
fi
# Start VNC server for watching the test runs and debugging problems.
x11vnc --listen 0.0.0.0 -rfbport 5900 -display :99 -forever >> x11.log 2>&1 &
export DISPLAY=:99
# Window manager for enabling resize of browser window.
fvwm >> x11.log 2>&1 &
Note that this also starts a lightweight window manager (fvwm) to enable tests that resize browser windows.