Test Automation using frameworks like Capybara and introduction to Cucumber
Web-based automation tools
Selenium
Watir
Capybara
Why we need automation framework ?
-
Easy to read and maintain.
-
Agile/TDD environments.
-
Avoid doing repetitive tasks.
Capybara
-
Capybara is a library/gem built to be used on top of an underlying web-based driver.
-
Tool of choice for developing web-based automated tests.
-
Capybara will try to locate the relevant element in the DOM (Document Object Model) and execute the action, such as click button, link, etc.
-
it offers a user-friendly DSL (Domain Specific Language) which is used to describe actions that are executed by the underlying web driver.
- Capybara will try to locate the relevant element in the DOM (Document Object Model) and execute the action, such as click button, link, etc.
- Here are some of the web drivers supported by Capybara:
rack::test
selenium-webdriver
capybara-webkit
Installation
gem install capybara
Basic DSL
Click
- visit(page_url)
- click_link(link_text or id_of_link)
- click_button(text)
- fill_in('id_of_control', with=>"value")
- choose(radio_button)
- check(check_box)
- uncheck(check_box)
- select('option', :from=>"select box")
Introduction to Cucumber
-
Cucumber is a powerful tool to write BDD Tests
- You can write your scenarios and definitions with common language
Feature: Find the GameSparks Website
Scenario: Search for the website
Given I am on the Google homepage
Then I will search for "GameSpark"
Then I should see "GameSpark"
Then I will click the Get Started link
1. Describe behaviour in plain text
2. Write a step definition in Ruby
Given(/^I am on the Google homepage$/) do
visit 'http://www.google.com'
end
Then(/^I will search for "(.*?)"$/) do |searchText|
fill_in 'lst-ib', :with => searchText
end
Then(/^I should see "(.*?)"$/) do |expectedText|
page.should have_content(expectedText)
end
Then(/^I will click the Get Started link$/) do
click_link('Get Started')
end
3. Run and watch it fail.
4. Write code to make the step pass.
5. Repeat 2-5 until green like a cuke
Questions????
Automation using
By Manoj Menon
Automation using
- 211