Category Archives: webdriver

Headless browser testing in docker container

Reading Time: 2 minutes

TL;DR

In this post you will find out how to run headless chrome browser tests on your development machine using prepared and configured docker machine.

Docker enables you to run on your development machine minimal linux machine. You are in control which software will be installed in that linux machine. All linux machine configuration is stored in two files. Docker uses cache, so only changes in machine configuration are rerun.

Install Docker

First, you need to install Docker for your operating system. Fire up docker terminal after you installed it.

Type: docker-machine ls

Output:

Screen Shot 2016-02-14 at 11.11.42 AM

 

docker machine is linux (special docker flavour), that has docker software that will run your docker containers. It runs in virtualbox that is automatically installed with docker.

You can ssh to it:

 

Screen Shot 2016-02-14 at 11.19.15 AM

 

Clone this github repository that contains docker files needed for creating and running docker image. Follow the README instructions. And that it is, you can run headless chrome tests on your development machine. While those tests are running, you can use your development machine for other tasks.

Dockerfile

Here is official Dockerfile reference documentation. Dockerfile is source code for creating docker images. But I would like to save you time that I spent investigating the official documentation, so you will be ready to create your own docker images very quickly.

Important note: in order to be able to create your own docker images, previously you have successfully configured and installed linux, connected to linux machine, and you know your way around in linux shell.

You do not have to create Dockerfile from scratch. There is great Dockerfile repository, called Docker hub. In search box input what you need, e.g headless chrome, and there is high probability that somebody already have prepared what you are looking for.

If this is not the case, you can download Dockerfile and change it according to your needs. Check in Dockerfile reference what every docker command actually do.

docker-compose.yml

This is second file from docker ecosystem. It is a source code for creating docker containers and their interconnections based on docker machines. For example, WordPress site needs (according to good architecture practice) php container and mysql container.

Line 4 in docker-compose.yml maps current directory (your ui automation project folder) to web docker container app folder. That is the magic which enables docker to run your cucumber tests in docker linux container that is ready with headless chrome, something that is not possible on osx.

Volumes are important docker feature, because without them, docker container does not remember any changes.

Additional magic is that bundle install is run on docker-compose build only when Gemfile is changed.

For example:

  1. docker-compose run web bash
  2. cd ~
  3. touch text.txt
  4. exit
  5. docker-compose run web bash
  6. ls -al ~

There is no text.txt file!

Here is composer reference documentation.

Here are instructions how to start testing using headless chrome:

  1. in docker-composer.yml, replace {project_name} with name of your ui automation project folder name.
  2. copy Dockerfile, docker-entrypoint.sh and docker-composer.yml to your ui automation project folder.
  3. start docker terminal, cd to ui automation project folder.
  4. run docker-compose build –force-rm
  5. run your tests: docker-compose run web /bundle/bin/cucumber -f html -o chrome.html features/feature_name.feature

chrome.html file is created in your local folder, in root folder of ui automation repository!

 

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Run Chrome with extension on SauceLabs

Reading Time: 1 minute

TLDR

In this post I will explain how to run chrome with extension on SauceLabs.

For one of my client I need to create webdriver automation scripts for web application that is javascript heavy. In order to identify html elements, I am using testability ids! chrome extension. We are also using SauceLabs in order to be able to test web application on chrome/windows7 combination.

Here is technology stack: cucumber->page-objects->watir-webdriver->webdriver->ruby

Heavy googling did not helped immediately because of this issue. Scroll to Ruby example. Can you spot the documentation UI issue? I also used git history feature to get important information. In the end I was able to see code example by looking at page source.

Here is the gist:

So, without the exploratory testing of ruby ChromeDriver documentation I would not be able to create automation script.

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather