Saturday, September 23, 2017

Headless testing with Firefox

Contents:

1) Introduction
2) Getting started - requirements
3) Headless Firefox configuration
4) Demo

1) Introduction

Last week I wanted to show you how to run Selenium tests using headless Firefox. Unfortunately my Browser Capabilities turned out to be outdated so I opted for correct Firefox Selenium Browser Capabilities explanation instead.

It turned out that most of the work was done already and I just needed few minutes to run Firefox in headless mode. Here is how I did it.

2) Getting started - requirements

According to official Mozilla guide you need Firefox 55+ on Linux and Firefox 56+ on Windows/Mac. 

I'm currently using Windows so I had to download Firefox 56 beta first (stable version is 55).

3) Headless Firefox configuration

My code from last week was almost sufficient. I only needed to add one option (--headless). Configuration is almost identical as in Chrome.



4) Demo

As usual I prepared quick demo for my readers. I run it few times in headless/non-headless mode on my local machine and didn't observe any time differences. Still the main benefit of headless testing is ease of use on Unix machines.  We don't have to install xvfb and other tools related to graphic environment.

Demo is testing that only 5 posts is displayed on my homepage.

PageObject code:


Class in which I configure Firefox browser:


Actual test code:


As usual I posted all the code from above in my GitHub Awesome Testing project.