Selenium WebDriver – How To Run Multiple Test Suites Using Docker Compose – Part 2

Overview:

The modern cloud infrastructure, continuous integration & deployment processes etc have completely changed the way how applications are deployed in production nowadays. In order to release new features faster in Production, you need to reduce time we take in the each phase of the SDLC. As an automation lead/architect, It could be your responsibility to have a proper infrastructure to speed up the automated test execution! When it comes to infrastructure automation, Docker plays a major role there!

Testautomationguru already has few docker and selenium related articles which talks about setting up the dockerized selenium grid & running a docker container with a test.

  1. Setting up Dockerized Selenium grid.
  2. Running Automated Tests Inside A Docker Container – Part 1

Before continuing this article, I would request you to read the above 2 first! I am explaining few things here assuming that you have already read them.

This article is going to explain how to combine above 2 articles – ie running all regression testcases with multiple test suites & selenium grid with a single docker-compose file.

Udemy – Selenium WebDriver With Docker:

TestAutomationGuru has released a brand new course in Udemy on Selenium WebDriver with Docker. 14 hours course which starts with installing docker from scratch and goes all the way up to running dockerized selenium tests on AWS cloud. Please access the above link which gives you the special discount.  You can also get your money back if you do not like the course within 30 days.

Test Suites:

We have thousands of automated tests for my application. I categorize / group them, based on the application business functionality / module and create multiple test suites. So that any change in specific module can trigger corresponding test suites.

Lets assume – in our sample application for this article, we have 3 modules.

  1. Registration Module
  2. Search Module
  3. Order Module

Lets also assume that, each module has hundreds of automated test cases already.  In order to get my automated results as early as possible, We need  to have multiple hosts + Selenium Grid set up as shown here to run the entire regression test suites!!

 

reg-suite-set-up

 

Setting up all the above machines with all the dependencies is a nightmare!

Lets see how we could set up the above entire infrastructure in a single compose file and execute the tests!!

Sample Project:

For the demo, I have created a simple project as shown here. This sample project is available in Github.

reg-suite-proj-set-up-1

Page Objects:

  • Above project has 2 page objects
    • SearchPage – acts as a page object for the search module (this is actually a page object for google search).
    • OrderPage  – acts as a page object for order module (this is actually a page object for  demoqa site).

Test Classes:

  • BaseTest – a base test which contains the logic for driver instantiation.
  • SearchTest – extends BaseTest – contains the test for the Search Module.
  • OrderTest – extends BaseTest – contains the test for the Order Module.

Test Suites:

In real life, we will have multiple tests for a single module. In our sample project, we have only one test. We collect all the tests for a module and create a test suite file as shown here.

  • order-module.xml – a testNG suite file which invokes order module tests.
<suite name="order-module" parallel="none" allow-return-values="true" >
  <test name="order-test">
    <classes>
      <class name="com.testautomationguru.container.test.OrderTest"/>
    </classes>
  </test>
</suite>
  • search-module.xml – a testNG suite file which invokes search module tests.
<suite name="search-module" parallel="none" allow-return-values="true" >
  <test name="search-test">
    <classes>
      <class name="com.testautomationguru.container.test.SearchTest"/>
    </classes>
  </test>
</suite>

Test Requirement:

In order to do the complete regression testing for the application, Lets assume that we need to invoke the tests for both modules as given below.

  • order module testing on chrome
  • search module testing on firefox

Dockerfile:

I create the below Dockerfile which creates an image which contains all the dependencies to the run the test including the testNG suite files. [I have already explained this here – Please read the article if you have not already]

FROM openjdk:8-jre-slim

# Add the jar with all the dependencies
ADD  target/container-test.jar /usr/share/tag/container-test.jar

# Add the suite xmls
ADD order-module.xml /usr/share/tag/order-module.xml
ADD search-module.xml /usr/share/tag/search-module.xml

# Command line to execute the test
# Expects below ennvironment variables
# BROWSER = chrome / firefox
# MODULE  = order-module / search-module
# SELENIUM_HUB = selenium hub hostname / ipaddress

ENTRYPOINT /usr/bin/java -cp /usr/share/tag/container-test.jar -DseleniumHubHost=$SELENIUM_HUB -Dbrowser=$BROWSER org.testng.TestNG /usr/share/tag/$MODULE

So basically idea here is to create a single image which accepts browser, module as parameters – then create a container which tests specific module.

Creating An Image:

Executing below command compiles, packages the jar with all the dependencies and builds the docker image based on the above Dockerfile.

mvn clean package

 

reg-suite-build-1

Docker Compose File:

Testautomationguru has already explained setting up the whole selenium grid infrastructure using docker-compose in this article – Setting up Dockerized Selenium grid.

version: "3"
services:
  selenium-hub:
    image: selenium/hub
    container_name: selenium-hub
    ports:
      - "4444:4444"
  chrome:
    image: selenium/node-chrome
    depends_on:
      - selenium-hub
    environment:
      - HUB_PORT_4444_TCP_ADDR=selenium-hub
      - HUB_PORT_4444_TCP_PORT=4444
  firefox:
    image: selenium/node-firefox
    depends_on:
      - selenium-hub
    environment:
      - HUB_PORT_4444_TCP_ADDR=selenium-hub
      - HUB_PORT_4444_TCP_PORT=4444

We were able to successfully create a Selenium Grid using above docker compose file.  Now we are going to add the image we created to create containers to test specific module.

search-module:
    image: vinsdocker/containertest:demo
    container_name: search-module
    depends_on:
      - chrome
      - firefox
    environment:
      - MODULE=search-module.xml
      - BROWSER=firefox
      - SELENIUM_HUB=selenium-hub
    volumes:
      - /home/user/search-module-result:/output     
order-module:
    image: vinsdocker/containertest:demo
    container_name: order-module
    depends_on:
      - chrome
      - firefox
    environment:
      - MODULE=order-module.xml
      - BROWSER=chrome
      - SELENIUM_HUB=selenium-hub
    volumes:
      - /home/user/order-module-result:/output
  • depends_on – lets the docker know that the service should be created once the all the dependent containers have been created.
  • volumes – TestNG writes the result in the output directory inside the container. We map the directory to some directory on the host machine. Ensure that you provide enough permission to write results.

Screenshot from 2018-04-16 12-19-24

Test Suites Execution:

Once the docker compose file is ready, the rest is very simple!!

  • A single command creates the entire infrastructure and executes the test.
sudo docker-compose up -d
Creating selenium-hub
Creating sel_firefox_1
Creating sel_chrome_1
Creating order-module
Creating search-module
  • Execute the below command to see the status
sudo docker-compose ps
    Name                   Command               State           Ports
-------------------------------------------------------------------------------
order-module    /bin/sh -c /usr/bin/java - ...   Up
search-module   /bin/sh -c /usr/bin/java - ...   Up
sel_chrome_1    /opt/bin/entry_point.sh          Up
sel_firefox_1   /opt/bin/entry_point.sh          Up
selenium-hub    /opt/bin/entry_point.sh          Up      0.0.0.0:4444->4444/tcp
  • Once the test execution is done, you would see Exit 0  (in case of any test failures, you would see Exit 1)
sudo docker-compose ps
    Name                   Command               State           Ports
-------------------------------------------------------------------------------
order-module    /bin/sh -c /usr/bin/java - ...   Exit 0
search-module   /bin/sh -c /usr/bin/java - ...   Exit 0
sel_chrome_1    /opt/bin/entry_point.sh          Up
sel_firefox_1   /opt/bin/entry_point.sh          Up
selenium-hub    /opt/bin/entry_point.sh          Up      0.0.0.0:4444->4444/tcp
  • If you are curious to see the test log of order-module and search-module only, then go for below command.
sudo docker-compose up | grep -e 'order-module' -e 'search-module'

reg-suite-log

  • To bring everything down, of course with a single command!
sudo docker-compose down
Removing search-module ... done
Removing order-module ... done
Removing sel_firefox_1 ... done
Removing sel_chrome_1 ... done
Removing selenium-hub ... done

Now the very complex selenium grid + hosts to run the java tests became very simple which you could define it in a text file. A single command creates the infrastructure in a second on a single host (you can also do that in multiple hosts) and disposes once everything is complete!

container-test-doc-04

 

GitHub:

This sample project is available here.

Summary:

Docker compose made our life very easier! With a single command,  we create Virtual Machines (containers are light weight VMs) with required browsers, tests and executes the test. Again with another command, we bring the entire infrastructure down!!

No more environment specific issues like ‘the test is not working in the machine’   🙂

By implementing docker in your project, you become 100% awesome as Barney!!

barney-awesomeness-thums-up

 

What Next?:

We are able to build docker image for your automated tests with all the dependencies. How to distribute this image with other machines to run your tests? If you would like to know more about this, please check here.

Selenium WebDriver – How To Distribute Docker Images – Part 3

Happy Testing & Subscribe 🙂

 

Share This:

34 thoughts on “Selenium WebDriver – How To Run Multiple Test Suites Using Docker Compose – Part 2

  1. Hi Vinoth,

    First of all thank you very much for the article. It is very helpful.
    I was trying to run your github code with small modifications to it. I was able to successfully run mvn test and also successfully get image, The problem appeared when I tried running the image created.
    I am constantly getting configuration failures.

    If you find sometime, please see my repo at –
    https://rahul-upadhyay@bitbucket.org/rahul-upadhyay/docker-maven-testng.git

    All my changes are placed in the files. This is basically your copy with some modifications.
    Need your help.

    1. TestNG expects all the dependencies to be in a separate folder – instead of one single jar. I modified my pom file in the github project. Please update yours and try.

  2. Hi Vinoth,
    Really useful article… Thanks for writing these…
    May I know where you are passing the chrome driver executable file here …? how the chrome instance configured with the hub will be invoked as it must definitely need to have the executable file ….
    also will you be able to visually see the browser automation when the tests are happening in the container..

    Thanks & Warm Regards
    Musaffir

  3. Now I understand you don’t have to pass the chrome driver executable… just would like to know how we can view the automtaed tests …

  4. Thanks Vinoth…
    One more question here…

    When you do mvn clean package….mvn is executing your tests already and it creates the test jar for you…. and later when mvn runs the docker plugin it utilizes the test jar and making an image… the image can be run on any machine where docker is installed…
    So for the first time , is your tests is not done on docker…?
    or is it also done on docker… in that case the tests will be happening two times as mvn already executed the tests in its test phase… pls clarrify….

  5. I’m not able to get this running, I may be missing a few steps:
    Your Dockerfile has the following:
    # Command line to execute the test
    # Expects below environment variables
    # BROWSER = chrome / firefox
    # MODULE = order-module / search-module
    # GRIDHOST = selenium hub hostname / ipaddress

    ENTRYPOINT /usr/bin/java -cp $BASE_DIR/container-test.jar: \
    -DseleniumHubHost=$SELENIUM_HUB \
    -Dbrowser=$BROWSER org.testng.TestNG $BASE_DIR/$MODULE

    $BASEDIR is defined in the Dockerfile, $SELNIUM_HUB and $MODULE are not, also the Dockerfile now comments on GRIDHOST not SELENIUM_HUB.
    Do I need to manually set these prior to running:
    mvn clean package (?)

  6. That works, but I needed to change the first command to:
    mvn clean package -DskipTests
    otherwise it runs tests prior to package, which fails because
    String host = System.getProperty(“seleniumHubHost”); is null

    Are you able to do this without -DskipTests?

    1. Those are java properties. you could pass them to mvn as well via mvn clean package -DseleniumHubHost=[ip.address]

      1. I agree we could us -DseleniumHubHost=[ip.address], but if we did that then we would be running the tests multiple times. First when we build the package then when we run them thru jenkins.

        BTW thanks for the article, are you using this methodology at work?

  7. Hi,

    First of all Nice article. Thanks.

    I am successful in building the image. When I try to run using the command “sudo docker-compose up -d” test execution started, but all the tests are failing. How can I debug and where can i find the final test reports.

    Thanks,
    AM

  8. Hi Vinoth. I am able to successfully build the test jars using mvn clean package -DskipTests. But then when tried to execute tests using the docker-compose it is throwing a configuration issue error. not sure what it is. Can you please help. The log is as below.

    1. Thrayee, Do you do volume mapping? if yes, can you check the testng result? Looks like something is wrong. Are you able to access the grid?

  9. I have tried importing the project in to eclipse using option existing maven import . I am seeing the following errors
    The declared package “com.testautomationguru.container.test” does not match the expected package “test.java.com.testautomationguru.container.test” .

    Do you want me to change or Fix the project using any of the Eclipse suggestions , ?

    1. The package in the class should start with com.testautomationguru…. Looks like something got messed up! In Intellij it can be changed in File -> project structure -> Modules. source folder should be src/main/java. and test should be src/test/java. I am not sure of the similar setting in Eclipse.

  10. Thanks vlns , I have fixed using the eclipse . Before running complete tests i thought of running the following command just to check how it works . But i am seeing this issue . “/d/MySpace/Learning/Docker And Kubarnates Traning/selenium/docker-selenium-test-master/target
    $ java -cp container-test.jar:lib/* org.test.TestNG -testclass ../order-module.xml
    Error: Could not find or load main class org.test.TestNG

    I have lot of googling and spent lot of time also . I could not fix this issue . Can you please help me here

  11. Just add on to that i have also $ java -cp container-test.jar:lib/* org.test.TestNG ../order-module.xml
    Error: Could not find or load main class org.test.TestNG

    Please let me know if i am missing anything here

  12. I am buid the image but seeing same issue while running the command locally .

    /selenium/docker-selenium-test-master/target
    $ java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* ../order-module.xml
    Error: Could not find or load main class …order-module.xml

    /selenium/docker-selenium-test-master/target
    $ java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* org.testng.TestNG -testclass com.testautomationguru.container.test.SearchTest
    Error: Could not find or load main class org.testng.TestNG

    /selenium/docker-selenium-test-master/target
    $ java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* org.testng.TestNG -testclass com.testautomationguru.container.test.SearchTest
    Error: Could not find or load main class org.testng.TestNG

    Below is the output where i have ran mvn clean package -DskipTests

    [INFO] — maven-jar-plugin:2.6:jar (default-jar) @ container-test —
    [INFO] Building jar: d:\MySpace\Learning\Docker And Kubarnates Traning\selenium\docker-selenium-test-master\target\selenium-docker.jar
    [INFO]
    [INFO] — maven-jar-plugin:2.6:test-jar (default) @ container-test —
    [INFO] Building jar: d:\MySpace\Learning\Docker And Kubarnates Traning\selenium\docker-selenium-test-master\target\selenium-docker-tests.jar
    [INFO]
    [INFO] — dockerfile-maven-plugin:1.3.5:build (default) @ container-test —
    [INFO] Building Docker context d:\MySpace\Learning\Docker And Kubarnates Traning\selenium\docker-selenium-test-master
    [INFO]
    [INFO] Image will be built as vinsdocker/containertest:demo
    [INFO]
    [INFO] Step 1/8 : FROM openjdk:8-jre-slim
    [INFO]
    [INFO] Pulling from library/openjdk
    [INFO] Digest: sha256:9598d00d111594d372836d276367ab59c75d2c56e17f8cf70ca4a1917a981c76
    [INFO] Status: Image is up to date for openjdk:8-jre-slim
    [INFO] —> 54567f06e0e8
    [INFO] Step 2/8 : WORKDIR /usr/share/tag
    [INFO]
    [INFO] —> Running in cd546a3b921e
    [INFO] Removing intermediate container cd546a3b921e
    [INFO] —> 40b2124da839
    [INFO] Step 3/8 : ADD target/selenium-docker.jar selenium-docker.jar
    [INFO]
    [INFO] —> 97883a6d0e7a
    [INFO] Step 4/8 : ADD target/selenium-docker-tests.jar selenium-docker-tests.jar
    [INFO]
    [INFO] —> 3a38471a9935
    [INFO] Step 5/8 : ADD target/libs libs
    [INFO]
    [INFO] —> 17fe817b0ab0
    [INFO] Step 6/8 : ADD order-module.xml order-module.xml
    [INFO]
    [INFO] —> 6a07216bdf76
    [INFO] Step 7/8 : ADD search-module.xml search-module.xml
    [INFO]
    [INFO] —> cc8214fa2b2f
    [INFO] Step 8/8 : ENTRYPOINT java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* -DseleniumHubHost=$SELENIUM_HUB -Dbrowser=$BROWSER org.test
    ng.TestNG $MODULE
    [INFO]
    [INFO] —> Running in 089226bef4dd
    [INFO] Removing intermediate container 089226bef4dd
    [INFO] —> 5c6640a070a8
    [INFO] Successfully built 5c6640a070a8
    [INFO] Successfully tagged vinsdocker/containertest:demo
    [INFO]
    [INFO] Detected build of image with id 5c6640a070a8
    [INFO] Building jar: d:\MySpace\Learning\Docker And Kubarnates Traning\selenium\docker-selenium-test-master\target\selenium-docker-docker-info.jar
    [INFO] Successfully built vinsdocker/containertest:demo
    [INFO] ————————————————————————
    [INFO] BUILD SUCCESS
    [INFO] ————————————————————————
    [INFO] Total time: 37.608 s
    [INFO] Finished at: 2019-01-21T15:08:24+05:30
    [INFO] Final Memory: 53M/496M
    [INFO] ————————————————————————

  13. Hi vIns , Can you please help me with my query . I am running on windows . Before creating the image i am trying locally with java -cp command it always failing with Error: Could not find or load main class org.test.TestNG

    I have tried :
    1. java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* org.testng.TestNG search-module.xml
    2. java -cp selenium-docker.jar:selenium-docker-tests.jar:selenium-docker-dockerinfo.jar:target/libs/testng-6.11.jar:target/libs/* org.testng.TestNG search-moule.xml

    Root Directory Contents :

    /d/MySpace/Learning/Docker And Kubarnates Traning/
    selenium/docker-selenium-test-master/target
    $ ls
    classes/ libs/ selenium-docker-docker-info.jar
    docker/ maven-archiver/ selenium-docker-tests.jar
    generated-sources/ maven-status/ test-classes/
    generated-test-sources/ selenium-docker.jar

    target dir contents :

    /d/MySpace/Learning/Docker And Kubarnates Traning/
    selenium/docker-selenium-test-master/target
    $ ls
    classes/ libs/ selenium-docker-docker-info.jar
    docker/ maven-archiver/ selenium-docker-tests.jar
    generated-sources/ maven-status/ test-classes/
    generated-test-sources/ selenium-docker.jar

    lib directory contents :

    /d/MySpace/Learning/Docker And Kubarnates Traning/
    selenium/docker-selenium-test-master/target/lib
    $ ls
    animal-sniffer-annotations-1.14.jar jna-4.1.0.jar
    bsh-2.0b6.jar jna-platform-4.1.0.jar
    cglib-nodep-3.2.4.jar jsr305-1.3.9.jar
    commons-codec-1.10.jar junit-4.12.jar
    commons-exec-1.3.jar neko-htmlunit-2.27.jar
    commons-io-2.5.jar phantomjsdriver-1.4.0.jar
    commons-lang3-3.5.jar sac-1.3.jar
    commons-logging-1.2.jar selenium-api-3.5.2.jar
    cssparser-0.9.23.jar selenium-chrome-driver-3.5.2.jar
    error_prone_annotations-2.0.18.jar selenium-edge-driver-3.5.2.jar
    gson-2.8.0.jar selenium-firefox-driver-3.5.2.jar
    guava-23.0.jar selenium-ie-driver-3.5.2.jar
    hamcrest-core-1.3.jar selenium-java-3.5.2.jar
    htmlunit-2.27.jar selenium-opera-driver-3.5.2.jar
    htmlunit-core-js-2.27.jar selenium-remote-driver-3.5.2.jar
    htmlunit-driver-2.27.jar selenium-safari-driver-3.5.2.jar
    httpclient-4.5.3.jar selenium-support-3.5.2.jar
    httpcore-4.4.6.jar serializer-2.7.2.jar
    httpmime-4.5.3.jar testng-6.14.3.jar
    j2objc-annotations-1.1.jar websocket-api-9.4.5.v20170502.jar
    javax.servlet-api-3.1.0.jar websocket-client-9.4.5.v20170502.jar
    jcommander-1.72.jar websocket-common-9.4.5.v20170502.jar
    jetty-client-9.4.5.v20170502.jar xalan-2.7.2.jar
    jetty-http-9.4.5.v20170502.jar xercesImpl-2.11.0.jar
    jetty-io-9.4.5.v20170502.jar xml-apis-1.4.01.jar
    jetty-util-9.4.5.v20170502.jar

    My POM.xml file

    4.0.0
    com.testautomationguru.container
    container-test
    0.0.1-SNAPSHOT

    <dependencies>
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.5.2</version>
    </dependency>
    <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
    </dependency>
    </dependencies>
    <build>
    <finalName>selenium-docker</finalName>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
    <compilerVersion>1.8</compilerVersion>
    <source>1.8</source>
    <target>1.8</target>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
    <execution>
    <id>copy-dependencies</id>
    <phase>prepare-package</phase>
    <goals>
    <goal>copy-dependencies</goal>
    </goals>
    <configuration>
    <outputDirectory>
    ${project.build.directory}/libs
    </outputDirectory>
    </configuration>
    </execution>
    </executions>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <executions>
    <execution>
    <goals>
    <goal>test-jar</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.17</version>
    <configuration>
    <suiteXmlFiles>
    <suiteXmlFile>search-module.xml</suiteXmlFile>
    </suiteXmlFiles>
    </configuration>
    </plugin>
    <plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.3.5</version>
    <executions>
    <execution>
    <id>default</id>
    <goals>
    <goal>build</goal>
    <goal>push</goal>
    </goals>
    </execution>
    </executions>
    <configuration>
    <repository>vinsdocker/containertest</repository>
    <tag>demo</tag>
    </configuration>
    </plugin>
    </plugins>
    </build>

    My Docker File :

    FROM openjdk:8-jre-slim

    WORKDIR /usr/share/tag

    Add the project jar & copy dependencies

    ADD target/selenium-docker.jar selenium-docker.jar
    ADD target/selenium-docker-tests.jar selenium-docker-tests.jar
    ADD target/libs libs

    Add the suite xmls

    #ADD order-module.xml order-module.xml
    ADD search-module.xml search-module.xml

    Command line to execute the test

    Expects below ennvironment variables

    BROWSER = chrome / firefox

    MODULE = order-module / search-module

    GRIDHOST = selenium hub hostname / ipaddress

    ENTRYPOINT java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* org.testng.TestNG search-module.xml

    1. if you are trying to do in windows, we need to replace : with ; also where you are trying to run this command?

      java -cp selenium-docker.jar;selenium-docker-tests.jar;libs/* org.testng.TestNG search-module.xml

  14. Thanks Vlns this helped me . I was able to run the windows . I am now seeing the following issue .. I have got this log by logging to the docker-machine and accessed the container .

    Please suggest

    {“log”:”[TestNG] [ERROR] \n”,”stream”:”stderr”,”time”:”2019-01-22T13:50:22.297810158Z”}
    {“log”:”Cannot find class in classpath: com.testautomationguru.container.test.GoogleTest\n”,”stream”:”stderr”,”time”:”2019-01-22T13:50:22.298325764Z”}
    {“log”:”Exception in thread \”main\” java.lang.NullPointerException\n”,”stream”:”stderr”,”time”:”2019-01-22T13:50:22.331367454Z”}
    {“log”:”\u0009at org.testng.TestNG.getStatus(TestNG.java:211)\n”,”stream”:”stderr”,”time”:”2019-01-22T13:50:22.332325626Z”}
    {“log”:”\u0009at org.testng.TestNG.main(TestNG.java:1324)\n”,”stream”:”stderr”,”time”:”2019-01-22T13:50:22.333093638Z”}
    ~
    ~
    ~

    I see CTRM Chars in search-module.xml file , before buiding the image i have ran dos2unix commmand on this file and then created the image , is it root cause of the issue ?

    Docker File is :

    FROM openjdk:8-jre-slim

    WORKDIR /usr/share/tag

    Add the project jar & copy dependencies

    ADD target/selenium-docker.jar selenium-docker.jar
    ADD target/selenium-docker-tests.jar selenium-docker-tests.jar
    ADD target/libs libs

    Add the suite xmls

    #ADD order-module.xml order-module.xml
    ADD search-module.xml search-module.xml

    Command line to execute the test

    Expects below ennvironment variables

    BROWSER = chrome / firefox

    MODULE = order-module / search-module

    GRIDHOST = selenium hub hostname / ipaddress

    ENTRYPOINT java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* -DseleniumHubHost=$SELENIUM_HUB -Dbrowser=$BROWSER org.testng.TestNG $MODULE

  15. Just note that this I am running in my windows laptop … Since docker machine will be Linux vm I have just used same docker file with same entry point. Please let me know in case of any changes … Appreciate your help and for this great article which will for getting to e2e docker selenium

  16. Hello vIns, I am new to docker selenium. I have downloaded the source code and opened the project in my IntelliJ on my windows machine. No errors. I tried below command from the project root path on cmd window ‘mvn clean package’ and i get the error as below

    [INFO] Running TestSuite
    [ERROR] Tests run: 24, Failures: 1, Errors: 0, Skipped: 23, Time elapsed: 2.775 s <<< FAILURE! – in TestSuite
    [ERROR] setUp(com.testautomationguru.container.test.BaseTest) Time elapsed: 2.536 s <<< FAILURE!
    java.lang.NullPointerException
    at com.testautomationguru.container.test.BaseTest.setUp(BaseTest.java:33)
    I have the following questions
    1. How do i package this?
    2. After packaging it and available as the image on my Docker, what is the next step to execute the test on docker
    3. If i want to execute on the docker installed on Windows machine, any additional changes I do I need to make in any file?
    4. How can we get the report (allure report) out this execution

    1. Regarding the error, we need to pass a system property called ‘browser’ – either chrome or firefox.
      For toher questions, I have other posts in this site. you have to refer!

  17. vIns,

    I have executed below command

    mvn clean -Dmaven.test.skip=true package and I get below error while packaging

    [INFO] Step 4/8 : ADD target/selenium-docker-tests.jar selenium-docker-tests.jar
    [INFO]
    [ERROR] ADD failed: stat /var/lib/docker/tmp/docker-builder604232321/target/selenium-docker-tests.jar: no such file or directory
    [WARNING] An attempt failed, will retry 1 more times
    org.apache.maven.plugin.MojoExecutionException: Could not build image
    at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:185)

    When i checked the Docker file i can see below step
    ADD target/selenium-docker-tests.jar selenium-docker-tests.jar
    So i checked the Target folder, there only one jar was generated which is selenium-docker.jar.
    So do we need to remove the step ADD target/selenium-docker-tests.jar selenium-docker-tests.jar from Docker file?
    Please suggest

  18. vIns,
    Please ignore my previous comment. I am able to package after removing the step “ADD target/selenium-docker-tests.jar selenium-docker-tests.jar” from Docker file

    Now my packaging is successful and also i can see the image in the docker

    docker images -a
    REPOSITORY TAG IMAGE ID CREATED SIZE
    vinsdocker/containertest demo 66751a3becbc 11 minutes ago 205MB

    Now just a doubt how do I run this image. Is this the command I should supply in the power shell?

    docker run vinsdocker/containertest:demo -Dbrowser=chrome -DseleniumHubHost=localhost org.testng.TestNG /usr/share/tag/order-module

    Please suggest

  19. Hi VIns
    Please help here. I am trying to implement the same solution in my project and I am stuck here.
    I have followed exactly the same as you mentioned in this post. I ave the hub and browsers up and running. I am trying to push an image to my docker hub. I am trying to package it
    I have given below commands
    ‘mvn clean package -Dbrowser=chrome -DseleniumHubHost=10.10.245.172 org.testng.TestNG order-module’
    but resulted in an error as below

    [INFO] Scanning for projects…
    [INFO]
    [INFO] ———-< com.testautomationguru.container:container-test >———–
    [INFO] Building container-test 0.0.1-SNAPSHOT
    [INFO] ——————————–[ jar ]———————————
    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 0.213 s
    [INFO] Finished at: 2019-07-31T10:09:01+05:30
    [INFO] ————————————————————————
    [ERROR] Unknown lifecycle phase “org.testng.TestNG”. You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

    could you extend your help to package this? Or anyone in this group who successfully done this

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.