BDD

Automated Accessibility with Cucumber and Capybara-Accessible

Automated Web Accessibility

Automated web accessibility checks plays important role in order to make website accessible to the people with disabilities. Accessibility testing can be done in the different ways and using different techniques but while plugging them into the BDD tools like Cucumber is good fun.

In this post, we will see how we can use ‘capybara-accessible‘ Rubygem in order to check accessibility of the website.

Capybara-Accessible

Capybara-accessible is a RubyGem which uses Google Accessibility Developer tool in order to check website against Google’s accessibility standards audit rules.

Using Gem

In order to use capybara-accessible gem, you just need to include it in your Gemfile and update bundle

Note: You also need to have ‘selenium-webdriver’ gem in order to get capybara-accessible working

Then you just update bundle

Now you need to update your ‘features/support/env.rb’ file with below code

This will use default capybara driver accessible.

You can then run ‘cucumber’ to see the result.

capybara-accessible In Action

Let’s create a feature file to test accessibility of the Google Home page and BBC home page

and add following feature

Now you can add step_definitions by using capybara library  in the ‘features/step_definitions/google_steps.rb’

You  are now good to run cucumber to perform accessibility check

I saw something like this

capybara-accessible

Why Google Scenario is tagged as @inaccessible 

Google scenario is failing if we don’t tag it as @inaccessible. Error looks like this

We have a hook that skips scenarios for accessibility check.

So the hook skips the Google scenario for the accessibility check.

Try it Yourself

You can find source code for the demo on Github

Cuke_Experiment

Conclusion

You can add automated accessibility checks with BDD tool Cucumber using ‘capybara-accessible’. Thanks to @ckundo

Watch Video