Integrating Ghost Inspector with Codeship

Written by: Kelly Andrews
2 min read
Stay connected

At Codeship, we’re pleased to be able to integrate with several third-party products across a variety of areas to ensure your CI/CD workflows are that much smoother. For example, Ghost Inspector lets you write and run UI and browser tests as part of your builds without configuring local servers and managing your own browsers.

By using Ghost Inspector, you can easily test your UI without complex browser testing overhead. Their documentation does a great job of providing more information, in addition to the setup instructions below for both Codeship Pro and Codeship Basic.

Codeship Pro

You will need to add your Ghost Inspector API key and suite ID to your encrypted environment variables that you encrypt and include in your codeship-services.yml file.

Triggering the suite

Next, you will need to add the following commands to a script, placed in your repository, that you will call from your codeship-steps.yml file:

- name: Ghost Inspector
  service: app
  command: ghost-inspector.sh

Inside the script, you will need the following Ghost Inspector commands:

# Execute Ghost Inspector suite via API and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY" > ghostinspector.json
# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

Advanced testing

For a more complex setup with more granular control, Ghost Inspector recommends setting up and using an ngrok tunnel to triggering the Ghost Inspector test suite.

To do this, you will want to change the script you run from your codeship-steps.yml file to the following:

# Start our application (Command needs to be customized)
node server.js &
# Download ngrok and unzip
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
chmod +x ngrok
# Download JSON parser for determining ngrok tunnel
wget https://stedolan.github.io/jq/download/linux64/jq
chmod +x jq
# Intialize ngrok and open tunnel to our application (Port 3000 needs to be customized)
./ngrok authtoken $NGROK_TOKEN
./ngrok http 3000 > /dev/null &
# Execute Ghost Inspector suite via API using the ngrok tunnel and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY&startUrl=$(curl 'http://localhost:4040/api/tunnels' | ./jq -r '.tunnels[1].public_url')" > ghostinspector.json
# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

Codeship Basic

Moving onto the setup for Codeship Basic, you will need to add your Ghost Inspector API key and suite ID to your to your project’s environment variables.

You can do this by navigating to Project Settings and then clicking on the Environment tab.

Triggering the suite

Once your Ghost Inspector credentials are loaded via your environment variables, you will want to run the following commands, directly or via a script, in your project’s setup commands:

# Execute Ghost Inspector suite via API and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY" > ghostinspector.json
# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

Advanced testing

For a more complex setup with more granular control, Ghost Inspector recommends setting up and using an ngrok tunnel to triggering the Ghost Inspector test suite.

To do this, you will want to add the following code to a script in your repository that you run in your setup commands:

# Start our application (Command needs to be customized)
node server.js &
# Download ngrok and unzip
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
chmod +x ngrok
# Download JSON parser for determining ngrok tunnel
wget https://stedolan.github.io/jq/download/linux64/jq
chmod +x jq
# Intialize ngrok and open tunnel to our application (Port 3000 needs to be customized)
./ngrok authtoken $NGROK_TOKEN
./ngrok http 3000 > /dev/null &
# Execute Ghost Inspector suite via API using the ngrok tunnel and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY&startUrl=$(curl 'http://localhost:4040/api/tunnels' | ./jq -r '.tunnels[1].public_url')" > ghostinspector.json
# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

Stay up to date

We'll never share your email address and you can opt out at any time, we promise.