095-自动化测试框架Cucumber
BDD
Behavior Driven Development
1.Describes overall behaviors of the system
2.customer focused
ATDD
Acceptance Test Driven Development
1.Defines tests which act as requirements for the system
2.Development focused
Gherkin
1.Gherkin is the language Cucumber uses to define test cases
2.Non-technical
3.Human readable
4.Helps enforce firm, unambiguous requirements
Keywords
Given ...
And ...
When ...
And ...
Then ...
Cucumber
1.Open source tool for test automation
2.Tests are written in Gherkin
3.Uses regular expressions to match Gherkin to a cucumber step
4.Cucumber step is what wraps the automation code
5.Cucumber has implementations in :
Ruby,Java,Javascript...
举例Example
Feature: The create account page should have verification on all the fields
Scenario: Error message should become visible when I try to submit the account creation form without a name
Given I am on the site homepage
When I click on "sign in link" on the "Home" page
And I click on "register" on the "Sign In" page
...
Then the "missing name error" on the "Create Account" page should be visible
What is Gherkin?
Real World Example
Given I am on the homepage
When I login as "gherkin_test"
And I navigate to the "My Account" page
And I click on the "My Lists" element on the "My Account" Page
Then I should be on the "My Lists" page
Gherkin:
Scenario Outline
Scenario will run as a unique scenario for each line in it's examples table
Gherkin:
Scenario Outline
Feature: Amazon create account page should have verification on all the fields
Scenario Outline: All of the fields should display an error when not populated on form submission
And I click on "submit" on the "Create Account" Page
Then the "
Examples:
| error
| missing name error
| missing email error
Feature: Amazon create account page should have verification on all the fields
Scenario Outline: All of the fields should display an error when not populated on form submission
Given I am using the "
And I click on "submit" on the "Create Account" Page
Then the "
Examples:
|user_data|error |
|user1 |missing name error |
|user2 |missing email error |
|user3 |missing password error |
Gherkin:
Steps Table
Scenario outlines
Example Table---Loop full scenario for each row
Step Table---All data is used in at once
Gherkin:
Steps Table
Feature: Amazon search results should contain all required data
Scenario Outline: Description of scenario outline
Given I am on the site homepage
When search for "
Then each result should have the following information:
| information | data_type |
| title | string |
| price | currency |
Examples:
| search_string |
| cucumber book |
| java book |
Gherkin:
Background
Feature: Insert detailed description here
Background: Insert background description here
Given I sign in as "user1"
Scenario: Examples 1
When I click on "My Account" on the "Home" Page
Then I should be on the "My Account" Page
Scenario: Example 2
When I click on "Log out" on the "Home" Page
Then I should be on the "Login" Page