Date post: | 19-Jul-2015 |
Category: |
Engineering |
Upload: | comaqaby |
View: | 102 times |
Download: | 1 times |
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').clickall(:xpath, ‘//a').last.click
accept_alert doclick_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