Skip to content

Instantly share code, notes, and snippets.

@mrfelton
Created December 3, 2013 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrfelton/7775884 to your computer and use it in GitHub Desktop.
Save mrfelton/7775884 to your computer and use it in GitHub Desktop.
## CONFIG ---
# Some variables to make our life easier.
# These are sourced in from a local config file so that we can keep them out of git.
# PANTHEON_SITE_NAME='X'
# PANTHEON_USERNAME='X'
# PANTHEON_PASSWORD='X'
# PANTHEON_SITE_USERNAME='X'
# PANTHEON_SITE_PASSWORD='X'
# TEST_SUITE_FILE='X'#
#
# Actually, dont do this - we'll do this in Jenkins
# so that we can override the vars per build job.
#
# if [ -f "$JENKINS_HOME/.pantheon_auth.concern" ] ; then
# . "$JENKINS_HOME/.pantheon_auth.concern"
# else
# echo "[ERROR] Could not locate config file at \$JENKINS_HOME/.pantheon_auth.concern." 1>&2
# exit 1
# fi
## SETUP ---
# In order to give the most accurate run of the tests, we instantiate a brand new
# multidev environment, cloned from production to run the selenium test suite against.
drush pauth $PANTHEON_USERNAME --password="$PANTHEON_PASSWORD"
SITE_UUID=$(drush psite-uuid $PANTHEON_SITE_NAME)
drush pantheon-site-environment-create $SITE_UUID test-$BUILD_NUMBER --source=live
# Create somewhere to store the results of our selenium tests.
mkdir -p "$WORKSPACE/seleniumhq"
## TEST AGAINST MASTER DEV SITE ---
# Run the Selenium tests against the main dev site.
cd "$JENKINS_HOME"
drush @pantheon.$PANTHEON_SITE_NAME.dev updatedb --strict=0 -y
cd "$WORKSPACE/concern_tests"
git checkout 7.x-1.x
git pull
export DISPLAY=":99" && java -jar /var/lib/selenium/selenium-server.jar -trustAllSSLCertificates -ensureCleanSession -htmlSuite *firefox "https://$PANTHEON_SITE_USERNAME:$PANTHEON_SITE_PASSWORD@dev-$PANTHEON_SITE_NAME.gotpantheon.com/" "$WORKSPACE/concern_tests/$TEST_SUITE_FILE" "$WORKSPACE/seleniumhq/result-dev.html"
## TEST AGAINST DEDICATED TEST ENVIRONMENT ---
# By now the test environent should be up and running since our test suite takes a while.
# Put test env in staging mode to prepare it for tests to run (enables test content etc).
# NOTE: we need to be outside of the drupal root so that all remote drush commands are available.
cd "$JENKINS_HOME"
drush pantheon-aliases
drush @pantheon.$PANTHEON_SITE_NAME.test-$BUILD_NUMBER env-switch staging --force --strict=0
cd "$WORKSPACE/concern_tests"
git checkout 7.x-1.x-stage
git pull
export DISPLAY=":99" && java -jar /var/lib/selenium/selenium-server.jar -trustAllSSLCertificates -ensureCleanSession -htmlSuite *firefox "https://$PANTHEON_SITE_USERNAME:$PANTHEON_SITE_PASSWORD@test-$BUILD_NUMBER-$PANTHEON_SITE_NAME.gotpantheon.com/" "$WORKSPACE/concern_tests/$TEST_SUITE_FILE" "$WORKSPACE/seleniumhq/result-test.html"
## CLEANUP ---
# If we got this far, everything is ok so destroy the test environment!
drush pantheon-site-environment-delete $SITE_UUID test-$BUILD_NUMBER
## NOTES ---
# In order to be able to run drush commands against the multidev test environment
# the Jenkins user needs to be able to connect to hosts over ssh without requiring
# that the ssh key is manually validated.
#
# Add the following to /var/lib/jenkins/.ssh/config
#
# StrictHostKeyChecking no
# UserKnownHostsFile=/dev/null
## TODO ---
# Currently pantheon-site-environment-create does not notify us correctly when it
# has finished. The above works because our selenium test suite takes a few minutes
# to run, and it just so happens that by the time this has finished the test env
# is ready. However, this means that we have to create the test env as the very
# first thing to ensure they are ready for when we need them. Idelly we would not
# actually create the test environment first and only create it if/when the tests
# pass on dev. That would save the creation of losts of unnecessacery test envs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment