BDD (Behaviour Driven Development) is a synthesis and refinement of practices stemming from TDD (Test Driven Development) and ATDD (Acceptance Test Driven Development). Although BDD is principally an idea about how software development should be managed by both business interests and technical insight, the practice of BDD does assume the use of specialized software tools to support the development process.
2. ❖ What is BDD?
➢ The main focus is on the expected behavior of the application and it’s
components.
➢ User stories created and maintained collaboratively by all
stakeholders
❖ What are the benefits?
➢ Define verifiable, executable and unambiguous requirements
➢ Developing features that truly add business value
➢ Preventing defects rather than finding defects
➢ Bring QA involvement to the forefront, great for team dynamics
3. ❖ Testing tool based on BDD written in Ruby.
❖ Tests are written in plain language called Gherkin based BDD style of
Given, When, Then, which any layperson can understand.
❖ Tests are grouped into feature files with .feature extension.
➢ E.g. Feature: As a Myish user I should be able to login
Scenario: Successful login
Given I am on the Myish home page
When I fill in email and password
And I click login button
Then I should be able to click on the profile
4. ❖ Capybara is a web-based automation framework used for creating
functional tests that simulate how users would interact with the application
❖ Capybara is library/gem built to be used on top of underlying web-based
driver
❖ Offers user-friendly DSL ( Domain Specific Language )
❖ Supported driver
➢ Rack::test
■ Default driver. No JavaScript support
➢ Selenium-Webdriver
■ Mostly used in web-based automation FW
➢ Capybara-Webkit
■ For true headless testing with JavaScript support
5. ❖ Basic DSL :
➢ Visit('page_url') # navigate to page
➢ Click_link('id_of_link') # click link by id
➢ Click_link('link_text') # click link by link text
➢ Click_button('button_name') # fill text field
➢ Fill_in('First Name', :with => 'John') # choose radio button
➢ Choose('radio_button') # choose radio button
➢ Check('checkbox') # check in checkbox
➢ Uncheck('checkbox') # uncheck in checkbox
➢ Select('option', :from=>'select_box') # select from dropdown
➢ Attach_file('image', 'path_to_image') # upload file
8. Project Structure :
Features – folder to host all your feature files.
Step_Definitions – folder to host all your step definition Ruby files.
Support – folder to host your configuration files (env.rb).
Gemfile – defines the top-level gems to be used in your project.
9. Sample: simple_search.feature:
– Describes the features that a user will be able to use in the program.
Feature: As a user I should be able to perform simple google search.
Scenario: A simple google search scenario
Given I am on the main google search
When I fill in "q" with "Cucumber test"
And I click "gbqfb" button
And I click on the first result
Then I should see "Cucumber lets software development teams describe
how software should behave in plain text."
10. Given /^I am on the main google search$/ do
visit ('/')
end
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
Then /^I click "([^"]*)" button$/ do |button|
click_button(button)
end
Then /^I click on the first result$/ do
find(:xpath, "//html/body/div[3]/div[2]/div/div[5]/div[2]/div[2]/div/div[2]/div/ol/li/div/h3/a").click
end
Then /^I should see "([^"]*)"$/ do |text|
page.should have_content(text)
end
13. command to run the script :
cucumber features/<name of the feature file>.feature
command to generate the report:
run this command by going to your project directory
cucumber features --format html --out reports