15
Capybara + RSpec Ruby DSL based Web UI QA Automation Иван Соболевский DPI.Solutions Issoft / Coherent Solutions

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

Embed Size (px)

Citation preview

Page 1: Capybara + RSpec - ruby dsl-based web ui qa automation

Capybara + RSpec – Ruby DSL based

Web UI QA Automation

Иван Соболевский

DPI.Solutions

Issoft / Coherent Solutions

Page 2: Capybara + RSpec - ruby dsl-based web ui qa automation

О себе

Иван Соболевский

• IT consultant

DPI.Solutions

• QA Automation Engineer

ISsoft / Coherent Solutions

Page 3: Capybara + RSpec - ruby dsl-based web ui qa automation

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)

Page 4: Capybara + RSpec - ruby dsl-based web ui qa automation

Rspec is:

BDD framework:

• BDD Engine

• Test runner

• Assertion tool

• Output generator

• Mocking tool

Page 5: Capybara + RSpec - ruby dsl-based web ui qa automation

Project structure example

Page 6: Capybara + RSpec - ruby dsl-based web ui qa automation

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

Page 7: Capybara + RSpec - ruby dsl-based web ui qa automation

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

Page 8: Capybara + RSpec - ruby dsl-based web ui qa automation

“Monkey patch” example:

Page 9: Capybara + RSpec - ruby dsl-based web ui qa automation

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)

Page 10: Capybara + RSpec - ruby dsl-based web ui qa automation

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):

Page 11: Capybara + RSpec - ruby dsl-based web ui qa automation

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

Page 12: Capybara + RSpec - ruby dsl-based web ui qa automation

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’)

Page 13: Capybara + RSpec - ruby dsl-based web ui qa automation

Useful links:

• https://github.com/jnicklas/capybara - General description

• http://www.rubydoc.info/github/jnicklas/capybara/Capybara/ -

Documentation

Page 14: Capybara + RSpec - ruby dsl-based web ui qa automation

Summary:

Rspec + Capybara The most:

-popular,

-functional,

-stable,

-supportable tools for automation on Ruby

Page 15: Capybara + RSpec - ruby dsl-based web ui qa automation

Спасибо! Вопросы!

Иван Соболевский

DPI.Solutions

www.dpi.solutions

Belarus QA Automation

Community

www.comaqa.by