Run Selenium Tests on Fargate From Jenkins Pipelines
Selenium automates browser interactions to test website functionality however this requires infrastructure and automation to run the Selenium hub and required nodes. Recently we released a way to run Selenium on Farget with the ciinabox2 0.4.0 release but it runs 100% of the time which could be costly if you’re not utilising it. With this ciinabox-pipeline functionality you can spin up the Selenium cluster from your pipeline, run the test and then destroy it. This is a good solution if you are running a small number of infrequent tests.
The Selenium cluster is started and stopped from the pipeline utilising the Jenkins pipeline post always step to stop the cluster so we don’t forget to stop it in case we hit an error. The pipeline functions use the opensource Selenium docker images which as browser support for Chrome, Firefox and Opera.
The following example starts a Selenium cluster with firefox and chrome nodes on the ciinabox ECS cluster and exposes a private endpoint on port 4444.
pipeline {
agent {
label 'linux'
}
stages {
stage('run selenium test') {
steps {
// Start the Selenium cluster with the default settings
startSelenium()
// Execute the tests
echo "execute the selenium tests against the selenium endpoint ${env.SELENIUM_ENDPOINT}"
}
post {
always {
// Stop the Selenium cluster once tests complete
stopSelenium()
}
}
}
}
}
This endpoint can be retrieved via environment variables
echo "Selenium private IP address ${env.SELENIUM_ENDPOINT}"
echo "Selenium port ${env.SELENIUM_PORT}"
echo "Selenium socket <ip-address>:<port> ${env.SELENIUM_SOCKET}"
The startSelenium()
and stopSelenium()
functions by default will lookup the the current ciinabox cluster details including the subnets and security group. You’ll need to make sure port 4444
is open on the security group. These settings can be overridden in the the method, see the functions startSelenium() and stopSelenium() for documentation.