bdd-helper 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bdd-helper.rb +3 -2
- data/lib/demo.feature +34 -3
- data/lib/steps/action/click_steps.rb +8 -0
- data/lib/steps/action/fill_steps.rb +17 -9
- data/lib/steps/action/select_steps.rb +8 -0
- data/lib/steps/assertion/assertion_steps.rb +112 -0
- data/lib/steps/util/browser_util_steps.rb +27 -3
- data/lib/steps/util/fill_in_util.rb +11 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55509be429c7af805db4bb6f2ba8e84a000379b5c50b60515533596271ee7a9f
|
4
|
+
data.tar.gz: fecc456613479d7c1cc70514eb492c26481a6c41491f4a896e22c08c7ae102db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f7376af00c34fef3a1437de882166da25d9e8b2a65e2a476875d288429989ce01a9abb671dd682d76465d70261f468672d64e5a5d1be4aefb061f9208fdd9eb
|
7
|
+
data.tar.gz: 616b8f799f735b10864851fa8bac2e5c3fb0d24a79f70c863d9d58a85956463db21b460bcc35b1e47bc0bcbf6406441fd587a9b3e2a60b4b0bd6b356b5e68569
|
data/lib/bdd-helper.rb
CHANGED
@@ -7,7 +7,6 @@ require 'selenium/webdriver'
|
|
7
7
|
require 'selenium/webdriver/common/wait'
|
8
8
|
require 'faker'
|
9
9
|
|
10
|
-
|
11
10
|
require 'steps/action/check_steps'
|
12
11
|
require 'steps/action/choose_steps'
|
13
12
|
require 'steps/action/click_steps'
|
@@ -18,6 +17,8 @@ require 'steps/assertion/assertion_steps'
|
|
18
17
|
require 'steps/customized/customized_steps'
|
19
18
|
require 'steps/util/browser_util_steps'
|
20
19
|
require 'steps/util/browser_util_methods'
|
20
|
+
require 'steps/util/fill_in_util'
|
21
21
|
require 'steps/config'
|
22
22
|
require 'steps/global/global_context'
|
23
|
-
require 'steps/config'
|
23
|
+
require 'steps/config'
|
24
|
+
|
data/lib/demo.feature
CHANGED
@@ -31,11 +31,15 @@ Feature: demo features
|
|
31
31
|
When switch to first tab
|
32
32
|
When switch to last tab
|
33
33
|
When switch to window by "Welcome" title
|
34
|
+
When switch to iframe by "123" id
|
35
|
+
When switch to parent frame
|
36
|
+
When switch to default content
|
34
37
|
|
35
38
|
When close window
|
36
39
|
When maximize window
|
37
40
|
When get window size
|
38
41
|
When resize window to 123 width 123 height
|
42
|
+
|
39
43
|
# BROWSER UTIL
|
40
44
|
####################################
|
41
45
|
|
@@ -55,6 +59,17 @@ Feature: demo features
|
|
55
59
|
|
56
60
|
Then verify ".success-message" element has "Welcome" text
|
57
61
|
Then verify ".fail-message" element has not "Welcome" text
|
62
|
+
Then verify ".success-message" element contains "Welcome" text
|
63
|
+
Then verify ".success-message" element contains "elcom" text
|
64
|
+
|
65
|
+
Then verify "#select-class-example legend" css element starts with "Select" text
|
66
|
+
Then verify "//*[@id='open-tab-example-div']" xpath element ends with "Tab" text
|
67
|
+
|
68
|
+
Then verify page has 8 occurrences of "[name='cars']" element
|
69
|
+
Then verify page has minimum 1 occurrences of "[name='cars']" element
|
70
|
+
Then verify page has maximum 8 occurrences of "[name='cars']" element
|
71
|
+
Then verify page has between 1 and 7 occurrences of "[name='cars']" element
|
72
|
+
|
58
73
|
|
59
74
|
Then verify "Login" button is displayed
|
60
75
|
Then verify "Sign In " button is not displayed
|
@@ -85,6 +100,17 @@ Feature: demo features
|
|
85
100
|
|
86
101
|
Then verify "audi" options is selected from "cars" dropdown
|
87
102
|
Then verify "audi" options is not selected from "cars" dropdown
|
103
|
+
|
104
|
+
Then verify page has ".login" css element
|
105
|
+
Then verify page has "//*[@class='login']" xpath element
|
106
|
+
Then verify page has not "#checkbox-example-div1" css element
|
107
|
+
Then verify page has not "//*[@id='checkbox-example-div1']" xpath element
|
108
|
+
|
109
|
+
Then verify "#checkbox-example-div" css element has "Checkbox Example" text
|
110
|
+
Then verify "//*[@id='checkbox-example-div']" xpath element has "Checkbox Example" text
|
111
|
+
Then verify "#checkbox-example-div" css element has not "Checkbox Example1" text
|
112
|
+
Then verify "//*[@id='checkbox-example-div']" xpath element has not "Checkbox Example1" text
|
113
|
+
|
88
114
|
# ASSERTION
|
89
115
|
####################################
|
90
116
|
|
@@ -93,19 +119,22 @@ Feature: demo features
|
|
93
119
|
####################################
|
94
120
|
# ACTION
|
95
121
|
When fill "Username" with "value"
|
122
|
+
When fill ".login-form .message" css element with "Thank you"
|
123
|
+
When fill "//div[@class='login-form']//input[@class='message']" xpath element with "Thank you"
|
96
124
|
When fill "First Name" with random first name
|
97
125
|
When fill "Last Name" with random last name
|
98
126
|
When fill "Email" with random email
|
99
127
|
When fill "Phone Number" with random phone number
|
100
128
|
When fill "Address" with random address
|
101
129
|
When fill "Zip Code" with random zip code
|
102
|
-
|
103
130
|
When fill inputs:
|
104
|
-
| username
|
105
|
-
| password
|
131
|
+
| username | test user |
|
132
|
+
| password | pas123 |
|
106
133
|
|
107
134
|
When click "Contact Us" link
|
108
135
|
When click "Sign In" button
|
136
|
+
When click "#bmwradio" css element
|
137
|
+
When click "//*[@id='openwindow']" xpath element
|
109
138
|
|
110
139
|
When check "Terms & Conditions" checkbox
|
111
140
|
When uncheck "Privacy Policy" checkbox
|
@@ -114,6 +143,8 @@ Feature: demo features
|
|
114
143
|
|
115
144
|
When clear "First Name" input
|
116
145
|
When select "audi" from "cars" dropdown
|
146
|
+
When select "Honda" from "#carselect" css element
|
147
|
+
When select "BMW" from "//*[@id='carselect']" xpath element
|
117
148
|
|
118
149
|
When press "#login" enter
|
119
150
|
When press "#username" delete
|
@@ -15,6 +15,14 @@ begin
|
|
15
15
|
click_link(link_id_title_or_text, wait: BddHelper.timeout)
|
16
16
|
end
|
17
17
|
|
18
|
+
When(/^click "([^"]*)" (css|xpath) element$/) do |locator, locator_type|
|
19
|
+
"
|
20
|
+
Locator can be xpath or css.
|
21
|
+
"
|
22
|
+
# E.g. : And click ".login" css element
|
23
|
+
find("#{locator_type}".to_sym, locator).click
|
24
|
+
end
|
25
|
+
|
18
26
|
When(/^click "([^"]*)" under "([^"]*)"$/) do |link, menu|
|
19
27
|
"
|
20
28
|
Finds a element with capybara default_selector, link can be id, text or title
|
@@ -4,7 +4,15 @@ begin
|
|
4
4
|
Fillable field can be name, id, placeholder or label text
|
5
5
|
"
|
6
6
|
# E.g : And fill "Name" with "John"
|
7
|
-
|
7
|
+
FillInUtil.fill_text_field(locator, text)
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^fill "([^"]*)" (css|xpath) element with "([^"]*)"$/) do |locator, locator_type, text|
|
11
|
+
"
|
12
|
+
Fillable field can be css or xpath locator.
|
13
|
+
"
|
14
|
+
# E.g : And fill ".username" css element with "John"
|
15
|
+
find("#{locator_type}".to_sym, locator).set(text)
|
8
16
|
end
|
9
17
|
|
10
18
|
When(/^fill inputs:$/) do |table|
|
@@ -14,7 +22,7 @@ begin
|
|
14
22
|
# E.g : And fill inputs:
|
15
23
|
# | username | test user |
|
16
24
|
# | password | pass123 |
|
17
|
-
table.raw.each { |raw|
|
25
|
+
table.raw.each { |raw| FillInUtil.fill_text_field(raw[0], raw[1]) }
|
18
26
|
end
|
19
27
|
|
20
28
|
When(/^fill "([^"]*)" with random (first name)$/) do |locator, arg|
|
@@ -22,7 +30,7 @@ begin
|
|
22
30
|
Fillable field can be name, id, placeholder or label text
|
23
31
|
"
|
24
32
|
# E.g : And fill "First Name" with random first name
|
25
|
-
|
33
|
+
FillInUtil.fill_text_field(locator, Faker::Name.first_name)
|
26
34
|
end
|
27
35
|
|
28
36
|
When(/^fill "([^"]*)" with random (last name)$/) do |locator, arg|
|
@@ -30,7 +38,7 @@ begin
|
|
30
38
|
Fillable field can be name, id, placeholder or label text
|
31
39
|
"
|
32
40
|
# E.g : And fill "Last Name" with random last name
|
33
|
-
|
41
|
+
FillInUtil.fill_text_field(locator, Faker::Name.last_name)
|
34
42
|
end
|
35
43
|
|
36
44
|
When(/^fill "([^"]*)" with random (email)$/) do |locator, arg|
|
@@ -38,7 +46,7 @@ begin
|
|
38
46
|
Fillable field can be name, id, placeholder or label text
|
39
47
|
"
|
40
48
|
# E.g : And fill "Email" with random email
|
41
|
-
|
49
|
+
FillInUtil.fill_text_field(locator, Faker::Internet.safe_email)
|
42
50
|
end
|
43
51
|
|
44
52
|
When(/^fill "([^"]*)" with random (phone number)$/) do |locator, arg|
|
@@ -46,7 +54,7 @@ begin
|
|
46
54
|
Fillable field can be name, id, placeholder or label text
|
47
55
|
"
|
48
56
|
# E.g : And fill "Phone Number" with random phone number
|
49
|
-
|
57
|
+
FillInUtil.fill_text_field(locator, Array.new(7) { Array(0..9).sample }.join)
|
50
58
|
end
|
51
59
|
|
52
60
|
When(/^fill "([^"]*)" with random (address)$/) do |locator, arg|
|
@@ -54,7 +62,7 @@ begin
|
|
54
62
|
Fillable field can be name, id, placeholder or label text
|
55
63
|
"
|
56
64
|
# E.g : And fill "Address" with random address
|
57
|
-
|
65
|
+
FillInUtil.fill_text_field(locator, Faker::Address.full_address)
|
58
66
|
end
|
59
67
|
|
60
68
|
When(/^fill "([^"]*)" with random (zip code)$/) do |locator, arg|
|
@@ -62,7 +70,7 @@ begin
|
|
62
70
|
Fillable field can be name, id, placeholder or label text
|
63
71
|
"
|
64
72
|
# E.g : And fill "Zip Code" with random zip code
|
65
|
-
|
73
|
+
FillInUtil.fill_text_field(locator, Faker::Address.zip_code)
|
66
74
|
end
|
67
75
|
|
68
76
|
When(/^clear "([^"]*)" input$/) do |locator|
|
@@ -70,7 +78,7 @@ begin
|
|
70
78
|
Fillable field can be name, id, placeholder or label text
|
71
79
|
"
|
72
80
|
# E.g : And clear "Name" input
|
73
|
-
|
81
|
+
FillInUtil.clear_text_field(locator)
|
74
82
|
end
|
75
83
|
rescue StandardError => e
|
76
84
|
puts e
|
@@ -11,6 +11,14 @@ begin
|
|
11
11
|
page.should have_select(dropdown_id_name_or_label_text, selected: option)
|
12
12
|
end
|
13
13
|
|
14
|
+
When(/^select "([^"]*)" from "([^"]*)" (xpath|css) element$/) do |option, dropdown_locator, locator_type|
|
15
|
+
"
|
16
|
+
Option is visible text and the dropdown locator should be css or xpath according to locator type.
|
17
|
+
"
|
18
|
+
# E.g : And select "Honda" from "#carselect" css element
|
19
|
+
find("#{locator_type}".to_sym, dropdown_locator).find(:option, option).select_option
|
20
|
+
end
|
21
|
+
|
14
22
|
rescue StandardError => e
|
15
23
|
puts e
|
16
24
|
end
|
@@ -26,6 +26,99 @@ begin
|
|
26
26
|
page.should_not have_selector(selector, text: text, wait: BddHelper.timeout)
|
27
27
|
end
|
28
28
|
|
29
|
+
Then(/^verify "([^"]*)" element contains "([^"]*)" text$/) do |selector, text|
|
30
|
+
"
|
31
|
+
Selector should be a css selector
|
32
|
+
"
|
33
|
+
# E.g : Then verify ".success-message" element contains "elcom" text
|
34
|
+
page.should have_selector(selector, text: text, exact_text: false, wait: BddHelper.timeout)
|
35
|
+
end
|
36
|
+
|
37
|
+
Then(/^verify "([^"]*)" (css|xpath) element starts with "([^"]*)" text$/) do |selector, selector_type, text|
|
38
|
+
"
|
39
|
+
Selector can be css or xpath.
|
40
|
+
"
|
41
|
+
# E.g : Then verify "#select-class-example legend" css element starts with "Select" text
|
42
|
+
case selector_type
|
43
|
+
when "xpath"
|
44
|
+
find(:xpath, "#{selector}").text.should start_with(text)
|
45
|
+
else #which is css
|
46
|
+
find(:css, "#{selector}").text.should start_with(text)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Then(/^verify "([^"]*)" (css|xpath) element ends with "([^"]*)" text$/) do |selector, selector_type, text|
|
51
|
+
"
|
52
|
+
Selector can be css or xpath.
|
53
|
+
"
|
54
|
+
# E.g : Then verify "//*[@id='open-tab-example-div']" xpath element ends with "Tab" text
|
55
|
+
case selector_type
|
56
|
+
when "xpath"
|
57
|
+
find(:xpath, "#{selector}").text.should end_with(text)
|
58
|
+
else
|
59
|
+
#which is css
|
60
|
+
find(:css, "#{selector}").text.should end_with(text)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Then(/^verify page has (\d+) (?:occurrences|occurrence) of "([^"]*)" element$/) do |number,selector|
|
65
|
+
"
|
66
|
+
Selector should be a css selector
|
67
|
+
"
|
68
|
+
# E.g : Then verify page has 7 occurrences of "[name='cars']" element
|
69
|
+
expect(page).to have_selector(selector, visible: true, count: number, wait: BddHelper.timeout)
|
70
|
+
end
|
71
|
+
|
72
|
+
Then(/^verify page has minimum (\d+) (?:occurrences|occurrence) of "([^"]*)" element$/) do |number, selector|
|
73
|
+
"
|
74
|
+
Selector should be a css selector
|
75
|
+
"
|
76
|
+
# E.g : Then verify page has minimum 1 occurrence of "[name='cars']" element
|
77
|
+
page.assert_selector(selector, minimum: number, wait: BddHelper.timeout)
|
78
|
+
end
|
79
|
+
|
80
|
+
Then(/^verify page has maximum (\d+) (?:occurrences|occurrence) of "([^"]*)" element$/) do |number, selector|
|
81
|
+
"
|
82
|
+
Selector should be a css selector
|
83
|
+
"
|
84
|
+
# E.g : Then verify page has maximum 8 occurrences of "[name='cars']" element
|
85
|
+
page.assert_selector(selector, maximum: number, wait: BddHelper.timeout)
|
86
|
+
end
|
87
|
+
|
88
|
+
Then(/^verify page has between (\d+) and (\d+) occurrences of "([^"]*)" element$/) do |minimum, maximum, selector|
|
89
|
+
"
|
90
|
+
Selector should be a css selector
|
91
|
+
"
|
92
|
+
# E.g : Then verify page has between 1 and 7 occurrences of "[name='cars']" element
|
93
|
+
page.assert_selector(selector, between: minimum..maximum, wait: BddHelper.timeout)
|
94
|
+
end
|
95
|
+
|
96
|
+
Then(/^verify "([^"]*)" (css|xpath) element has "([^"]*)" text$/) do |selector, selector_type, text|
|
97
|
+
"
|
98
|
+
Selector can be xpath or css.
|
99
|
+
"
|
100
|
+
# E.g : Then verify ".success-message" css element has "Welcome" text
|
101
|
+
case selector_type
|
102
|
+
when "xpath"
|
103
|
+
page.should have_xpath(selector, text: text)
|
104
|
+
else #which is css
|
105
|
+
page.should have_css(selector, text: text)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
Then(/^verify "([^"]*)" (css|xpath) element has not "([^"]*)" text$/) do |selector, selector_type, text|
|
110
|
+
"
|
111
|
+
Selector can be xpath or css.
|
112
|
+
"
|
113
|
+
# E.g : Then verify ".success-message" css element has not "Welcome" text
|
114
|
+
case selector_type
|
115
|
+
when "xpath"
|
116
|
+
find(:xpath,"#{selector}").text.should_not == text
|
117
|
+
else #which is css
|
118
|
+
find(:css,"#{selector}").text.should_not == text
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
29
122
|
Then(/^verify "([^"]*)" button is displayed$/) do |button|
|
30
123
|
"
|
31
124
|
Button can be id, name, value, or title
|
@@ -197,6 +290,25 @@ begin
|
|
197
290
|
# E.g : Then verify "United States" options is not selected from "Country" dropdown
|
198
291
|
page.should_not have_select(dropdown, selected: option, wait: BddHelper.timeout)
|
199
292
|
end
|
293
|
+
|
294
|
+
Then(/^verify page has "([^"]*)" (css|xpath) element$/) do |locator, locator_type|
|
295
|
+
"
|
296
|
+
Locator type can be 'css' or 'xpath'.
|
297
|
+
Then the locator should be given correspondingly.
|
298
|
+
"
|
299
|
+
#E.g. : Then verify page has ".class" css element
|
300
|
+
page.assert_selector("#{locator_type}".to_sym, locator, wait: BddHelper.timeout)
|
301
|
+
end
|
302
|
+
|
303
|
+
Then(/^verify page has not "([^"]*)" (css|xpath) element$/) do |locator, locator_type|
|
304
|
+
"
|
305
|
+
Locator type can be 'css' or 'xpath'.
|
306
|
+
Then the locator should be given correspondingly.
|
307
|
+
"
|
308
|
+
#E.g. : Then verify page has not ".class" css element
|
309
|
+
page.should_not have_selector("#{locator_type}".to_sym, locator, wait: BddHelper.timeout)
|
310
|
+
end
|
311
|
+
|
200
312
|
rescue StandardError => e
|
201
313
|
puts e
|
202
314
|
end
|
@@ -54,13 +54,13 @@ begin
|
|
54
54
|
open_new_window
|
55
55
|
end
|
56
56
|
|
57
|
-
When(/^switch to
|
57
|
+
When(/^switch to last (?:window|tab)$/) do
|
58
58
|
# E.g : And switch to last window
|
59
59
|
# E.g : And switch to last tab
|
60
60
|
page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
|
61
61
|
end
|
62
62
|
|
63
|
-
When(/^switch to
|
63
|
+
When(/^switch to first (?:window|tab)$/) do
|
64
64
|
# E.g : And switch to first window
|
65
65
|
# E.g : And switch to first tab
|
66
66
|
page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
|
@@ -166,12 +166,36 @@ begin
|
|
166
166
|
|
167
167
|
When(/^get window title$/) do
|
168
168
|
"
|
169
|
-
|
169
|
+
This gets title of the current page then defines it to the global variable
|
170
170
|
"
|
171
171
|
# E.g : And get window title
|
172
172
|
$page_title = title
|
173
173
|
end
|
174
174
|
|
175
|
+
When(/^switch to iframe by "([^"]*)" id$/) do |web_element|
|
176
|
+
"
|
177
|
+
Switches to the iframe with id.
|
178
|
+
"
|
179
|
+
#E.g. : And switch to iframe by "myIframe" id
|
180
|
+
page.driver.browser.switch_to.frame(web_element)
|
181
|
+
end
|
182
|
+
|
183
|
+
When(/^switch to parent frame$/) do
|
184
|
+
"
|
185
|
+
Switches to the parent frame.
|
186
|
+
"
|
187
|
+
#E.g. : And switch to parent frame
|
188
|
+
page.driver.browser.switch_to.parent_frame
|
189
|
+
end
|
190
|
+
|
191
|
+
When(/^switch to default content$/) do
|
192
|
+
"
|
193
|
+
Switches back to default content.
|
194
|
+
"
|
195
|
+
#E.g. : And switch to default content
|
196
|
+
switch_to_frame(:top)
|
197
|
+
end
|
198
|
+
|
175
199
|
rescue StandardError => e
|
176
200
|
puts e
|
177
201
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class FillInUtil
|
2
|
+
|
3
|
+
def self.clear_text_field(locator)
|
4
|
+
fill_in(locator, with: '', fill_options: { clear: :backspace }, wait: BddHelper.timeout)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.fill_text_field(locator, text)
|
8
|
+
clear_text_field(locator)
|
9
|
+
fill_in(locator, with: text, wait: BddHelper.timeout)
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bdd-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kloia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/steps/global/global_context.rb
|
107
107
|
- lib/steps/util/browser_util_methods.rb
|
108
108
|
- lib/steps/util/browser_util_steps.rb
|
109
|
+
- lib/steps/util/fill_in_util.rb
|
109
110
|
homepage: https://github.com/kloia/bdd-helper
|
110
111
|
licenses:
|
111
112
|
- MIT
|
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
128
|
- !ruby/object:Gem::Version
|
128
129
|
version: '0'
|
129
130
|
requirements: []
|
130
|
-
rubygems_version: 3.2.
|
131
|
+
rubygems_version: 3.2.32
|
131
132
|
signing_key:
|
132
133
|
specification_version: 4
|
133
134
|
summary: Helper steps for client-based automation testing
|