CodeceptJS - Selenium Container - TeamCity


#1

Have you ever got trouble to make CodeceptJS is running with a selenium container in a CI like TeamCity for instance to test against a web app that is up and running in a TeamCity agent? So I hope this guide somehow guide you a bit to solve that issue.

First, let’s kill any running selenium container before starting a new one, in my case, I want to test against Chrome, keep it in mind for now.

docker kill $(docker ps -q)
docker run -d -p 4444:4444 selenium/standalone-chrome:latest

Next, install all needed libs and start your app locally in Teamcity. The command to start the app would be varied based on your project. This is how it looks like in my current project.

npm i & npm run dev-serve &

Okay, now let’s take a look at the codeceptjs config. So you may wonder, what process.env.AGENT_IP is? Yeah, to make the selenium container access the local app on Teamcity, we need to get the TeamCity agent IP. Don’t know how to get it? No worries, I show you in the next steps.

   helpers: {
       WebDriver: {
            url: `http://${process.env.AGENT_IP}:8000/`,
            browser: 'chrome',
            smartWait: 10000,
            waitForTimeout: 10000,
            desiredCapabilities: {
                "chromeOptions": {
                    "args": ["--headless", "--disable-gpu", "--window-size=1920,1080"]
                }
            },
            keepCookies: false,
            restart: true,
            windowSize: '1920x1080',
        },
    },

Well, now you need to get the Teamcity agent IP, that’s simple

export AGENT_IP=$(hostname -I | cut -d’ ’ -f1)
echo $AGENT_IP

Great, let’s start the tests. Again, this is just an example. You should modify it to fit with your current project.

./node_modules/.bin/codeceptjs run --grep @smoke_desktop --config=./test/codeceptjs/codecept.conf.js

Start your build from CI. It may vary from other CIs but I think mostly everything is not much different.
Nothing more, nothing less. That’s it.