ruby-rspec-selenium
Using the minimal number of libs to do UI Testing
Initial project structure
bundle init
to Generate Gemfile- Go to Rubygems and look for the right way to pu rspec and selenium-webdriver at the Gemfile
gem 'rspec', '~> 3.9'
gem 'selenium-webdriver', '~> 3.142', '>= 3.142.6'
bundle install
to install all gems at Gemfilerspec --init
to create rspec structure:spec
folderspec_helper.rb
file
.rspec
file
Writing first test script
- Create the first test file at
spec
foldertest_specfile.rb
- Describe: our first scenario
- All starts with a
describe
plusit
(orexample
) commands
- All starts with a
- To run tests, just type
rspec <specfile>.rb
- It is not a actual test script without an assertion: using
expect
[More info about Expectations] - Creating class file to play around doing tests with an objects
Using Selenium WebDriver
- First of all, you must Download Firefox, Chrome Driver compatible with your Browser
- Put its path into the Path environment variable
- create file
test_with_selenium.rb
- add require 'selenium-webdriver'
- Start to use Selenium API
- Start with
driver = Selenium::WebDriver.for :firefox or :chrome
driver.get "<URL>"
open and load a Web Page- You can use
driver.navigate.to "<URL>"
, to navigate to a webpage also
- You can use
- Start with
- Exercise element locators with: find_element (HOW, WHAT)
- HOW: Strategy used to locate elements
- :id
- :name
- :class
- :tag_name
- :css
- WHAT: text to find element
- HOW: Strategy used to locate elements
- RSpec Hooks:
- before, after:
- :each
- :all
- before, after:
Optional Moves
- One can find interesting moving standard configurations, including stardard Hooks to
spec_helper.rb
file- Do it within
RSpec.configure do |config|
session
- Do it within
- Using tags to filter examples:
it 'example name', :tag do ...
orit 'example name', :tag => 'tag value' do ...
- Running options
- Test Progress style:
rspec spec/test_*.rb --format documentation
- Running filtering by tags:
rspec spec/test_*.rb --tag tag
orrspec spec/test_*.rb --tag tag:'tag value'
- Running filtering by example name:
rspec spec/test_*.rb --example 'example name'
orrspec spec/test_*.rb -e 'example name'
- Test Progress style:
What is next
- Implement POM
- Explore more types of Elements: Combo box, Radiobutton, check box and Ajax calls