0 votes
1 view
in Devops and Agile by (22.5k points)

  Due to my circumstances for the current project I need to use 2 docker images together for selenium testing.

One is called Zalenium. I have it up and working via the docker-compose demo. Its basically like the selenium docker repo except that this can record video and show you live progress

zalenium:

      

  image: "dosel/zalenium"

        container_name: zalenium

        hostname: zalenium

        tty: true

        volumes:

            - /Users/josephastrahan/seluser/videos:/home/seluser/videos

            - /var/run/docker.sock:/var/run/docker.sock

            - /usr/bin/docker:/usr/bin/docker

        ports:

            - 4444:4444

        command: >

          start --chromeContainers 1

                --firefoxContainers 1

                --maxDockerSeleniumContainers 8

                --screenWidth 800 --screenHeight 600

                --timeZone "Europe/Berlin"

                --videoRecordingEnabled true

                --sauceLabsEnabled false

                --browserStackEnabled false

                --testingBotEnabled false

                --startTunnel false

        environment:

          - HOST_UID

          - HOST_GID

          - SAUCE_USERNAME

          - SAUCE_ACCESS_KEY

          - BROWSER_STACK_USER

          - BROWSER_STACK_KEY

          - TESTINGBOT_KEY

          - TESTINGBOT_SECRET

The other image is a NodeJS server pre-installed with Mocha and the nodejs (npm package) of selenium-webdriver so that I can run the commands to trigger browser automation. Details on this here (https://github.com/SeleniumHQ/selenium/tree/master/javascript/node/selenium-webdriver) and here (https://hub.docker.com/r/qmu1/selenium-webdriver-node/)You can see Zalenium running from docker compose just fine here. I can see the time updating every second correctly so it's definitely showing a live view.enter image description hereAccording to the documentation for the other docker container I'm using which is here (https://hub.docker.com/r/qmu1/selenium-webdriver-node/), I should be able to run tests simply with a docker command like this. 

HERE=$(pwd)

echo ""

echo "----------------------------"

echo "----------------------------"

echo ""

docker run -it --rm \

    -v $HERE:/workspace \

    qmu1/selenium-webdriver-node:latest /bin/sh -c "

        mocha sample.js --timeout=10000

"

I changed this command to fit my needs until it seemed liked it worked.

docker run -it --rm --net=distributiontech_default -v $HERE:/workspace qmu1/selenium-webdriver-node:latest /bin/sh -c "mocha tests/seleniumtest.js --timeout=10000"

I got the response:

all modules are ready!

  0 passing (1ms)

The issue using Zalenium is that I didn't see anything happen on the viewer to verify it was even working?

My selenium script looks like below.

//Run using this project (https://github.com/qmu/dockerfiles/blob/master/src/selenium-webdriver-node/example/bin/run)

"use strict";

const webdriver = require('selenium-webdriver'),

    By = webdriver.By,

    until = webdriver.until,

    test = require('selenium-webdriver/testing');

const expect = require('expect.js');

const assert = require('assert');

// var driver = new webdriver.Builder()

//    .withCapabilities(webdriver.Capabilities.chrome())

//    .usingServer('http://localhost:4444/wd/hub')

//    .build();

var driver = new webdriver.Builder()

    .forBrowser('firefox')

    .usingServer('http://zalenium:4444/wd/hub')

    .build();

driver.get('http://www.google.com');

driver.findElement(webdriver.By.name('q')).sendKeys('simple programmer');

driver.findElement(webdriver.By.name('btnG')).click();

//driver.quit();

console.log('all modules are ready!');

I tried without the --net command and with... and  no luck. Just so you can see the network details and containers running. You can see that zalenium is added to the distributiontech_default network.

enter image description here

enter image description here

enter image description here

How do I connect the docker container running the selenium code to the docker hub running Zalenium?

I tried changing this to...

var driver = new webdriver.Builder()

    .forBrowser('firefox')

    .usingServer('http://localhost:4444/wd/hub')

    .build();

but, no luck either. I can put any fake address I want where it says localhost and it doesn't seem to throw any errors or anything either oddly enough.

1 Answer

0 votes
by (57.5k points)

I had a similar issue and I found I could use the --link command so I could link a named Zalenium grid instance with the docker instance which executes my tests:

docker run --privileged --name stg-selenium-client --rm=true --link zalenium:hub hub.platformservices.io/sbg_core_automation/core-test-runner-with-maven-dependencies:0.12 <command to execute tests>
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...