Upgrading Selenium 3.141.59-gold to 4.0

  docker, javascript, selenium, selenium-webdriver

So one of the things I’m tasked to do is to create auto tests and we use selenium for this. We have been using version 3.141.59-gold but we have been getting a lot of test failures which seem to have been caused by the headless version using an outdated version of chrome. It is currently using 72.0.3626.81. Now I have been asked to upgrade the selenium version to 4.0 but I am struggling to do this. For this to run locally we use images from our docker hub.

Currently this is how the protractor.conf.js file looks like:

const nodeReduceCount = 7;
let isBrowserOpen = false;

exports.config = {
    framework: 'jasmine',
    seleniumAddress: settings.seleniumHubHost,
    capabilities: {
        'shardTestFiles': true,
        'maxInstances': Math.max(settings.countOfStreams - nodeReduceCount, 1),
        'browserName': settings.browser,
        'loggingPrefs': {
            performance: 'INFO',
        },
        'moz:firefoxOptions': getFirefoxOptions(),
        'goog:chromeOptions': getChromeOptions(),
    },
    suites: [
        suiteSettings.suite,
    ],
    jasmineNodeOpts: {
        defaultTimeoutInterval: settings.jasmineTimeout,
        isVerbose: false,
        includeStackTrace: true,
        realtimeFailure: false,
    },
    onPrepare: async () => {
        const jasmineEnv = jasmine.getEnv();
        const capabilities = await browser.getCapabilities();

        console.log(capabilities);

        registerReporter(jasmineEnv);

        jasmineEnv.beforeEach(async () => {
            jasmine.DEFAULT_TIMEOUT_INTERVAL = settings.jasmineTimeout;

            if (isBrowserOpen) {
                browser.restart();
            }

            await browser.driver.manage().window().setSize(settings.viewPort.width, settings.viewPort.height);

            isBrowserOpen = true;

            await browser.waitForAngularEnabled(false);
            await browser.get(settings.newPlanUrl());
        });
    },
};

function registerReporter(jasmineEnv) {
    jasmineEnv.addReporter(new SpecReporter({
        spec: {
            displayStacktrace: true,
        },
    }));

    const config = {
        id: browser.params.id,
        ...settings.reportPortal,
    };
    const agent = new ReportportalAgent(config);
    const reporter = agent.getJasmineReporter();

    jasmineEnv.afterAll(async (done) => {
        await agent.getPromiseFinishAllItems(agent.tempLaunchId);

        done();
    });

    global.reporter = reporter;
    jasmineEnv.addReporter(reporter);

    return agent;
}

function getFirefoxOptions() {
    const options = {};

    if (settings.headless) {
        options.args = ['--headless'];
    }

    return options;
}

function getChromeOptions() {
    const options = {
        args: [
            '--disable-gpu',
            '--no-sandbox',
            '--disable-extensions',
            '--disable-dev-shm-usage',
            '--disable-infobars',
        ],
    };

    if (settings.headless) {
        options.args.push('--headless');

        options.perfLoggingPrefs = {
            enableNetwork: true,
        };
    }

    return options;
}

The network is sorted in our docker-commmon.sh file:

#!/bin/bash

function checkParameters()
{
    missingParams=false;

    if [ -z "$NETWORK_NAME" ]; then
        echo "NETWORK_NAME must be set. [dev, grid]"
        missingParams=true
    fi

    if [ -z "$TEST_ENV" ]; then
        echo "TEST_ENV must be set. [dev, light, live, projectX]"
        missingParams=true
    fi

    if [ -z "$DEFAULT_BROWSER" ]; then
        echo "DEFAULT_BROWSER must be set. [chrome, firefox]"
        missingParams=true
    fi

    if [ -z "$SELENIUM_NODES" ]; then
        echo "SELENIUM_NODES must be set. [integer]"
        missingParams=true
    fi

    if [ -z "$REPORT_PORTAL_TOKEN" ]; then
        echo "REPORT_PORTAL_TOKEN must be set. [string]"
        missingParams=true
    fi

    if [ -z "$DB_USERNAME" ]; then
        echo "DB_USERNAME must be set. [string]"
        missingParams=true
    fi

    if [ -z "$DB_PASSWORD" ]; then
        echo "DB_USERNAME must be set. [string]"
        missingParams=true
    fi
}

function createHub()
{
    echo "Creating Hub"
    docker network create ${NETWORK_NAME}
    SEL_HUB_ID=$(docker run --net ${NETWORK_NAME} ${additionalDnsArgument} -d -p 4444:4444 --name selenium-hub selenium/hub:4.0)
    SEL_HUB_IP=$(docker inspect -f "{{ .NetworkSettings.Networks.${NETWORK_NAME}.IPAddress }}" ${SEL_HUB_ID})
    echo $SEL_HUB_ID
}

function createNodes()
{
    echo ""
    echo "Creating Nodes"
    COUNTER=0
    until [  $COUNTER -eq ${SELENIUM_NODES} ]; do
        docker run -d --net ${NETWORK_NAME} ${additionalDnsArgument} 
            -e NODE_MAX_INSTANCES=2 
            -e NODE_MAX_SESSION=2 
            -e HUB_HOST=selenium-hub 
            --shm-size=2g 
            --name selenium-node-${COUNTER} selenium/node-${DEFAULT_BROWSER}:4.0
        let COUNTER+=1
    done
}

function runTests()
{
    echo ""
    echo "Running Tests: ${REPORT_PORTAL_TOKEN}"
    docker run -i --net ${NETWORK_NAME} ${additionalDnsArgument} --rm 
        -e COUNT_OF_STREAMS=${SELENIUM_NODES} 
        -e SELENIUM_HUB_HOST=http://${SEL_HUB_IP}:4444 
        -e OGUSER=$(id -u) 
        -e OGGROUP=$(id -g) 
        -w /app 
        -v ${PWD}:/app 
        node:alpine sh -c 'npm install && npm start'
}

function cleanup()
{
    echo ""
    echo "Clean up containers"
    docker rm -f $(docker ps -a --filter=name=selenium-hub --format='{{ .ID }}')
    COUNTER=0
    until [  $COUNTER -eq ${SELENIUM_NODES} ]; do
        docker rm -f $(docker ps -a --filter=name=selenium-node-${COUNTER} --format='{{ .ID }}')
        let COUNTER+=1
    done

    docker network rm ${NETWORK_NAME}
}

checkParameters
createHub
createNodes
runTests
cleanup

The 3 lines I have changed is so:

    SEL_HUB_ID=$(docker run --net ${NETWORK_NAME} ${additionalDnsArgument} -d -p 4444:4444 --name selenium-hub selenium/hub:4.0)

--name selenium-node-${COUNTER} selenium/node-${DEFAULT_BROWSER}:4.0

-e SELENIUM_HUB_HOST=http://${SEL_HUB_IP}:4444

The 4.0 used to be 3.141.59-gold

And the selenium hub host used to include /wd/hub but after reading online I have seen that the url has now changed in 4.0 or is this incorrect?

When I now try to run the test I get stuck at the line:

[12:56:41] I/launcher – Running 1 instances of WebDriver
[12:56:41] I/hosted – Using the selenium server at "….." i’ve removed the ip address here

It just carries on running forever and never actually gets the capabilities set. In my docker when I am getting messages such as:

Started Selenium Hub 4.0.0-beta-1 (revision Unknown):
and
SE_EVENT_BUS_HOST not set, exiting!

What is the SE_EVENT_BUS_HOST? And how come this works fine with the old version but when trying to use 4.0 I am not able to run tests? Is there anything else I need to change? Thanks in advance for any help

Source: Docker Questions

LEAVE A COMMENT