Integration tests for Ivy projects can be done using Selenium (Selenide) . Selenium itself just simulates a browser like Firefox or Chrome. Like all tests you want to run them automated on a build infrastructure like Jenkins.
To automate these tests, browser installations are needed. We @ ivyTeam have now fully containerized 🐳 all our builds. The definition of our builds and the software needed to build them is part of the source code - in the Jenkinsfile
.
What we need
We need now two containers 📦. The first container is the Selenium container (selenium/standalone-firefox:3) where we choose Firefox. One small optimization, we don't start the virtual frame buffer (XVFB), because @IvyWebTests
are headless by default (performance first approach 🏎). The second container is a maven (maven:3.6.3-jdk-11) container to build the ivy projects and run the web tests.
Now comes the tricky part - to allow these two containers to communicate with each other in isolation on the Jenkins node, we set up a Docker network and put the two containers on that network. We define host names for these container by using the--name
flag. Now the @IvyWebTests
needs to know these names so we have to set the JVM properties test-engine-url
and selenide-remote
.
Jenkinsfile
-Snippet:
def random = (new Random()).nextInt(10000000)
def networkName = "build-" + random
def seleniumName = "selenium-" + random
def ivyName = "ivy-" + random
sh "docker network create ${networkName}"
try {
docker.image("selenium/standalone-firefox:3").withRun("-e START_XVFB=false --shm-size=2g --name ${seleniumName} --network ${networkName}") {
docker.image('maven:3.6.3-jdk-11').inside("--name ${ivyName} --network ${networkName}") {
sh "clean verify -Dtest.engine.url=http://${ivyName}:8080 -Dselenide.remote=http://${seleniumName}:4444/wd/hub"
}
}
} finally {
sh "docker network rm ${networkName}"
}
And how do you run selenium tests ?