KEMBAR78
Capybara + RSpec - ruby dsl-based web ui qa automation | PPTX
Capybara + RSpec – Ruby DSL based
Web UI QA Automation
Иван Соболевский
DPI.Solutions
Issoft / Coherent Solutions
О себе
Иван Соболевский
• IT consultant
DPI.Solutions
• QA Automation Engineer
ISsoft / Coherent Solutions
Testing tools:
• Rspec (22M downloads from rubygems.org)
• Cucumber (7,5 M
https://rubygems.org/search?utf8=%E2%9C%9
3&query=Cucumber)
• TestUnit (2,6 M
https://rubygems.org/search?utf8=%E2%9C%9
3&query=test-unit)
Rspec is:
BDD framework:
• BDD Engine
• Test runner
• Assertion tool
• Output generator
• Mocking tool
Project structure example
Notes:
Rules:
1) spec_helper.rb – entry point
2) *_spec.rb – Test name
pattern
Must read:
http://betterspecs.org/
“rspec --init” command will create “spec_helper.rb”
and “.rspec”
.rspec file example:
--color
--require spec_helper
--format documentation
--format h --out report/index.html
spec_helper.rb – tests, tools, webdriver
Initialization; entry point
Reporting:
2) gem ‘allure-rspec’ or other
gems
3) Monkey patch – the way to override code.
Usually “support” directory contains patches.
If you you want to add something to default
rspec report – just patch it!
1) Using default rspec html-report
“Monkey patch” example:
WebDriver Ruby wrappers
• Capybara (10,9 M downloads from rubygems.org)
• Watir (0,4 M https://rubygems.org/search?utf8=%E2%9C%93&query=Watir)
Capybara is:
visit ‘/session/new'
fill_in('First Name', :with => 'John')
choose('A Radio Button')
check('A Checkbox')
require ‘capybara/rspec’
browser = ENV.fetch('BROWSER', :firefox).to_sym
Capybara.register_driver browser do |app|
Capybara::Selenium::Driver.new(app, :browser => browser)
end
Capybara.javascript_driver = browser
Capybara.current_driver= browser
Capybara.app_host = 'http://google.com'
Capybara.default_selector = :css
Capybara.default_wait_time = 5
WebDriver wrapper
Configuration (in spec_helper.rb):
Capybara features:
visit ‘/session/new'
fill_in('First Name', :with => 'John')
fill_in('Password', :with => 'Seekrit')
fill_in('Description', :with => 'Really Long Text...')
choose('A Radio Button')
check('A Checkbox')
uncheck('A Checkbox')
attach_file('Image', '/path/to/image.jpg')
select('Option', :from => 'Select Box')
first(:xpath, ‘//a').click
all(:xpath, ‘//a').last.click
accept_alert do
click_link('Show Alert')
end
WebDriver calls:
page.driver.execute_script(“js body”)
page.driver.browser.find_element(:xpath, “//div”)
page.driver.browser.manage.window.maximize
Capybara Rspec matchers
expect(page).to have_title(‘My title’)
expect(page).to have_content(‘My content’)
expect(page).to have_xpath(‘My xpath’)
expect(page).to have_css(‘My css’)
expect(page).to have_link(‘My link’)
expect(page).to have_field(‘My field’)
…
Useful links:
• https://github.com/jnicklas/capybara - General description
• http://www.rubydoc.info/github/jnicklas/capybara/Capybara/ -
Documentation
Summary:
Rspec + Capybara
The most:
-popular,
-functional,
-stable,
-supportable tools for automation on Ruby
Спасибо! Вопросы!
Иван Соболевский
DPI.Solutions
www.dpi.solutions
Belarus QA Automation
Community
www.comaqa.by

Capybara + RSpec - ruby dsl-based web ui qa automation

  • 1.
    Capybara + RSpec– Ruby DSL based Web UI QA Automation Иван Соболевский DPI.Solutions Issoft / Coherent Solutions
  • 2.
    О себе Иван Соболевский •IT consultant DPI.Solutions • QA Automation Engineer ISsoft / Coherent Solutions
  • 3.
    Testing tools: • Rspec(22M downloads from rubygems.org) • Cucumber (7,5 M https://rubygems.org/search?utf8=%E2%9C%9 3&query=Cucumber) • TestUnit (2,6 M https://rubygems.org/search?utf8=%E2%9C%9 3&query=test-unit)
  • 4.
    Rspec is: BDD framework: •BDD Engine • Test runner • Assertion tool • Output generator • Mocking tool
  • 5.
  • 6.
    Notes: Rules: 1) spec_helper.rb –entry point 2) *_spec.rb – Test name pattern Must read: http://betterspecs.org/ “rspec --init” command will create “spec_helper.rb” and “.rspec” .rspec file example: --color --require spec_helper --format documentation --format h --out report/index.html spec_helper.rb – tests, tools, webdriver Initialization; entry point
  • 7.
    Reporting: 2) gem ‘allure-rspec’or other gems 3) Monkey patch – the way to override code. Usually “support” directory contains patches. If you you want to add something to default rspec report – just patch it! 1) Using default rspec html-report
  • 8.
  • 9.
    WebDriver Ruby wrappers •Capybara (10,9 M downloads from rubygems.org) • Watir (0,4 M https://rubygems.org/search?utf8=%E2%9C%93&query=Watir)
  • 10.
    Capybara is: visit ‘/session/new' fill_in('FirstName', :with => 'John') choose('A Radio Button') check('A Checkbox') require ‘capybara/rspec’ browser = ENV.fetch('BROWSER', :firefox).to_sym Capybara.register_driver browser do |app| Capybara::Selenium::Driver.new(app, :browser => browser) end Capybara.javascript_driver = browser Capybara.current_driver= browser Capybara.app_host = 'http://google.com' Capybara.default_selector = :css Capybara.default_wait_time = 5 WebDriver wrapper Configuration (in spec_helper.rb):
  • 11.
    Capybara features: visit ‘/session/new' fill_in('FirstName', :with => 'John') fill_in('Password', :with => 'Seekrit') fill_in('Description', :with => 'Really Long Text...') choose('A Radio Button') check('A Checkbox') uncheck('A Checkbox') attach_file('Image', '/path/to/image.jpg') select('Option', :from => 'Select Box') first(:xpath, ‘//a').click all(:xpath, ‘//a').last.click accept_alert do click_link('Show Alert') end WebDriver calls: page.driver.execute_script(“js body”) page.driver.browser.find_element(:xpath, “//div”) page.driver.browser.manage.window.maximize
  • 12.
    Capybara Rspec matchers expect(page).tohave_title(‘My title’) expect(page).to have_content(‘My content’) expect(page).to have_xpath(‘My xpath’) expect(page).to have_css(‘My css’) expect(page).to have_link(‘My link’) expect(page).to have_field(‘My field’) …
  • 13.
    Useful links: • https://github.com/jnicklas/capybara- General description • http://www.rubydoc.info/github/jnicklas/capybara/Capybara/ - Documentation
  • 14.
    Summary: Rspec + Capybara Themost: -popular, -functional, -stable, -supportable tools for automation on Ruby
  • 15.