-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cucumber.txt
147 lines (100 loc) · 3.35 KB
/
Cucumber.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Cucumber
---------------------------------
Install:
group :test, :development do
gem 'cucumber-rails', :require => false
# database_cleaner is not required, but highly recommended
gem 'database_cleaner'
end
bundle install
rails generate cucumber:install
---------------------------------
Run:
rake cucumber
cucumber >> runs all
cucumber --tags @tag_name >> only runs scenarios tagged with @tag_name
-----------------------------------
Writing test cases in Cucumber
2 types of files: Feature and Test Definitions
root/features/<feature>/feature.feature
features/step_definitions/steps.rb
Features can be in root features directory or grouped into subfolders based on object/action
To keep it DRY:
Use a Page Object Pattern should be mapped to a Ruby class file,
and each method within the class represents a page object on the page.
Expect:
The rspec-expectations library is bundled with many built-in matchers for testing validation.
Each of the matchers can be used with expect(..).to or expect(..).not_to to define positive
and negative expectations respectively on an object under test.
===========================================
Plain English (.feature file)
Feature: <feature title>
As a <persona|role>
I want to <action>
So that <outcome>
EX:
Feature: Refund item
Sales assistants should be able to refund customers' purchases.
This is required by the law, and is also essential in order to
keep customers happy.
Rules:
- Customer must present proof of purchase
- Purchase must be less than 30 days ago
Scenario: Jeff returns a faulty microwave
Given Jeff has bought a microwave for $100
And he has a receipt
When he returns the microwave
Then Jeff should be refunded $100
--------------------------------------
Keywords:
Feature
Scenario == example of business rule with steps
Given, When, Then, And, But == steps
Background == Used to gather repeated steps into group (given, and, etc)
Scenario Outline == complex business rule with variable i/o values <value>
Examples == table of example values used with scenario outline
""" (Doc Strings)
| (Data Tables)
@ (Tags)
# (Comments)
EX:
Scenario Outline: feeding a suckler cow
Given the cow weighs <weight> kg
When we calculate the feeding requirements
Then the energy should be <energy> MJ
And the protein should be <protein> kg
Examples:
| weight | energy | protein |
| 450 | 26500 | 215 |
| 500 | 29500 | 245 |
| 575 | 31500 | 255 |
| 600 | 37000 | 305 |
--------------------------------------
ONLY 3-5 steps per scenario!
Scenario: User logs in
Given I am on the homepage
When I log in
Then I should see a login notification
===========================================
Ruby
For each scenario, list execution step-by-step in Ruby:
Takes the string after a keyword and defines an action to perform
EX:
Feature: Welcome Message
When(/^I go to the homepage$/) do
visit root_path
end
Then(/^I should see the welcome message$/) do
expect(page).to have_content("Hello Cucumber")
end
--------------------------------------
JavaScript
You can also check javascript execution, as JavaScript is /not run/ by Cucumber
without the @javascript tag
EX:
Feature: Link Click
@javascript
Scenario: User clicks the link
Given I am on the homepage
When I click the provided link
Then I should see the link click confirmation