Home Ask Login Register

Developers Planet

Your answer is one click away!

Kostas Demiris February 2016

Creating a testing infrastructure with Pytest , Selenium Grid and Docker

Based on this article, I successfully created the scalable selenium grid . Then I want to run my test suites [written in Python] using Pytest into that Grid.

I am new to Docker and trying to find the best way to migrate my testing procedures into the microservices architecture. Essentially I want to give the ability to the devs to setup a full testing infrastructure locally on their PCs.

So, I have 4 Dockerfiles and 1 docker-compose.yml .

The BASE dockerfile:

FROM ubuntu


# Update repos for Java
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
software-properties-common \
&& rm -rf /var/lib/apt/lists/*
RUN add-apt-repository -y ppa:webupd8team/java

RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
RUN echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections

# Install Java7
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
oracle-java7-installer \
&& rm -rf /var/lib/apt/lists/*

# Download Selenium Server
RUN wget http://selenium-release.storage.googleapis.com/${SEL_VERSION%.*}/selenium-server-standalone-${SEL_VERSION}.jar

The HUB dockerfile :

FROM org/grid:base


# Add and set permissions to the script that will launch the hub
ADD register-hub.sh /var/register-hub.sh
RUN chmod 755 /var/register-hub.sh

# start a shell and run the script
CMD ["/bin/bash", "/var/register-hub.sh"]

The NODE dockerfile :

FROM org/grid:base

# set the FF version to use

# Update and install what's needed
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
firefox \
xvfb \
bzip2 \
&& rm -rf /var        


dnephin February 2016

I think you're almost there.

I would add a pytest service to the docker-compose.yml, and remove the volumes_from and external_links from the hub image (so that it looks more like the example from the blog post you linked).

The pytest service will run the python code, but it should connect to hub to run selenium. I believe somewhere in the org_QA_folder there is configuration that tries to start up selenium locally. It needs to be reconfigured to use the hub server instead.

Kostas Demiris February 2016

I finally made it to work like this:

From my code I use this:

class Fixtures_docker(unittest.TestCase):

    def setUp(self, hub_ip="http://HUB_CONTAINER_IP", hub_port=4444):
        print "--Fixtures_docker in config.py trying to run on--: %s:%s"%(hub_ip, hub_port)

        if platform.system() == 'Linux':
            from pyvirtualdisplay import Display

            self.display = Display(visible=0, size=(1024, 768))

        if browser == "Firefox": 
            self.wd = webdriver.Remote(
                command_executor=hub_ip + ':' + str(hub_port) + '/wd/hub',
                        "browserName"   : "firefox",
                        # "maxInstances"  : 10,
                        "seleniumProtocol": "WebDriver",
                        "platform"      : "ANY",
                        "node"          : hub_port

        # for debugging purposes from local machine
        elif browser == "Firefox" and os == "Windows":
            self.wd = webdriver.Remote(
                command_executor=hub_ip + ':' + str(hub_port) + '/wd/hub',
                        # FIREFOX -> WINDOWS
                        # "firefox_binary":"C:\\firefox3\Firefox3.exe", # path to find another version of ff
                        "browserName"   : "firefox",
                        #"version"      : "3.0b3", # trying to run a specific ff version
                        "platform"      : "WINDOWS",
                        "node"          : hub_port,
                        "maxSession"    : 5


    def tearDown(self):
        if platform.system() == 'Linux':

and in the docker-compose.yml:

  image: org/grid:hub # image must already exist

Post Status

Asked in February 2016
Viewed 1,344 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved