Cucumber Tip – Skip HTTP Auth with capybara and headless Drivers

HTTP Authentication

HTTP authentication is a mechanism of force use to user credential before entering into the website. While developing application, we might need to use HTTP authentication to restrict unauthorised user accessing site. You can read more HTTP auth  

While automating the pages with HTTP authentication we need to enter the login credentials to carry on test journey. Here is something we can do to skip HTTP auth

Set HTTP Headers

Headless capybara drivers provides mechanism to set HTTP headers before visiting page which skips http authorisation. There are Poltergeist and Mechanize  drivers for the capybara which allows us to set HTTP header. You can add those steps in the before hook.

Using Poltergeist

You can set HTTP header with Poltergeist to skip basic http auth like this. You need base64 for this

Using Mechanize

You can set headers using mechanize like this:

It become so simple to skip basic http auth using headless drives like Poltergeist and Mechanize.

Happy BDD