bdd-helper 0.0.4 → 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 +5 -5
- data/lib/bdd-helper.rb +16 -9
- data/lib/demo.feature +172 -0
- data/lib/steps/action/check_steps.rb +19 -0
- data/lib/steps/action/choose_steps.rb +11 -0
- data/lib/steps/action/click_steps.rb +45 -0
- data/lib/steps/action/fill_steps.rb +85 -0
- data/lib/steps/action/key_action_steps.rb +59 -0
- data/lib/steps/action/select_steps.rb +24 -0
- data/lib/steps/assertion/assertion_steps.rb +314 -0
- data/lib/steps/config.rb +18 -3
- data/lib/steps/customized/customized_steps.rb +37 -0
- data/lib/steps/global/global_context.rb +9 -0
- data/lib/steps/util/browser_util_methods.rb +12 -0
- data/lib/steps/util/browser_util_steps.rb +202 -0
- data/lib/steps/util/fill_in_util.rb +11 -0
- metadata +54 -45
- data/lib/steps/assertion.rb +0 -92
- data/lib/steps/browser.rb +0 -35
- data/lib/steps/check.rb +0 -24
- data/lib/steps/click.rb +0 -26
- data/lib/steps/fill.rb +0 -44
- data/lib/steps/select.rb +0 -38
- data/lib/steps/unclassified.rb +0 -19
@@ -0,0 +1,314 @@
|
|
1
|
+
# frozen_string = true
|
2
|
+
begin
|
3
|
+
Then(/^verify "([^"]*)" text is displayed$/) do |text|
|
4
|
+
# E.g : Then verify "Thank you for filling in the form" text is displayed
|
5
|
+
page.should have_text(text, wait: BddHelper.timeout)
|
6
|
+
end
|
7
|
+
|
8
|
+
Then(/^verify "([^"]*)" text is not displayed$/) do |text|
|
9
|
+
# E.g : Then verify "Thank you for filling in the form" text is not displayed
|
10
|
+
page.should_not have_text(text, wait: BddHelper.timeout)
|
11
|
+
end
|
12
|
+
|
13
|
+
Then(/^verify "([^"]*)" element has "([^"]*)" text$/) do |selector, text|
|
14
|
+
"
|
15
|
+
Selector should be a css selector
|
16
|
+
"
|
17
|
+
# E.g : Then verify ".success-message" element has "Welcome" text
|
18
|
+
page.should have_selector(selector, text: text, wait: BddHelper.timeout)
|
19
|
+
end
|
20
|
+
|
21
|
+
Then(/^verify "([^"]*)" element has not "([^"]*)" text$/) do |selector, text|
|
22
|
+
"
|
23
|
+
Selector should be a css selector
|
24
|
+
"
|
25
|
+
# E.g : Then verify ".success-message" element has not "Welcome" text
|
26
|
+
page.should_not have_selector(selector, text: text, wait: BddHelper.timeout)
|
27
|
+
end
|
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
|
+
|
122
|
+
Then(/^verify "([^"]*)" button is displayed$/) do |button|
|
123
|
+
"
|
124
|
+
Button can be id, name, value, or title
|
125
|
+
"
|
126
|
+
# E.g : Then verify "Login" button is displayed
|
127
|
+
page.should have_button(button, wait: BddHelper.timeout)
|
128
|
+
end
|
129
|
+
|
130
|
+
Then(/^verify "([^"]*)" button is not displayed$/) do |button|
|
131
|
+
"
|
132
|
+
Button can be id, name, value, or title
|
133
|
+
"
|
134
|
+
# E.g : Then verify "Login" button is not displayed
|
135
|
+
page.should_not have_button(button, wait: BddHelper.timeout)
|
136
|
+
end
|
137
|
+
|
138
|
+
Then(/^verify "([^"]*)" button is enabled$/) do |button|
|
139
|
+
"
|
140
|
+
Button can be id, name, value, or title
|
141
|
+
"
|
142
|
+
# E.g : Then verify "Login" button is enabled
|
143
|
+
page.should have_button(button, disabled: false, wait: BddHelper.timeout)
|
144
|
+
end
|
145
|
+
|
146
|
+
Then(/^verify "([^"]*)" button is disabled$/) do |button|
|
147
|
+
"
|
148
|
+
Button can be id, name, value, or title
|
149
|
+
"
|
150
|
+
# E.g : Then verify "Login" button is disabled
|
151
|
+
page.should have_button(button, disabled: true, wait: BddHelper.timeout)
|
152
|
+
end
|
153
|
+
|
154
|
+
Then(/^verify current url is "([^"]*)"$/) do |expected_url|
|
155
|
+
"
|
156
|
+
Expected url should be fully URL of the current page
|
157
|
+
"
|
158
|
+
# E.g : Then verify current url is "http:www.example.com"
|
159
|
+
current_url.should == expected_url
|
160
|
+
end
|
161
|
+
|
162
|
+
Then(/^verify current path is "([^"]*)"$/) do |current_path|
|
163
|
+
"
|
164
|
+
Path should be path+query of the current page
|
165
|
+
"
|
166
|
+
# E.g : Then verify current path is "/login"
|
167
|
+
assert_current_path(current_path)
|
168
|
+
end
|
169
|
+
|
170
|
+
Then(/^verify page title is "([^"]*)"$/) do |page_title|
|
171
|
+
"
|
172
|
+
Title should be title of the current page
|
173
|
+
"
|
174
|
+
# E.g : Then verify page title is "Welcome"
|
175
|
+
assert_title(page_title, wait: BddHelper.timeout)
|
176
|
+
end
|
177
|
+
|
178
|
+
Then(/^verify page title contains "([^"]*)"$/) do |text|
|
179
|
+
"
|
180
|
+
Title should be contains of the current page title
|
181
|
+
"
|
182
|
+
# E.g : Then verify page title contains "Welcome"
|
183
|
+
title.should include(text)
|
184
|
+
end
|
185
|
+
|
186
|
+
Then(/^verify below texts are displayed:$/) do |table|
|
187
|
+
# E.g : Then verify below texts are displayed:
|
188
|
+
# | Welcome |
|
189
|
+
# | Thank you |
|
190
|
+
table.raw.each { |raw| page.should have_text(raw[0], wait: BddHelper.timeout) }
|
191
|
+
end
|
192
|
+
|
193
|
+
Then(/^verify below texts are not displayed:$/) do |table|
|
194
|
+
# E.g : Then verify below texts are not displayed:
|
195
|
+
# | Welcome |
|
196
|
+
# | Thank you |
|
197
|
+
table.raw.each { |raw| page.should_not have_text(raw[0], wait: BddHelper.timeout) }
|
198
|
+
end
|
199
|
+
|
200
|
+
Then(/^verify "([^"]*)" alert message is displayed$/) do |text|
|
201
|
+
# E.g : Then verify "Successful" alert message is displayed
|
202
|
+
text.should == page.driver.browser.switch_to.alert.text
|
203
|
+
end
|
204
|
+
|
205
|
+
Then(/^verify "([^"]*)" alert message is not displayed$/) do |text|
|
206
|
+
# E.g : Then verify "Successful" alert message is not displayed
|
207
|
+
text.should_not == page.driver.browser.switch_to.alert.text
|
208
|
+
end
|
209
|
+
|
210
|
+
Then(/^verify "([^"]*)" checkbox is checked$/) do |checkbox|
|
211
|
+
"
|
212
|
+
Checkbox can be name, id and label text
|
213
|
+
"
|
214
|
+
# E.g : Then verify "Terms & Conditions" checkbox is checked
|
215
|
+
expect(page).to have_field(checkbox, checked: true, visible: true, wait: BddHelper.timeout)
|
216
|
+
end
|
217
|
+
|
218
|
+
Then(/^verify "([^"]*)" checkbox is unchecked/) do |checkbox|
|
219
|
+
"
|
220
|
+
Checkbox can be name, id and label text
|
221
|
+
"
|
222
|
+
# E.g : Then verify "Terms & Conditions" checkbox is unchecked
|
223
|
+
expect(page).to have_field(checkbox, checked: false, visible: true, wait: BddHelper.timeout)
|
224
|
+
end
|
225
|
+
|
226
|
+
Then(/^verify "([^"]*)" radio button is selected$/) do |radio_button|
|
227
|
+
"
|
228
|
+
Radio Button can be name, id and label text
|
229
|
+
"
|
230
|
+
# E.g : Then verify "Male" radio button is selected
|
231
|
+
expect(page).to have_field(radio_button, checked: true, visible: true, wait: BddHelper.timeout)
|
232
|
+
end
|
233
|
+
|
234
|
+
Then(/^verify "([^"]*)" radio button is not selected$/) do |radio_button|
|
235
|
+
"
|
236
|
+
Radio Button can be name, id and label text
|
237
|
+
"
|
238
|
+
# E.g : Then verify "Female" radio button is not selected
|
239
|
+
expect(page).to have_field(radio_button, checked: false, visible: true, wait: BddHelper.timeout)
|
240
|
+
end
|
241
|
+
|
242
|
+
Then(/^verify "([^"]*)" dropdown contains "([^"]*)" option$/) do |dropdown, option_text|
|
243
|
+
"
|
244
|
+
Dropdown can be id, name, label
|
245
|
+
"
|
246
|
+
# E.g : Then verify "Country" dropdown contains "United States" option
|
247
|
+
page.should have_select(dropdown, with_options: [option_text], wait: BddHelper.timeout)
|
248
|
+
end
|
249
|
+
|
250
|
+
Then(/^verify "([^"]*)" dropdown does not contain "([^"]*)" option$/) do |dropdown, option_text|
|
251
|
+
"
|
252
|
+
Dropdown can be id, name, label
|
253
|
+
"
|
254
|
+
# E.g : Then verify "Country" dropdown does not contain "United States" option
|
255
|
+
page.should_not have_select(dropdown, with_options: [option_text], wait: BddHelper.timeout)
|
256
|
+
end
|
257
|
+
|
258
|
+
Then(/^verify "([^"]*)" dropdown contains the options below:$/) do |dropdown, table|
|
259
|
+
"
|
260
|
+
Dropdown can be id, name, label
|
261
|
+
"
|
262
|
+
# E.g : Then verify "Country" dropdown contains the options below:
|
263
|
+
# |United States|
|
264
|
+
# |Turkey |
|
265
|
+
table.raw.each { |raw| page.should have_select(dropdown, with_options: [raw[0]], wait: BddHelper.timeout) }
|
266
|
+
end
|
267
|
+
|
268
|
+
Then(/^verify "([^"]*)" dropdown does not contain the options below:$/) do |dropdown, table|
|
269
|
+
"
|
270
|
+
Dropdown can be id, name, label
|
271
|
+
"
|
272
|
+
# E.g : Then verify "Country" dropdown does not contain the options below:
|
273
|
+
# |United States|
|
274
|
+
# |Turkey |
|
275
|
+
table.raw.each { |raw| page.should_not have_select(dropdown, with_options: [raw[0]], wait: BddHelper.timeout) }
|
276
|
+
end
|
277
|
+
|
278
|
+
Then(/^verify "([^"]*)" options is selected from "([^"]*)" dropdown$/) do |option, dropdown|
|
279
|
+
"
|
280
|
+
Dropdown can be id, name, label
|
281
|
+
"
|
282
|
+
# E.g : Then verify "United States" options is selected from "Country" dropdown
|
283
|
+
page.should have_select(dropdown, selected: option, wait: BddHelper.timeout)
|
284
|
+
end
|
285
|
+
|
286
|
+
Then(/^verify "([^"]*)" options is not selected from "([^"]*)" dropdown$/) do |option, dropdown|
|
287
|
+
"
|
288
|
+
Dropdown can be id, name, label
|
289
|
+
"
|
290
|
+
# E.g : Then verify "United States" options is not selected from "Country" dropdown
|
291
|
+
page.should_not have_select(dropdown, selected: option, wait: BddHelper.timeout)
|
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
|
+
|
312
|
+
rescue StandardError => e
|
313
|
+
puts e
|
314
|
+
end
|
data/lib/steps/config.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
-
module
|
1
|
+
module BddHelper
|
2
|
+
class << self
|
3
|
+
attr_accessor :timeout, :base_url
|
2
4
|
|
3
|
-
|
5
|
+
def timeout
|
6
|
+
@timeout || 20
|
7
|
+
end
|
4
8
|
|
5
|
-
|
9
|
+
def base_url
|
10
|
+
unless @base_url.nil? || @base_url.match?(URI::DEFAULT_PARSER.make_regexp)
|
11
|
+
raise ArgumentError, "BddHelper.base_url should be set to a url (http://www.example.com). Attempted to set #{@base_url.inspect}."
|
12
|
+
end
|
13
|
+
@base_url || nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
When(/^hover to "([^"]*)" value "([^"]*)" web element$/) do |web_element_type, web_element|
|
3
|
+
"
|
4
|
+
Web element type can be css, xpath, id, field, link, button, link_or_button or label
|
5
|
+
"
|
6
|
+
# E.g: And hover to "css" value ".list_item" web element
|
7
|
+
find(:"#{web_element_type}".to_sym, web_element).hover
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^wait (\d+) (?:second|seconds)$/) do |sec_value|
|
11
|
+
"
|
12
|
+
Second's value should be integer
|
13
|
+
"
|
14
|
+
# E.g: And wait 2 seconds
|
15
|
+
sleep sec_value.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
And(/^generate (\d+) char random string and type into type "([^"]*)" value "([^"]*)"$/) do |count, web_element_type, web_element|
|
19
|
+
"
|
20
|
+
Web element type can be css, xpath, id, field, fillable_field or label
|
21
|
+
"
|
22
|
+
# E.g: And generate "10" char random string and type into type "id" value "mobile"
|
23
|
+
charset = (0...count).map { rand(65..90).chr }.join
|
24
|
+
find(:"#{web_element_type}".to_sym, web_element, wait: BddHelper.timeout).set(charset)
|
25
|
+
end
|
26
|
+
|
27
|
+
And(/^execute javascript code "([^"]*)"/) do |code|
|
28
|
+
"
|
29
|
+
Code should be javascript code
|
30
|
+
"
|
31
|
+
# E.g : And execute javascript code "window.location.reload()"
|
32
|
+
page.execute_script(code)
|
33
|
+
end
|
34
|
+
|
35
|
+
rescue StandardError => e
|
36
|
+
puts e
|
37
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
begin
|
2
|
+
When(/^scroll (\d+) px (down) the page$/) do |pixel, arg|
|
3
|
+
"
|
4
|
+
This scrolls down the page by the given amount of pixel.
|
5
|
+
"
|
6
|
+
# E.g : And scroll 500 px down the page
|
7
|
+
page.execute_script("window.scrollBy(0,#{pixel})")
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^scroll (\d+) px (up) the page$/) do |pixel, arg|
|
11
|
+
"
|
12
|
+
This scrolls up the page by the given amount of pixel.
|
13
|
+
"
|
14
|
+
# E.g : And scroll 500 px up the page
|
15
|
+
page.execute_script("window.scrollBy(0,#{-pixel})")
|
16
|
+
end
|
17
|
+
|
18
|
+
When(/^scroll (bottom) of the page$/) do |arg|
|
19
|
+
"
|
20
|
+
This scrolls the page to the bottom
|
21
|
+
"
|
22
|
+
# E.g : And scroll bottom of the page
|
23
|
+
page.execute_script('window.scrollTo(0, document.body.scrollHeight)')
|
24
|
+
end
|
25
|
+
|
26
|
+
When(/^scroll (top) of the page$/) do |arg|
|
27
|
+
"
|
28
|
+
This scrolls the page to the top
|
29
|
+
"
|
30
|
+
# E.g : And scroll top of the page
|
31
|
+
page.execute_script('window.scrollTo(document.body.scrollHeight,0)')
|
32
|
+
end
|
33
|
+
|
34
|
+
When(/^focus to element by "([^"]*)" text$/) do |text|
|
35
|
+
# E.g : And focus to element by "Agree Button" text
|
36
|
+
scroll_to(find(xpath: "//*[contains(text(), '#{text}')]"))
|
37
|
+
end
|
38
|
+
|
39
|
+
When(/^refresh the page$/) do
|
40
|
+
"
|
41
|
+
This refreshes the current page
|
42
|
+
"
|
43
|
+
# E.g : And refresh the page
|
44
|
+
page.evaluate_script('window.location.reload()')
|
45
|
+
end
|
46
|
+
|
47
|
+
When(/^open a (new window)$/) do |args|
|
48
|
+
# E.g : And open a new window
|
49
|
+
open_new_window(:window)
|
50
|
+
end
|
51
|
+
|
52
|
+
When(/^open a (new tab)$/) do |args|
|
53
|
+
# E.g : And open a new tab
|
54
|
+
open_new_window
|
55
|
+
end
|
56
|
+
|
57
|
+
When(/^switch to last (?:window|tab)$/) do
|
58
|
+
# E.g : And switch to last window
|
59
|
+
# E.g : And switch to last tab
|
60
|
+
page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
|
61
|
+
end
|
62
|
+
|
63
|
+
When(/^switch to first (?:window|tab)$/) do
|
64
|
+
# E.g : And switch to first window
|
65
|
+
# E.g : And switch to first tab
|
66
|
+
page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
|
67
|
+
end
|
68
|
+
|
69
|
+
When(/^switch to window by "([^"]*)" title$/) do |window_title|
|
70
|
+
"
|
71
|
+
Window title should be title of the target window
|
72
|
+
"
|
73
|
+
# E.g : And switch to window by "Welcome" title
|
74
|
+
switch_to_window { title == window_title }
|
75
|
+
end
|
76
|
+
|
77
|
+
When(/^resize window to (\d+) width (\d+) height$/) do |width, height|
|
78
|
+
"
|
79
|
+
This resize to the current window by the given width and height
|
80
|
+
"
|
81
|
+
# E.g : And resize window to 1280 width 720 height
|
82
|
+
page.driver.browser.manage.window.resize_to(width, height)
|
83
|
+
end
|
84
|
+
|
85
|
+
When(/^get window size$/) do
|
86
|
+
"
|
87
|
+
This gets the current window's size then defines it to the global variable
|
88
|
+
"
|
89
|
+
# E.g : And get window size
|
90
|
+
$window_size = page.driver.browser.manage.window.size
|
91
|
+
end
|
92
|
+
|
93
|
+
When(/^close window$/) do
|
94
|
+
"
|
95
|
+
This closes the current window
|
96
|
+
"
|
97
|
+
# E.g : And close window
|
98
|
+
page.driver.browser.close
|
99
|
+
end
|
100
|
+
|
101
|
+
When(/^get current url$/) do
|
102
|
+
"
|
103
|
+
This get full URL of the current page then defines it to the global variable
|
104
|
+
"
|
105
|
+
# E.g : And get current url
|
106
|
+
$current_url = current_url
|
107
|
+
end
|
108
|
+
|
109
|
+
When(/^go back$/) do
|
110
|
+
"
|
111
|
+
This move back a single entry in the browser's history
|
112
|
+
"
|
113
|
+
# E.g : And go back
|
114
|
+
go_back
|
115
|
+
end
|
116
|
+
|
117
|
+
When(/^go forward$/) do
|
118
|
+
"
|
119
|
+
This move forward a single entry in the browser's history
|
120
|
+
"
|
121
|
+
# E.g : And go forward
|
122
|
+
go_forward
|
123
|
+
end
|
124
|
+
|
125
|
+
When(/^visit base page$/) do
|
126
|
+
"
|
127
|
+
Should configure base_url from bdd-helper config
|
128
|
+
"
|
129
|
+
# E.g : And visit base page
|
130
|
+
visit BddHelper.base_url
|
131
|
+
end
|
132
|
+
|
133
|
+
When(/^visit "([^"]*)" url$/) do |url|
|
134
|
+
"
|
135
|
+
The URL can either be a relative URL or an absolute URL
|
136
|
+
"
|
137
|
+
# E.g : And visit "http://www.example.com" url
|
138
|
+
visit url
|
139
|
+
end
|
140
|
+
|
141
|
+
When(/^visit relative url "([^"]*)"$/) do |url|
|
142
|
+
"
|
143
|
+
The URL can be a relative URL
|
144
|
+
"
|
145
|
+
# E.g : And visit relative url '/login'
|
146
|
+
visit BddHelper.base_url + url
|
147
|
+
end
|
148
|
+
|
149
|
+
When(/^maximize window$/) do
|
150
|
+
"
|
151
|
+
This maximizes the current window
|
152
|
+
"
|
153
|
+
# E.g : And maximize window
|
154
|
+
page.driver.browser.manage.window.maximize
|
155
|
+
end
|
156
|
+
|
157
|
+
When(/^accept alert$/) do
|
158
|
+
# E.g : And accept alert
|
159
|
+
page.driver.browser.switch_to.alert.accept
|
160
|
+
end
|
161
|
+
|
162
|
+
When(/^dismiss alert$/) do
|
163
|
+
# E.g : And dismiss alert
|
164
|
+
page.driver.browser.switch_to.alert.dismiss
|
165
|
+
end
|
166
|
+
|
167
|
+
When(/^get window title$/) do
|
168
|
+
"
|
169
|
+
This gets title of the current page then defines it to the global variable
|
170
|
+
"
|
171
|
+
# E.g : And get window title
|
172
|
+
$page_title = title
|
173
|
+
end
|
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
|
+
|
199
|
+
rescue StandardError => e
|
200
|
+
puts e
|
201
|
+
end
|
202
|
+
|
@@ -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
|