Overview:
We already have seen the challenges related to setting up the Selenium Grid infrastructure and how docker helps us in setting up a flexible/disposable/highly scalable selenium grid within few seconds in these articles below.
In this article, We will see how Zalenium (a similar dockerized selenium grid infrastructure with few other features) helps.
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.
Zalenium Setup:
- Ensure that you have latest docker engine is running. You can get the instructions here on installing docker.
- Pull below docker images.
- docker pull elgalu/selenium
- docker pull dosel/zalenium
- Run the below command to start the zaleniukm-selenium-grid
docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/videos:/home/seluser/videos \
dosel/zalenium start
- Zalenium is ready to use now in our tests.
DesiredCapabilities dc = DesiredCapabilities.firefox();
RemoteWebDriver driver=new RemoteWebDriver(new URL("http://10.11.12.13:4444/wd/hub"), dc);
driver.get("https://www.google.com");
Zalenium – Live Preview:
- One of the cool features of zalenium is the live preview of the dockerized containers. We can access this using below URL.
- http://localhost:4444/grid/admin/live#
- By default, our Selenium grid will have 1 Chrome and 1 Firefox container. If you need more, say 3 chrome containers, 2 firefox then use below arguments
- –chromeContainers 3
- –firefoxContainers 2
docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/videos:/home/seluser/videos \
dosel/zalenium start --chromeContainers 3 --firefoxContainers 2
Demo:
I am running the test I had created as part of DatePicker Automation in this demo.
I have embedded this live preview in Jenkins itself. You would like to know how? Check here.
Dashboard:
- Zalenium also has a nice dashboard to show the list of recorded tests it has captured.
- Can be accessed at this URL: http://localhost:4444/dashboard
- By default, name of the test has some random string which can be replaced by passing the name of test in the Desired Capabilities.
desiredCapabilities.setCapability("name", "myTestName");
- Disable the video recording feature using below capability.
desiredCapabilities.setCapability("recordVideo", false);
Integrating with Cloud Testing Platforms:
- Yet another cool feature of zalenium is – It can be integrated with cloud based testing solutions like BrowserStack/SuaceLabs.
- Any incoming request to the hub is verified by zalenium – If it can create a container for the request, It starts a container and runs the test.
- Otherwise, the test gets executed at the cloud testing platforms.
Sauce Labs:
export SAUCE_USERNAME=[your Sauce Labs username]
export SAUCE_ACCESS_KEY=[your Sauce Labs access key]
docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \
-e SAUCE_USERNAME -e SAUCE_ACCESS_KEY \
-v /tmp/videos:/home/seluser/videos \
-v /var/run/docker.sock:/var/run/docker.sock \
dosel/zalenium start --sauceLabsEnabled true
BrowserStack:
export BROWSER_STACK_USER=[your BrowserStack username]
export BROWSER_STACK_KEY=[your BrowserStack access key]
docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \
-e BROWSER_STACK_USER -e BROWSER_STACK_KEY \
-v /tmp/videos:/home/seluser/videos \
-v /var/run/docker.sock:/var/run/docker.sock \
dosel/zalenium start --browserStackEnabled true
For more information on Zalenium, please check here.
Happy Testing & Subscribe 🙂