Watir Tutorial
Getting Started with Applitools
Want to learn more about the Applitools platform and how it works? First get started with one of the following:
Running Tests with Applitools
Prerequisites
- A free Applitools account and Applitools API KEY
Tip: Unsure how to set up your API key?
Learn how to get started at Setting Up
Note: Installing `git` is optional
Installing git is used to clone the demo project from the Github repository. Instead of installing git
, you can simply download the Zip file from the repository. Further, if you are Mac, you already have git
.
Google Chrome Browser https://www.google.com/chrome/
ChromeDriver https://chromedriver.chromium.org/getting-started
ChromeDriver must be installed and in your `PATH`
Below are some resources from the internet that'll help you
On Mac, place the chromedriver
executable in /usr/local/bin
folder so Eclipse and IntelliJ can find it.
Running the Example Project
- Clone or download the repository and navigate to that folder
git clone https://github.com/applitools/tutorial-watir-ruby-basic.git
cd tutorial-watir-ruby-basic
2
Note: you can alternatively download the project as a Zip file and extract it
- Install the dependencies
gem install bundler && bundle install
- Run the example test
APPLITOOLS_API_KEY="[Your API Key]" bundle exec ruby simple_test_script.rb
This will first set your APPLITOOLS_API_KEY
into the node process then run bundle exec
.
Adding Applitools Eyes to an Existing Project
Install Applitools Eyes dependencies:
gem install eyes_selenium
Sample test
require 'eyes_selenium'
require 'watir'
options = Selenium::WebDriver::Chrome::Options.new
runner = Applitools::ClassicRunner.new
eyes = Applitools::Selenium::Eyes.new(runner: runner)
browser = Watir::Browser.new(:chrome, options:options)
Applitools::EyesLogger.log_handler = Logger.new(STDOUT).tap do |l|
l.level = Logger::INFO
end
sconf = Applitools::Selenium::Configuration.new.tap do |conf|
conf.api_key = ENV['APPLITOOLS_API_KEY']
conf.app_name = 'Demo App - Watir'
conf.test_name = 'Ruby Watir demo'
conf.viewport_size = Applitools::RectangleSize.new(800, 600)
end
eyes.config = sconf
begin
# Call Open on eyes to initialize a test session
driver = eyes.open(driver: browser.driver)
# Navigate to the url we want to test
driver.get('https://demo.applitools.com/index.html')
# Note to see visual bugs, run the test using the above URL for the 1st run.
# but then change the above URL to https://demo.applitools.com/index_v2.html (for the 2nd run)
# check the login page
eyes.check('Login page', Applitools::Selenium::Target.window.fully)
# Click the 'Log In' button
driver.find_element(:id, 'log-in').click
# Check the app page
eyes.check('App Page', Applitools::Selenium::Target.window.fully)
eyes.close
ensure
# Close the browser
driver.quit
eyes.abort
# Get and print all test results
puts runner.get_all_test_results
end
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
More information
Resources
Terms & Conditions Privacy Policy GDPR© 2021 Applitools. All rights reserved.