Looking for some guidlines to run my selenium tests on Docker

899 views
Skip to first unread message

Musaffir lp

unread,
Dec 19, 2017, 2:14:03 AM12/19/17
to Selenium Users
Hello,

My selenium tests are not runnning with Selenium Grid platform.
The project is a Maven Project, and I use TestNg as the testing framework
I use mavens sure-fire plugin to trigger testNg test suite xml files for the execution. while maven build the project , i pass the testng suite file name as a run time paramter and triggers it ...

I have no plan to start using selenium grid at the moment , but would like to run tests in Docker container .

I understand very basic concepts of Docker.
I know there is a maven plugin for docker which helps to make a docker image
The docker image can then be run as container.
I couldn't make this work but .
Would like to get some guidlines on how we can run non grid selenium tests in Docker ?
and if I make an image of such suite with browser type etc , can it run on any machine where docker is installed with out any other dependencies...?

Looking for some info on this area

Thanks & Warm Regards
Musaffir

Vinoth Selvaraj

unread,
Dec 20, 2017, 12:44:48 AM12/20/17
to Selenium Users
Message has been deleted

Musaffir lp

unread,
Dec 20, 2017, 4:54:03 AM12/20/17
to Selenium Users
Thanks Vinoth, I have gone through all your blog posts.

Actually I dont want the docker file to have the ENTRYPOINT as below
ENTRYPOINT ["/usr/bin/java", "-cp", "/usr/share/tag/container-test.jar","org.testng.TestNG", "-testclass", "com.testautomationguru.container.test.GoogleTest"]


as my project and framework is already designed to run with maven sure-fire plugin ,and I have some listeners too there too to help in reporting later...ex of sure-fire config in pom xml
<plugin>
               
<groupId>org.apache.maven.plugins</groupId>
               
<artifactId>maven-surefire-plugin</artifactId>
               
<version>2.17</version>
               
<configuration>
                   
<suiteXmlFiles>
                       
 
<suiteXmlFile>${project.basedir}\src\test\java\net\cal\mycompany\TestNgSuites\${suite.name}.xml</suiteXmlFile>
                   
</suiteXmlFiles>
                   
<properties>
                       
<property>
                           
<name>listener</name>
                           
<value>net.mycompany.test.reporting.AutomationReporting</value>
                       
</property>
                   
</properties>
               
</configuration>
           
</plugin>



I want to pass -Dsuite.name during run time....so if this can be passed in docker file its fine...but not sure how to do it...
tried maven docker image thinking I can pass
CMD [maven commands here..] like CMD [mvn clean install -Dsuite.name="mytestNgsuite.xml"]
but that seems not a vaid syntax...


(or)
If we use the already built jar file in docker file ,then can we pass the testNg suite xml there and trigger the suite execution when we do docker run command ?


Thanks & Warm Regards
Musaffir

⇜Krishnan Mahadevan⇝

unread,
Dec 20, 2017, 5:07:11 AM12/20/17
to Selenium Users
Why do you want your tests to be part of the docker container in which the tests are to be executed ?

The docker container, ideally speaking should represent just the execution environment.

And the tests should run against the docker container.

You can basically have @BeforeSuite/@BeforeTest/@BeforeClass/@BeforeMethod configuration methods which can spin off a docker container which runs a selenium standalone instance, to which you have your tests point to and run against (You will need your tests to be modified to use RemoteWebDriver instead of the other flavors of webdriver implementations), and in your @AfterMethod/@AfterClass/@AfterTest/@AfterSuite, you clean up the docker containers.

Docker installation when configured, can expose http end points using which you can spin off containers on-demand. So if you couple both these, you should be able to achieve what you are after.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ff2bf62e-3fbb-4c69-9196-85a26c6d1b8a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Musaffir lp

unread,
Dec 20, 2017, 5:44:57 AM12/20/17
to Selenium Users
Hi Krishnan,

    1. Why do you want your tests to be part of the docker container in which the tests are to be executed ?
      1. We have some web applications that are being deployed using Docker containers, and I would like to run my selenium sanity suites after the deployment is done to check app stability etc.and I want to check if this can also be part of docker container and as part of continous delivery cycle of the app.....( right now am managing this seperately using jenkins job which runs on a seperate VM, the job pulls the automation code on manual/schedule trigger of the job and it gets build/tests with maven..)
      2. I was under the mindset that once you create a docker image , you can pull this image (make it available) in any machine where docker is running...and we should be able to run that image in that machine when ever we want...and while docker runs the image , it should open the browser,load url and executes our scripts etc to test the app... so I was thinking making image is kind of a one time activity and run it always in the docker container....
    1. You can basically have @BeforeSuite/@BeforeTest/@
    1. BeforeClass/@BeforeMethod configuration methods which can spin off a docker container which runs a selenium standalone instance, to which you have your tests point to and run against (You will need your tests to be modified to use RemoteWebDriver instead of the other flavors of webdriver implementations), and in your @AfterMethod/@AfterClass/@AfterTest/@AfterSuite, you clean up the docker containers.
      1. You meant to say we can spin of containers programatically inside the @Before methods of our java class ?
    To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
    To post to this group, send email to seleniu...@googlegroups.com.

    ⇜Krishnan Mahadevan⇝

    unread,
    Dec 20, 2017, 5:52:29 AM12/20/17
    to Selenium Users
    Comments inline

    Thanks & Regards
    Krishnan Mahadevan

    "All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
    My Scribblings @ http://wakened-cognition.blogspot.com/
    My Technical Scribbings @ http://rationaleemotions.wordpress.com/

    On Wed, Dec 20, 2017 at 4:14 PM, Musaffir lp <musaf...@gmail.com> wrote:
    Hi Krishnan,

    1. Why do you want your tests to be part of the docker container in which the tests are to be executed ?
      1. We have some web applications that are being deployed using Docker containers, and I would like to run my selenium sanity suites after the deployment is done to check app stability etc.and I want to check if this can also be part of docker container and as part of continous delivery cycle of the app.....( right now am managing this seperately using jenkins job which runs on a seperate VM, the job pulls the automation code on manual/schedule trigger of the job and it gets build/tests with maven..)
    ​[Krishnan] I think you should still be able to get this done. Basically you would have the following setup. Your jenkins job would clone your tests from a test case repository and before running the tests, it would spin off a container which hosts your web application. Your tests now would spin off a second docker container which would host the selenium standalone. So your browsers would open up in the docker container spun off by your tests via a configuration method, but they would basically open up the web application that is being hosted in the first docker container. Of-course you may have to fiddle around/tweak some of the network nuances so that the web application hosted in container1 is exposed and available for use via the web browsers from docker container 2 to "n" [ here the idea is to spin off a selenium standalone docker container for every test, so that it can be easily cleaned up after the test runs to completion ]​

      1. I was under the mindset that once you create a docker image , you can pull this image (make it available) in any machine where docker is running...and we should be able to run that image in that machine when ever we want...and while docker runs the image , it should open the browser,load url and executes our scripts etc to test the app... so I was thinking making image is kind of a one time activity and run it always in the docker container....
    1. You can basically have @BeforeSuite/@BeforeTest/@
      BeforeClass/@BeforeMethod configuration methods which can spin off a docker container which runs a selenium standalone instance, to which you have your tests point to and run against (You will need your tests to be modified to use RemoteWebDriver instead of the other flavors of webdriver implementations), and in your @AfterMethod/@AfterClass/@AfterTest/@AfterSuite, you clean up the docker containers.
      1. You meant to say we can spin of containers programatically inside the @Before methods of our java class ?
    ​[Krishnan] Of-course you can. For some code samples, take a look at the On-Demand Docker Grid that I built which essentially leverages this concept. But it works on the grid environment, wherein there's only the hub that you spin off. After that for every test, a new docker container is spun off and the test gets routed to it. 

     
     
    To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
    To post to this group, send email to selenium-users@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/970736f1-269d-4999-9454-c30609074c4f%40googlegroups.com.

    Musaffir lp

    unread,
    Jan 3, 2018, 3:29:48 AM1/3/18
    to Selenium Users
    Thanks Krishnan, I will explore above option.
    I was trying the below approach, just would like to know what you think about it ..

    1. I made a test jar which contains the test classes and the testNG xml file
    2. I also have a jar with all the dependencies of my automation project
    3. I could invoke the browser and the test from command prompt successfully using normal java command and passing the jars in classpath. and using testNG cmd line parameters....  -testjar , -xmlpathinjar
    4. Example :
    5. java -DchromeDriverPath=chromedriver.exe -cp myproject-jar-with-dependencies.jar;myproject-tests.jar org.testng.TestNG -testjar myproject-tests.jar -xmlpathinjar MytestSuite.xml
    6. I was thinking I will make a simple docker image utilizing the above method, as I understand we should be able to run normal java programs etc from docker container too
    7. So made a simple docker file and made the image successully
    8. Example:Dockerfile
    9. # Sample Dockerfile
      # Indicates that the java:8 image will be used as the base image.
      FROM java:8

      # Add the jar with all the dependencies
      ADD  target/
      myproject-tests.jar myproject-tests.jar
      ADD  target/
      myproject-jar-with-dependencies.jar myproject-jar-with-dependencies.jar
      ADD  target/chromedriver.exe chromedriver.exe

      CMD java -DchromeDriverPath=chromedriver.exe -cp
      myproject-jar-with-dependencies.jar;myproject-tests.jar org.testng.TestNG -testjar myproject-tests.jar -xmlpathinjar MytestSuite.xml


    10. The docker image gets created , (am yet to successfuly run it though)  ( even if this works, I understand the browser has to be in the machine when we running the docker image )
    11. but do you think this is an ok approach ?


    Thanks,
    Musaffir
    Comments inline

    Musaffir lp

    unread,
    Jan 8, 2018, 3:46:14 AM1/8/18
    to Selenium Users
    I could find some lights at the end of the tunnel....
    Thanks to Vinoth and Krishnan for constantly sharing the knowledge...


    I understood we have selenium grid image and chrome image set up available from the docker hub...
    Made the docker-compose file to pull them ...so that it will get you a selenium grid set up ready...
    Just modifed my framework to work with the Remote web driver flavour..and driver instance is created with it...

    the docker image is crated with a docker file having simple java commands to execute the testNg test jar files with passed arguments...
    This docker image too configured in the docker-compose file which is depended on the chrome > grid set up... ( chromdriver executable path need not be passed as it is already configured in the chrome -node )

    issue docker-compose run command does alll the set up and run the tests inside the container successfullly....

    Musaffir lp

    unread,
    Jan 10, 2018, 11:05:52 PM1/10/18
    to Selenium Users
    I would like to ask a question here .

    Making a test jar and a dependency jar... then utilizing them to make the docker image....then running it in the docker container with selenium-grid set up ----> is it only the way by which we can dockerize selenium ui tests ?

    To dockerize, definitely you need to have a docker image....i guess docker image is something like an artifact / or say kind of a bundled thing which has all the components etc to make things work...
    So with out utilizing the test jar files, is it ever possible to make an image and run selenium tests on the fly inside the docker container....?

    By on the fly I meant to say....
    when I use maven sure-fire plugin to run the tests ....what happens is it gets picked up at the test phase of maven build cycle... it picks up the testNg xml file or anything or the test class to trigger tests etc ... so this is part of maven build cycle....( you may be even packing the tests in to a jar file at the end of maven cycle... )..

    the similar way...can we dockerize tests....? i.e fom all the source files etc.. it makes an image straight a way and run it in container....
    (I know kind of stupid question....but trying to understand the concept and how things can work )

    appreciate any response...

    Many Thanks
    Musaffir

    Musaffir lp

    unread,
    Jan 14, 2018, 10:08:16 PM1/14/18
    to Selenium Users
    Thought about some thing simple and straight forward too...

    Not making any test jar.... all the automation project and src files are as it is .... which is a maven project which uses sure-fire plugin to trigger testNG suite xml file....

    prior to running mvn command.... the docker-compose file will be run to make the selenium grid set up ready.....( for ex: hub and a chrome node ready )

    when the mvn command is executed , the driver instance is created for the remote webdriver flavour and it is being routed to the grid-hub which is a docker container....  so tests are running in the docker container....

    thought mvn artificat etc everything will be on the machine where mvn was invoked....

    once tests done... the grid docker container can be brought down....

    Musaffir lp

    unread,
    Jan 18, 2018, 12:23:46 AM1/18/18
    to Selenium Users
    From my research I feel the below approach is the simplest one .. mentioning here as probably it can help any future reader....

      
          Docker has inbuilt image for maven.. i.e maven officials have already built docker image ... please see here - https://hub.docker.com/_/maven/
          If your project is a maven one... we can simply build it using above image....
          The docker file need to be written accordinly... and run docker build command to make an image...
          This image can be run in docker container..... the container can be set up using docker-compose file....
          so the mvn build happens in docker container....
          the selenium grid set up should be done inorder to receive the selenium tests.... so driver instance is a remotewebdriver flavour....
          maven runs the tests in docker based on the suite-file you pass... maven uses sure-fireplugin for it.... all becomes simple then to docerize the selenium tests....
          In order for maven not to download the entire dependecy repo everytime it is run inside the docker containner... just use docker volume concept to mount the .m2 folder as a docker volume.... this can also be made part of the docker-compose file...


    Thanks to Vinoth and Krishnan for given the initial ideas....


    Warm Regards
    Musaffir

    On Tuesday, December 19, 2017 at 3:14:03 PM UTC+8, Musaffir lp wrote:
    Reply all
    Reply to author
    Forward
    0 new messages