WebDriver Ruby SDK
The Evinced WebDriver Ruby SDK integrates with new or existing Selenium WebDriver tests to automatically detect accessibility issues. By adding a few lines of code to your Selenium WebDriver project, you can begin analyzing all the web pages and DOM changes to provide a dynamic view of how your site can become more accessible. As a result of the test, a rich and comprehensive report is generated to easily track issues to resolution.
Interested in seeing this in action? Contact us to get started!
Prerequisites
- Ruby version 2.6.3 or higher
- selenium-webdriver gem 4.0.1 or higher
- ChromeDriver
Get Started
Installation
1gem install selenium-webdriver2gem install evinced-rubysdk --source https://<USER>:<PASSWORD>@evinced.jfrog.io/artifactory/api/gems/private-ruby
To avoid using plain text password you can generate an encrypted password in your JFrog profile.
If there is an issue
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)bad response Not Found 404 please update the gem package manager
gem update --system. We observed such an issue on gem version 3.2.3.
Your First Test
SDK Initialization
To work with WebDriver Ruby SDK you need to have authentication token. Please refer to licensing section for details.
The only command you need to add to add Evinced SDK to your code is
1require 'evinced/rubysdk'
Evinced uses the selenium-webdriver
gem which will be added automatically.
All Evinced commands will be attached to the driver
object upon initialization using the Selenium::WebDriver
.for command.
Add Evinced accessibility checks (Single Run Mode)
This is a simple example of how to add an Evinced accessibility scan to a test. Please note the inline comments that give detail on each test step.
1#filename: evinced_rspec_demo_spec.rb23require 'evinced/rubysdk'45describe 'Evinced RSpec example' do6 it 'gathers issues with ev_analyze' do7 driver = Selenium::WebDriver.for :chrome8 driver.get 'https://ruby-doc.org/'9 issues = driver.ev_analyze10 expect(issues.size).to be == 011 end12end
Run this code with the command rspec evinced_rspec_demo_spec.rb
Add Evinced accessibility checks (Continuous Mode)
This is an example of how to add a continuous Evinced accessibility scan to a test. Using the ev_start
and ev_stop
methods, the Evinced engine will continually scan in the background capturing all DOM changes and page navigations as the test is executed. This will capture all accessibility issues as clicking on drop-downs or similar interactions reveals more of the page. The advantage of continuous mode is that no interaction with the actual test code is needed.
1#filename: evinced_rspec_demo_spec.rb23require 'evinced/rubysdk'45describe 'Evinced rspec example' do6 it 'gathers issues with ev_start and ev_stop' do7 driver = Selenium::WebDriver.for :chrome8 driver.ev_start910 url1, url2 = %w[https://ruby-doc.org/ https://ruby-doc.org/core-3.1.0/File.html]11 driver.get url112 driver.get url21314 driver.ev_stop1516 expect(Evinced::Rubysdk::OVERALL_RESULT[url1].size).to be > 017 expect(Evinced::Rubysdk::OVERALL_RESULT[url2].size).to be > 018 end19end
Run this code with the command rspec evinced_rspec_demo_spec.rb
API
global initialization
Initializes the Evinced object within the project.
Example
1require 'evinced/rubysdk'
In this WebDriver Ruby SDK there is no specific command you need to call to initialize SDK. However, there is a mechanism to
define global configuration options. For instance you can call it in BeforeAll hook.
Please refer to examples that uses Evinced.global_config
in configuration section
Please refer to configuration to see examples of using init with options.
ev_analyze(options={}) -> array
Scans the current page and returns a list of accessibility issues.
Note: This method is not supported if ev_start
is already running.
Please refer to configuration to see examples of using init with options.
Example
1issues = @driver.ev_analyze(root_selector: '#some .selector')2expect(issues.size).to eql 2
Return value
Array
of Issue type
A Report object is returned containing accessibility issues. This is the recommended method for static page analysis.
For more information regarding reports as well as the Report
object itself, please refer to our detailed Web Reports page.
ev_start(options={}) -> nil
Continually watches for DOM mutations and page navigation and records all accessibility issues until the ev_stop
method is called. This method is recommended for dynamic page flows.
Example
1 @driver.get 'http://example.com'2 @driver.ev_start3 expect(@driver.ev_stop.size).to eql 6
Return value
nil
ev_stop -> array
Stops the process of issue gathering started by ev_start
command.
Example
1 @driver.get 'http://example.com'2 @driver.ev_start3 @driver.find_element(css: '#some.selector').click4 @driver.find_element(xpath: '//div[@class="clickable"]').click5 issues = @driver.ev_stop6 expect(issues.size).to be > 07 expect(issues).not_to be_ev_valid
Return value
Array
of Issue type
Returns an object containing recorded accessibility issues from the point in time at which the ev_start
method
was instantiated. For more information regarding reports as well as the returned object itself, please refer to detailed
Web Reports page.
ev_save_file(destination: 'evinced-results.json', format: :json, report: nil) -> nil
Saves list of the issues in a file, with the specified format and location. For example, format could be ‘json
',
'html
, 'sarif
' or 'csv
'. Please find detailed information on Web Reports page.
Example
1 issues = @driver.ev_analyze2 @driver.ev_save_file destination: '/tmp/evinced.json'
Arguments
1 destination: 'evinced-results.json', # path to the file where to store results2 format: :json, # output format, :json by default. :yaml and html are also supported3 report: nil # the report to store. Optional. Will store the daefault report object.
Return value
nil
Aggregated Report
The aggregated report feature allows you to have a general aggregated report for the
whole run (not only for one test or suite).
This report will contain all the issues found by the tests where ev_start
and ev_stop
commands were called.
It is still possible to use the ev_save_file
command in any place of your code along with this Aggregated Report feature.
Example
1tmpfile = Tempfile.new('evinced-test-results').path2Evinced.save_file destination: tmpfile, format: :html
Licensing
To work with WebDriver Ruby SDK you need to have Authentication token. There are two methods to provide the token: offline mode and online mode. The difference is if you use online mode the request to obtain the token will be sent to Evinced Licencing Server. You need to provide Service ID and Secret API key in such a case. They are available via the Evinced Product Hub.
Offline mode assumes that you already have token and can provide it directly. If an offline token is required please reach out to your account team or support@evinced.com.
We encourage to use environment variables to store credentials and read them in code
1# Offline mode2export AUTH_SERVICE_ID=<serviceId>3export AUTH_TOKEN=<token>45# Online mode6export AUTH_SERVICE_ID=<serviceId>7export AUTH_SECRET=<secret>
Example
1 # Offline mode2 config.before(:suite) do3 token, service_id = [ ENV['AUTH_TOKEN'], ENV['AUTH_SERVICE_ID'] ]45 Evinced.set_offline_credentials token: token, service_id: service_id6 end78 # OR9 # Online mode10 config.before(:suite) do11 secret, service_id = [ ENV['AUTH_SECRET'], ENV['AUTH_SERVICE_ID'] ]1213 Evinced.set_credentials secret: secret, service_id: service_id14 end
Configuration
The same configuration object can be used in global initialization, ev_start
and ev_analyze
methods but
with a bit different consequences. By providing some options in global initialization method you define a global
configuration for all calls of ev_start
or ev_analyze
methods. Please note that global configuration is not
intended to be altered from tests due to it will affect all the rest tests as well as tests running in parallel threads.
To alter configuration in specific tests you can provide config on the method's level, for instance with ev_start
it
defines local configuration for this particular session until ev_stop
is called.
If provided in both levels, the command's level config will override the global one.
Engines configuration
Evinced uses two separate engines when scanning for accessibility issues, one is the aXe engine and the other is the Evinced engine. By default, Evinced disables the aXe Needs Review and Best Practices issues based on customer request and due to the fact they are mostly false positives. Please note this setting when comparing issue counts directly. See an example of how to enable Needs Review and Best practices issues in our toggles section.
Configuration object type
EvincedConfig
class is used as a configuration object.
Restoring default options
1Evinced::Rubysdk::EvincedConfig.restore_default
Root Selector
Instructs engine to return issues which belong to or which are nested to element with the specified selector. By default the issues for all elements from document root will be returned.
nil
by default.
Example
Global
1Evinced.global_config.root_selector = "#my-top-level-selector"2# OR3Evinced.global_config[:rootSelector] = "#my-top-level-selector"
Local
1driver.ev_start(rootSelector: "#my-top-level-selector")
AXE Configuration
Evinced leverages Axe open-source accessibility toolkit as part of its own accessibility detection engine. The Evinced engine is able to pinpoint far more issues than Axe alone.
For the full Axe config options, see Axe Core API.
Example
1Evinced.global_config.plugins.axe[:resultTypes] = ['violations']23# It'll replace default rules4Evinced.global_config.plugins.axe[:rules] = {5 'document-title': { enabled: false },6 'html-has-lang': { enabled: true },7}89# It'll add/replace axe rules10Evinced.global_config.plugins.axe.rules['document-title'] = { enabled: true }11Evinced.global_config.plugins.axe.rules['accesskeys'] = { enabled: false }
Errors Strict Mode
When set to true
it switches SDK in mode when Evinced SDK errors are thrown as runtime errors and stops current test
execution. Otherwise errors are printed into console except critical ones.
false
by default.
Example
The feature **is not yet implemented** in this SDK. If you'd like to increase the priority of it, please contact support@evinced.com.
Engine Logging
Switches logging on for engine. Log messages from the engine will be printed to console.
Levels are: debug
, info
, warn
, error
nil
by default.
error
is a default level on engine side.
1Evinced.global_config.set_engine_logging level: 'info', context: true
Reports Screenshots
The Screenshots feature allows to include screenshots to the Evinced reports. When the feature is enabled, Evinced will take screenshots of the page, highlight an element with a specific accessibility issue, and include them to the report.
false
by default.
Note: The Screenshots feature may affect the test run performance.
Enabling the Screenshots feature
The method enable_screenshots
should be used to switch the on/off:
1# To enable screenshots please use2Evinced.global_config.enable_screenshots3# OR4Evinced.global_config.enable_screenshots true
Toggles
Toggles are feature flags which controls SDK and Engine behavior. With toggles we introduce experimental features or manage the way how accessibility issues are gathered. The list of toggles is not specified so we suggest not to rely on specific toggle name or value and use them in investigation purposes only.
Example enabling aXe Best Practices and Needs Review Issues
1Evinced.global_config.experimental_flags.toggles[:USE_AXE_BEST_PRACTICES] = true2Evinced.global_config.experimental_flags.toggles[:USE_AXE_NEEDS_REVIEW] = true
Skip Validations
Skips specific validations for the given URL pattern and the selector.
SkipValidation[]
by default.
Example
The feature **is not yet implemented** in this SDK. If you'd like to increase the priority of it, please contact support@evinced.com.
Knowledge Base Link overrides
This custom parameter helps to customize knowledge base links in the reports. Those links are displayed in the reports as follows:
The knowledge base link can be overridden for every issue type ID.
Example
The feature **is not yet implemented** in this SDK. If you'd like to increase the priority of it, please contact support@evinced.com.
Shadow DOM support
Example
1# The support is off by default.2# To switch on3Evinced.global_config.enable_shadow_dom4# OR5Evinced.global_config.enable_shadow_dom true
IFrames support
When set to true
, the accessibility tests run analysis on iframes that exist inside the page. Default is false
.
The feature **is not yet implemented** in this SDK. If you'd like to increase the priority of it, please contact support@evinced.com.
Global Switch
Global Switch allows to disable or enable Evinced functionality. It could be needed, for example, while working on functional tests in your local environment or for running some CI jobs that are not intended to gather information regarding accessibility issues.
When switched off
ev_start
andev_save_file
will be bypassed.ev_stop
andev_analyze
will return an empty report.evValid()
will never fail.
true
by default.
Important! Global Switch environment variable overrides the global configuration option.
Switch on/off Evinced functionality in config
1Evinced.on false2## OR3Evinced.off
Switching off Evinced functionality with environment variable
1export EV_SWITCH_ON=false
Tutorials
You can find fully functional example projects on our GitHub
Step by step adding Evinced to your tests
1. Initial tests
1#filename: evinced_tutorial_spec.rb23require 'selenium-webdriver'45EVINCED_DEMO_SITE = 'https://demo.evinced.com/'6ANOTHER_PAGE_ON_DEMO_SITE = 'https://demo.evinced.com/results/?what=Caravan&where=Canada&date=Mon%20Mar%2029%202021%2011:38:30%20GMT+0300%20(Israel%20Daylight%20Time)'78BASE_SELECTOR = '#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container'9SELECT_HOME_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(1) > div > div.dropdown.line"10SELECT_WHERE_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(2) > div > div.dropdown.line"11TINY_HOME_OPTION = "#{BASE_SELECTOR} > div:nth-child(1) > div > ul > li:nth-child(2)"12EAST_COAST_OPTION = "#{BASE_SELECTOR} > div:nth-child(2) > div > ul > li:nth-child(3)"1314describe 'evinced demo site' do15 before :all do16 @driver = Selenium::WebDriver.for :chrome17 Selenium::WebDriver::Wait.new(timeout: 10)18 end1920 after :all do21 @driver.quit22 end2324 it 'has clickable home selector' do25 @driver.get EVINCED_DEMO_SITE26 @driver.find_element(css: SELECT_HOME_DROPDOWN).click27 @driver.find_element(css: TINY_HOME_OPTION).click28 end2930 it 'has clickable where selector' do31 @driver.get EVINCED_DEMO_SITE32 @driver.find_element(css: SELECT_WHERE_DROPDOWN).click33 @driver.find_element(css: EAST_COAST_OPTION).click34 end3536 it 'has another page' do37 @driver.get ANOTHER_PAGE_ON_DEMO_SITE38 expect(@driver.current_url).to eql(ANOTHER_PAGE_ON_DEMO_SITE)39 end40end
Run this code snipped with rspec evinced_tutorial_spec.rb
2. Add evinced SDK to your tests
1#filename: evinced_tutorial_spec.rb23require 'selenium-webdriver'4require 'evinced/rubysdk' # <---- Only one line of code is added56EVINCED_DEMO_SITE = 'https://demo.evinced.com/'7ANOTHER_PAGE_ON_DEMO_SITE = 'https://demo.evinced.com/results/?what=Caravan&where=Canada&date=Mon%20Mar%2029%202021%2011:38:30%20GMT+0300%20(Israel%20Daylight%20Time)'89BASE_SELECTOR = '#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container'10SELECT_HOME_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(1) > div > div.dropdown.line"11SELECT_WHERE_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(2) > div > div.dropdown.line"12TINY_HOME_OPTION = "#{BASE_SELECTOR} > div:nth-child(1) > div > ul > li:nth-child(2)"13EAST_COAST_OPTION = "#{BASE_SELECTOR} > div:nth-child(2) > div > ul > li:nth-child(3)"1415describe 'evinced demo site' do16 before :all do17 @driver = Selenium::WebDriver.for :chrome18 Selenium::WebDriver::Wait.new(timeout: 10)19 end2021 after :all do22 @driver.quit23 end2425 it 'has clickable home selector' do26 @driver.get EVINCED_DEMO_SITE27 @driver.find_element(css: SELECT_HOME_DROPDOWN).click28 @driver.find_element(css: TINY_HOME_OPTION).click29 end3031 it 'has clickable where selector' do32 @driver.get EVINCED_DEMO_SITE33 @driver.find_element(css: SELECT_WHERE_DROPDOWN).click34 @driver.find_element(css: EAST_COAST_OPTION).click35 end3637 it 'has another page' do38 @driver.get ANOTHER_PAGE_ON_DEMO_SITE39 expect(@driver.current_url).to eql(ANOTHER_PAGE_ON_DEMO_SITE)40 end41end
Please see line 4 above. It’s the only line you need to add to your code to include the Evinced ruby SDK. Optionally, line 3 could be omitted because the Evinced SDK requires Selenium WebDriver implicitly.
3. Activate accessibility issue gathering and store results in file
1#filename: evinced_tutorial_spec.rb23require 'selenium-webdriver'4require 'evinced/rubysdk'56EVINCED_DEMO_SITE = 'https://demo.evinced.com/'7ANOTHER_PAGE_ON_DEMO_SITE = 'https://demo.evinced.com/results/?what=Caravan&where=Canada&date=Mon%20Mar%2029%202021%2011:38:30%20GMT+0300%20(Israel%20Daylight%20Time)'89BASE_SELECTOR = '#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container'10SELECT_HOME_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(1) > div > div.dropdown.line"11SELECT_WHERE_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(2) > div > div.dropdown.line"12TINY_HOME_OPTION = "#{BASE_SELECTOR} > div:nth-child(1) > div > ul > li:nth-child(2)"13EAST_COAST_OPTION = "#{BASE_SELECTOR} > div:nth-child(2) > div > ul > li:nth-child(3)"1415describe 'evinced demo site' do16 before :all do17 @driver = Selenium::WebDriver.for :chrome18 Selenium::WebDriver::Wait.new(timeout: 10)19 end2021 after :all do22 @driver.quit23 end2425 before :each do26 @driver.ev_start27 end2829 after :each do30 @driver.ev_stop31 end3233 after :all do34 @driver.ev_save_file destination: 'evinced-tutorial-results.json'35 end3637 it 'has clickable home selector' do38 @driver.get EVINCED_DEMO_SITE39 @driver.find_element(css: SELECT_HOME_DROPDOWN).click40 @driver.find_element(css: TINY_HOME_OPTION).click41 end4243 it 'has clickable where selector' do44 @driver.get EVINCED_DEMO_SITE45 @driver.find_element(css: SELECT_WHERE_DROPDOWN).click46 @driver.find_element(css: EAST_COAST_OPTION).click47 end4849 it 'has another page' do50 @driver.get ANOTHER_PAGE_ON_DEMO_SITE51 expect(@driver.current_url).to eql(ANOTHER_PAGE_ON_DEMO_SITE)52 end53end
Please review the new lines from 25 till 35. This code will activate accessibility issues gathering before each test and stop it after test.
You can add it into rspec_helper.rb
to apply to all spec files in your test suite.
The new after :all
block stores results in the file.
4. Store results in after :suite once
The previous code snippet shows how to store results after running each test in the spec file.
It is possible to save a separate report for each test, but usually it is more convenient to create a single consolidated report once all the tests are complete.
RSpec has an after :suite
hook, however it is likely that the driver object is not initialized there. In this case the Evinced.save
static method can be used.
1#filename: evinced_tutorial_spec.rb23require 'selenium-webdriver'4require 'evinced/rubysdk'56EVINCED_DEMO_SITE = 'https://demo.evinced.com/'7ANOTHER_PAGE_ON_DEMO_SITE = 'https://demo.evinced.com/results/?what=Caravan&where=Canada&date=Mon%20Mar%2029%202021%2011:38:30%20GMT+0300%20(Israel%20Daylight%20Time)'89BASE_SELECTOR = '#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container'10SELECT_HOME_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(1) > div > div.dropdown.line"11SELECT_WHERE_DROPDOWN = "#{BASE_SELECTOR} > div:nth-child(2) > div > div.dropdown.line"12TINY_HOME_OPTION = "#{BASE_SELECTOR} > div:nth-child(1) > div > ul > li:nth-child(2)"13EAST_COAST_OPTION = "#{BASE_SELECTOR} > div:nth-child(2) > div > ul > li:nth-child(3)"1415describe 'evinced demo site' do16 before :all do17 @driver = Selenium::WebDriver.for :chrome18 Selenium::WebDriver::Wait.new(timeout: 10)19 end2021 after :all do22 @driver.quit23 end2425 before :each do26 @driver.ev_start27 end2829 after :each do30 @driver.ev_stop31 end3233 it 'has clickable home selector' do34 @driver.get EVINCED_DEMO_SITE35 @driver.find_element(css: SELECT_HOME_DROPDOWN).click36 @driver.find_element(css: TINY_HOME_OPTION).click37 end3839 it 'has clickable where selector' do40 @driver.get EVINCED_DEMO_SITE41 @driver.find_element(css: SELECT_WHERE_DROPDOWN).click42 @driver.find_element(css: EAST_COAST_OPTION).click43 end4445 it 'has another page' do46 @driver.get ANOTHER_PAGE_ON_DEMO_SITE47 expect(@driver.current_url).to eql(ANOTHER_PAGE_ON_DEMO_SITE)48 end49end5051RSpec.configure do |config|52 config.after :suite do53 Evinced.save_file destination: 'evinced-tutorial-results.html', format: 'html'54 end55end
Support
Please feel free to reach out to support@evinced.com with any questions.
FAQ
- Can I configure which validations to run?
Yes, see the configuration section for details on how to configure Axe validations to your needs.
- Can I run tests with Evinced using cloud-based services like Sauce Labs, Perfecto, or BrowserStack?
Yes, we have tested the Evinced SDK on many of these types of cloud-based services and expect no issues.