This article will explain:
How to use the Applitools Eyes SDK for adding visual validation to your Selenium Ruby and
Capybara tests.
Capybara tests.
Using the Applitools Eyes SDK involves 4 main steps:
1. Create and config an Eyes object.
2. Start a test.
3. Add UI validation check points.
4. Close the test.
The example below illustrates how to build a visual test with Selenium Ruby followed by another example using Capybara:
require 'eyes_selenium' eyes = Applitools::Eyes.new # This is your api key, make sure you use it in all your tests. eyes.api_key = 'YOUR_API_KEY' # Get a selenium web driver object. my_webdriver = Selenium::WebDriver.for :firefox begin # Start visual testing using my_webdriver and setting the viewport to 1024x768. eyes.test(app_name: 'Applitools', test_name: 'Test Web Page', viewport_size: {width: 1024, height: 768}, driver: my_webdriver) do |driver| driver.get 'http://www.applitools.com' # Visual validation point #1 eyes.check_window('Main Page') driver.find_element(:css, ".features>a").click # Visual validation point #2 eyes.check_window('Features Page') end ensure my_webdriver.quit endThe example below illustrates how to build a visual test using Capybara:
require 'capybara/rspec' require 'eyes_selenium' Capybara.run_server = false describe 'Applitools' , :type=>:feature, :js=>true do before(:all) do end let(:eyes) do Applitools::Eyes.new end describe 'Test Web Page' do it 'should navigate from the main page to the features page' do # Set your api key, and make sure you use it in all your tests. eyes.api_key = 'your api key' # Start visual testing with browser viewport set to 1024x768. eyes.test(app_name: 'Applitools', test_name: 'Test Web Page', viewport_size: {width: 1024, height: 768}, driver: page.driver.browser) do visit 'http://www.applitools.com' # Visual validation point #1 eyes.check_window('Main Page') page.first('.features>a').click # Visual validation point #2 eyes.check_window('Features Page') end end end end