Skip to main content

Selenium Grid with Docker: custom nodes

In my last post I wrote about creating Selenium Grid with use of Docker. I’ve received some questions about customising node’s containers – by default, Docker containers for Selenium Grid nodes run only one instance of browser per node. It’s important to understand that running Grid on Docker is slightly different approach than running it alone – instead of building huge Grid with multiple nodes and dozens of browsers, you run few smaller, independent machines. If one machine is down – you throw it away and build another one. Great use case of Selenium Grid with Docker is to build Grid’s machines as a self service for teams in your company, or to build it automatically before automated tests trigger, and destroy it after. 

Nevertheless, it is possible to tweak default node’s conteiners, so they would contain more browser instances. In this post we’ll create container with custom Selenium Grid’s node configuration – our container would provide more than one instance of browser. Remember, that if you have an account on Docker Hub, you can host one container for free, so after going through this tutorial you can commit your own container and host it, or just create your own, custom Grid on Docker, tailored to your needs.




Prerequisites 

For purpose of this tutorial, we’ll assume that you’ve already set your Selenium Grid with Docker. If not, see the full step-by-step tutorial in my previous post. Starting point for this post is having hub and at least one node linked and running…


… so right now we’re having Selenium Grid with one node, running one instance of Firefox:


Our goal is to increase number of instances to – let’s say – three Firefox’es. How to do that, since Docker containers are isolated units by default? First thing we have to do is ssh to container. It’s not a simple ssh though, it’s rather connecting to node’s tty:

$ docker exec -it firefox bash

… and we’re in! Now you can execute command on container process:


Changing configuration 

Our node is configured by config.json file. How can we locate it? First, let’s go sudo…

$ sudo su

… and find it!

$ find . -name "config.json"


Our config is in ./opt/selenium/ directory. We can’t open config.json in vi, vim, or any other, because Docker containers are running on minimalistic linux vm’s, without any additional tools. We have apt-get though, so we can add some!

$ apt-get update && apt-get install vim

After downloading vim, let’s edit our config.json. File looks as follows:


We have two maxInstances keys. First one is Selenium RC, which is deprecated, and the second one is WebDriver. Our goal is to change the number of Firefox instances to 3, so let’s change the value of the second maxInstances key from 1 to 3 (“maxInstances”: 3). If you’re having problems navigating through the file by arrows, try to use h,j,k,l keys. When value is changed, save and exit from the file, and then type exit to change user and one more exit to go abandon container’s terminal.

Our new container’s configuration is ready to go. Last thing we have to do is to restart out container:

$ docker restart firefox

If you open your Grid in browser now, you’ll see 3 Firefox instances in Webdriver protocol:


Continue reading 

If you want to continue reading and expand your knowledge in area of Docker and Selenium Grid, I recommend you these books:

Summary 

Although recommended approach to work with Selenium Grid with containers is slightly different, Docker gives you many possibilities. It’s always good to search your own, best solution. If you have any thoughts or questions – leave a comment!




Popular posts from this blog

Notes after TestingCup 2018

On May 28-29th I attended TestingCup conference in Łódź. Having quite unique perspective: this was my second year in row as a Speaker at this conference I want to share some thoughts on the event. Dust has settled, lets go! 



Championship Originally TestingCup is a software testing championship. Wait, what? Yes, the formula is unique: teams and individuals from all around Poland are competing in finding the most bugs and defects in specially prepared application - Mr. Buggy. I don’t have specific data, but since this year’s conference was all english I guess competitors were not only from Poland. As a spectator, I must say that the whole competition looked very professional. There were team shirts and names, podium and trophies (gold cup and cash). 
Some cons? Testing championship is held at the first day of the conference. So this is already a conference, but if you’re not taking part in the championship… there’s not much to do, since all the talks are in the next day. Organizers are aw…

REST-Assured framework overview

In modern software development, REST services becomes most popular choice for implementing distributed and scalable web application. They are light and easy to maintain, which results in faster and more effective implementation and system integration.
I recommend you also my other posts about REST-Assured and building microservice’s test automation frameworks: REST-Assured: going deeperBuilding microservices testing framework
With the increase popularity of RESTful services, there is a need for fast and lightweight tool for REST webservices testing automation. One of the most popular choice is Rest-Assured framework from Jayway. It introduces simplicity of testing web services from dynamic languages like groovy or ruby to java. In this post we will get our hands dirty and write automatic test in Rest-Assured framework.
In order to create complete implementation of automated tests in Rest-Assured framework, we need to write our code against some example API. We’ll use standalone Wiremock m…

Building microservices testing framework

RESTful services and microservice architecture in general are big trends in the industry right now. I’ve noticed it also from this blog’s traffic analytics, where topics related with REST testing get the highest interest. Therefore I’ve decided to create some kind of example framework for RESTful APIs functional testing. Project is based on REST-Assured as a services client, Spock as a testing framework, Groovy and Gradle. You can clone full repository from my github. Tests are run against Wiremock API described in this post. Please consider this project as a kind of bootstrap, since it’s an example, not full-blown test framework. Ok, so as Linus said – talk is cheap, show me the code!
Dependencies Usually, first thing for me after importing new project is opening build.gradle (or pom.xml, in case of maven). In our example, the most important dependencies are REST-Assured and Spock. We’ve also Jackson, for serializing objects, Logback for our logs and snakeyaml for reading .yaml files,…