bdd-helper 0.0.1 → 1.0
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 +23 -5
- data/lib/demo.feature +141 -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 +37 -0
- data/lib/steps/action/fill_steps.rb +77 -0
- data/lib/steps/action/key_action_steps.rb +59 -0
- data/lib/steps/action/select_steps.rb +16 -0
- data/lib/steps/assertion/assertion_steps.rb +202 -0
- data/lib/steps/config.rb +20 -0
- 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 +178 -0
- metadata +100 -21
- data/lib/step_definitions/assertion.rb +0 -93
- data/lib/step_definitions/browser.rb +0 -48
- data/lib/step_definitions/check.rb +0 -22
- data/lib/step_definitions/click.rb +0 -29
- data/lib/step_definitions/env.rb +0 -12
- data/lib/step_definitions/fill.rb +0 -56
- data/lib/step_definitions/select.rb +0 -40
- data/lib/step_definitions/unclassified.rb +0 -19
- data/lib/support/config.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7a2f6404fb5d8c81b9e9537f34038036725ee9f8081cc336b6656efb23d14418
|
4
|
+
data.tar.gz: c219637921c7e57893839c417ee330a3dae119bc2363c518ca3cfe9373d842ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f03a9b36f0e1e47104df4672db7295f24a66832c184478468cf3f15bcc66a9daaf0d44e5f89227e4187df7215f1dbed5f30ca2671bbc1704afbb5a134d44de7
|
7
|
+
data.tar.gz: 9739cee85ca0997bafa0e52ddd0da7c111bbbc7a894e608ba267f80c90448d91a1aa9f2d1ea8b6174752a4be38741a5f17b779656026e5f59f74913d8ac690b3
|
data/lib/bdd-helper.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'capybara'
|
2
|
+
require 'capybara/rspec'
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec/expectations'
|
5
|
+
require 'rspec/matchers'
|
6
|
+
require 'selenium/webdriver'
|
7
|
+
require 'selenium/webdriver/common/wait'
|
8
|
+
require 'faker'
|
9
|
+
|
10
|
+
|
11
|
+
require 'steps/action/check_steps'
|
12
|
+
require 'steps/action/choose_steps'
|
13
|
+
require 'steps/action/click_steps'
|
14
|
+
require 'steps/action/fill_steps'
|
15
|
+
require 'steps/action/key_action_steps'
|
16
|
+
require 'steps/action/select_steps'
|
17
|
+
require 'steps/assertion/assertion_steps'
|
18
|
+
require 'steps/customized/customized_steps'
|
19
|
+
require 'steps/util/browser_util_steps'
|
20
|
+
require 'steps/util/browser_util_methods'
|
21
|
+
require 'steps/config'
|
22
|
+
require 'steps/global/global_context'
|
23
|
+
require 'steps/config'
|
data/lib/demo.feature
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
Feature: demo features
|
2
|
+
|
3
|
+
|
4
|
+
Scenario: steps
|
5
|
+
####################################
|
6
|
+
# BROWSER UTIL
|
7
|
+
When visit base page
|
8
|
+
When visit "http://www.example.com" url
|
9
|
+
When get current url
|
10
|
+
When get window title
|
11
|
+
|
12
|
+
When scroll top of the page
|
13
|
+
When scroll bottom of the page
|
14
|
+
When scroll 250 px up the page
|
15
|
+
When scroll 250 px down the page
|
16
|
+
|
17
|
+
When focus to element by "Agree Button" text
|
18
|
+
|
19
|
+
When go back
|
20
|
+
When go forward
|
21
|
+
When refresh the page
|
22
|
+
|
23
|
+
When accept alert
|
24
|
+
When dismiss alert
|
25
|
+
|
26
|
+
When open a new window
|
27
|
+
When switch to first window
|
28
|
+
When switch to last window
|
29
|
+
When switch to first window
|
30
|
+
When open a new tab
|
31
|
+
When switch to first tab
|
32
|
+
When switch to last tab
|
33
|
+
When switch to window by "Welcome" title
|
34
|
+
|
35
|
+
When close window
|
36
|
+
When maximize window
|
37
|
+
When get window size
|
38
|
+
When resize window to 123 width 123 height
|
39
|
+
# BROWSER UTIL
|
40
|
+
####################################
|
41
|
+
|
42
|
+
########################################################################
|
43
|
+
|
44
|
+
####################################
|
45
|
+
# ASSERTION
|
46
|
+
Then verify below texts are displayed:
|
47
|
+
| Welcome |
|
48
|
+
| Thank you |
|
49
|
+
Then verify below texts are not displayed:
|
50
|
+
| Welcome |
|
51
|
+
| Thank you |
|
52
|
+
Then verify "text" text is displayed
|
53
|
+
Then verify "text" text is not displayed
|
54
|
+
|
55
|
+
|
56
|
+
Then verify ".success-message" element has "Welcome" text
|
57
|
+
Then verify ".fail-message" element has not "Welcome" text
|
58
|
+
|
59
|
+
Then verify "Login" button is displayed
|
60
|
+
Then verify "Sign In " button is not displayed
|
61
|
+
|
62
|
+
Then verify "Login" button is enabled
|
63
|
+
Then verify "Logout" button is disabled
|
64
|
+
|
65
|
+
Then verify current url is "http:www.example.com"
|
66
|
+
Then verify current path is "/login"
|
67
|
+
|
68
|
+
Then verify page title is "Welcome"
|
69
|
+
Then verify page title contains "Welcome"
|
70
|
+
|
71
|
+
Then verify "Successful Login" alert message is displayed
|
72
|
+
Then verify "Incorrect login or password." alert message is not displayed
|
73
|
+
|
74
|
+
|
75
|
+
Then verify "Terms & Conditions" checkbox is checked
|
76
|
+
Then verify "Terms & Conditions" checkbox is unchecked
|
77
|
+
|
78
|
+
Then verify "Male" radio button is selected
|
79
|
+
Then verify "Female" radio button is not selected
|
80
|
+
Then verify "cars" dropdown contains "audi" option
|
81
|
+
Then verify "cars" dropdown does not contain "audi" option
|
82
|
+
Then verify "cars" dropdown contains the options below:
|
83
|
+
| au |
|
84
|
+
| bm |
|
85
|
+
|
86
|
+
Then verify "audi" options is selected from "cars" dropdown
|
87
|
+
Then verify "audi" options is not selected from "cars" dropdown
|
88
|
+
# ASSERTION
|
89
|
+
####################################
|
90
|
+
|
91
|
+
########################################################################
|
92
|
+
|
93
|
+
####################################
|
94
|
+
# ACTION
|
95
|
+
When fill "Username" with "value"
|
96
|
+
When fill "First Name" with random first name
|
97
|
+
When fill "Last Name" with random last name
|
98
|
+
When fill "Email" with random email
|
99
|
+
When fill "Phone Number" with random phone number
|
100
|
+
When fill "Address" with random address
|
101
|
+
When fill "Zip Code" with random zip code
|
102
|
+
|
103
|
+
When fill inputs:
|
104
|
+
| username | test user |
|
105
|
+
| password | pas123 |
|
106
|
+
|
107
|
+
When click "Contact Us" link
|
108
|
+
When click "Sign In" button
|
109
|
+
|
110
|
+
When check "Terms & Conditions" checkbox
|
111
|
+
When uncheck "Privacy Policy" checkbox
|
112
|
+
|
113
|
+
When choose "Male" radio button
|
114
|
+
|
115
|
+
When clear "First Name" input
|
116
|
+
When select "audi" from "cars" dropdown
|
117
|
+
|
118
|
+
When press "#login" enter
|
119
|
+
When press "#username" delete
|
120
|
+
When press ".list-selector" down
|
121
|
+
When press ".list-selector" up
|
122
|
+
When press ".list-selector" left
|
123
|
+
When press ".list-selector" right
|
124
|
+
|
125
|
+
When click "Logout" under ".account-menu"
|
126
|
+
When click "Logout" item 0 under ".account-menu" menu item 0
|
127
|
+
|
128
|
+
When hover over "Account"
|
129
|
+
# ACTION
|
130
|
+
####################################
|
131
|
+
|
132
|
+
########################################################################
|
133
|
+
|
134
|
+
####################################
|
135
|
+
# CUSTOMIZED
|
136
|
+
When hover to "css" value ".list_item" web element
|
137
|
+
When wait 2 seconds
|
138
|
+
When generate 10 char random string and type into type "css" value ".username"
|
139
|
+
When execute javascript code "window.location.reload()"
|
140
|
+
# CUSTOMIZED
|
141
|
+
####################################
|
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
When(/^check "([^"]*)" checkbox$/) do |checkbox_name_id_or_label|
|
3
|
+
"
|
4
|
+
Checkbox can be name, id and label text
|
5
|
+
"
|
6
|
+
# E.g : And check "Terms & Conditions" checkbox
|
7
|
+
check(checkbox_name_id_or_label, wait: BddHelper.timeout)
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^uncheck "([^"]*)" checkbox$/) do |checkbox_name_id_or_label|
|
11
|
+
"
|
12
|
+
Checkbox can be name, id and label text
|
13
|
+
"
|
14
|
+
# E.g : And uncheck "Privacy Policy" checkbox
|
15
|
+
uncheck(checkbox_name_id_or_label, wait: BddHelper.timeout)
|
16
|
+
end
|
17
|
+
rescue StandardError => e
|
18
|
+
puts e
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
begin
|
2
|
+
When(/^choose "([^"]*)" radio button$/) do |radio_button_id_name_or_label|
|
3
|
+
"
|
4
|
+
Radio Button can be name, id and label text
|
5
|
+
"
|
6
|
+
# E.g : And choose "Male" radio button
|
7
|
+
choose(radio_button_id_name_or_label, wait: BddHelper.timeout)
|
8
|
+
end
|
9
|
+
rescue StandardError => e
|
10
|
+
puts e
|
11
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
When(/^click "([^"]*)" button$/) do |button_id_title_or_text|
|
3
|
+
"
|
4
|
+
Button can be name, id, value or title
|
5
|
+
"
|
6
|
+
# E.g : And click "Sign In" button
|
7
|
+
click_button(button_id_title_or_text, wait: BddHelper.timeout)
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^click "([^"]*)" link$/) do |link_id_title_or_text|
|
11
|
+
"
|
12
|
+
Link can be id, text or title
|
13
|
+
"
|
14
|
+
# E.g : And click "Contact Us" link
|
15
|
+
click_link(link_id_title_or_text, wait: BddHelper.timeout)
|
16
|
+
end
|
17
|
+
|
18
|
+
When(/^click "([^"]*)" under "([^"]*)"$/) do |link, menu|
|
19
|
+
"
|
20
|
+
Finds a element with capybara default_selector, link can be id, text or title
|
21
|
+
"
|
22
|
+
# E.g : And click "Logout" under ".account-menu"
|
23
|
+
find(menu, wait: BddHelper.timeout).hover
|
24
|
+
click_link(link, wait: BddHelper.timeout)
|
25
|
+
end
|
26
|
+
|
27
|
+
When(/^click "([^"]*)" item (\d+) under "([^"]*)" menu item (\d+)$/) do |link, link_item, menu, menu_item|
|
28
|
+
"
|
29
|
+
Link can be id, text or title, menu can be text content
|
30
|
+
"
|
31
|
+
# E.g : And click "Logout" item 2 under "Account" menu item 1
|
32
|
+
(page.all(:xpath, "//*[text()='#{menu}']", wait: BddHelper.timeout)[menu_item]).hover
|
33
|
+
(page.all(:link, link, wait: BddHelper.timeout)[link_item]).click
|
34
|
+
end
|
35
|
+
rescue StandardError => e
|
36
|
+
puts e
|
37
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
begin
|
2
|
+
When(/^fill "([^"]*)" with "([^"]*)"$/) do |locator, text|
|
3
|
+
"
|
4
|
+
Fillable field can be name, id, placeholder or label text
|
5
|
+
"
|
6
|
+
# E.g : And fill "Name" with "John"
|
7
|
+
fill_in(locator, with: text, wait: BddHelper.timeout)
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^fill inputs:$/) do |table|
|
11
|
+
"
|
12
|
+
Fillable field can be name, id, placeholder or label text
|
13
|
+
"
|
14
|
+
# E.g : And fill inputs:
|
15
|
+
# | username | test user |
|
16
|
+
# | password | pass123 |
|
17
|
+
table.raw.each { |raw| fill_in(raw[0], with: raw[1], wait: BddHelper.timeout) }
|
18
|
+
end
|
19
|
+
|
20
|
+
When(/^fill "([^"]*)" with random (first name)$/) do |locator, arg|
|
21
|
+
"
|
22
|
+
Fillable field can be name, id, placeholder or label text
|
23
|
+
"
|
24
|
+
# E.g : And fill "First Name" with random first name
|
25
|
+
fill_in(locator, with: Faker::Name.first_name, wait: BddHelper.timeout)
|
26
|
+
end
|
27
|
+
|
28
|
+
When(/^fill "([^"]*)" with random (last name)$/) do |locator, arg|
|
29
|
+
"
|
30
|
+
Fillable field can be name, id, placeholder or label text
|
31
|
+
"
|
32
|
+
# E.g : And fill "Last Name" with random last name
|
33
|
+
fill_in(locator, with: Faker::Name.last_name, wait: BddHelper.timeout)
|
34
|
+
end
|
35
|
+
|
36
|
+
When(/^fill "([^"]*)" with random (email)$/) do |locator, arg|
|
37
|
+
"
|
38
|
+
Fillable field can be name, id, placeholder or label text
|
39
|
+
"
|
40
|
+
# E.g : And fill "Email" with random email
|
41
|
+
fill_in(locator, with: Faker::Internet.safe_email, wait: BddHelper.timeout)
|
42
|
+
end
|
43
|
+
|
44
|
+
When(/^fill "([^"]*)" with random (phone number)$/) do |locator, arg|
|
45
|
+
"
|
46
|
+
Fillable field can be name, id, placeholder or label text
|
47
|
+
"
|
48
|
+
# E.g : And fill "Phone Number" with random phone number
|
49
|
+
fill_in(locator, with: Array.new(7) { Array(0..9).sample }.join, wait: BddHelper.timeout)
|
50
|
+
end
|
51
|
+
|
52
|
+
When(/^fill "([^"]*)" with random (address)$/) do |locator, arg|
|
53
|
+
"
|
54
|
+
Fillable field can be name, id, placeholder or label text
|
55
|
+
"
|
56
|
+
# E.g : And fill "Address" with random address
|
57
|
+
fill_in(locator, with: Faker::Address.full_address, wait: BddHelper.timeout)
|
58
|
+
end
|
59
|
+
|
60
|
+
When(/^fill "([^"]*)" with random (zip code)$/) do |locator, arg|
|
61
|
+
"
|
62
|
+
Fillable field can be name, id, placeholder or label text
|
63
|
+
"
|
64
|
+
# E.g : And fill "Zip Code" with random zip code
|
65
|
+
fill_in(locator, with: Faker::Address.zip_code, wait: BddHelper.timeout)
|
66
|
+
end
|
67
|
+
|
68
|
+
When(/^clear "([^"]*)" input$/) do |locator|
|
69
|
+
"
|
70
|
+
Fillable field can be name, id, placeholder or label text
|
71
|
+
"
|
72
|
+
# E.g : And clear "Name" input
|
73
|
+
fill_in(locator, with: '', fill_options: { clear: :backspace }, wait: BddHelper.timeout)
|
74
|
+
end
|
75
|
+
rescue StandardError => e
|
76
|
+
puts e
|
77
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
begin
|
2
|
+
When(/^press "([^"]*)" (enter)$/) do |locator, arg|
|
3
|
+
"
|
4
|
+
Locator should be capybara default_selector
|
5
|
+
"
|
6
|
+
# E.g : And press "#login" enter
|
7
|
+
find(locator, wait: BddHelper.timeout).native.send_keys(:return)
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^press "([^"]*)" (down)$/) do |locator, arg|
|
11
|
+
"
|
12
|
+
Locator should be capybara default_selector
|
13
|
+
"
|
14
|
+
# E.g : And press ".list-selector" down
|
15
|
+
find(locator, wait: BddHelper.timeout).native.send_keys(:down)
|
16
|
+
end
|
17
|
+
|
18
|
+
When(/^press "([^"]*)" (up)$/) do |locator, arg|
|
19
|
+
"
|
20
|
+
Locator should be capybara default_selector
|
21
|
+
"
|
22
|
+
# E.g : And press ".list-selector" up
|
23
|
+
find(locator, wait: BddHelper.timeout).native.send_keys(:up)
|
24
|
+
end
|
25
|
+
|
26
|
+
When(/^press "([^"]*)" (delete)$/) do |locator, arg|
|
27
|
+
"
|
28
|
+
Locator should be capybara default_selector
|
29
|
+
"
|
30
|
+
# E.g : And press "#username" delete
|
31
|
+
find(locator, wait: BddHelper.timeout).native.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
When(/^press "([^"]*)" (left)$/) do |locator, arg|
|
35
|
+
"
|
36
|
+
Locator should be capybara default_selector
|
37
|
+
"
|
38
|
+
# E.g : And press ".list-selector" left
|
39
|
+
find(locator, wait: BddHelper.timeout).native.send_keys(:left)
|
40
|
+
end
|
41
|
+
|
42
|
+
When(/^press "([^"]*)" (right)$/) do |locator, arg|
|
43
|
+
"
|
44
|
+
Locator should be capybara default_selector
|
45
|
+
"
|
46
|
+
# E.g : And press ".list-selector" right
|
47
|
+
find(locator, wait: BddHelper.timeout).native.send_keys(:right)
|
48
|
+
end
|
49
|
+
|
50
|
+
When(/^hover over "([^"]*)"$/) do |text|
|
51
|
+
# E.g : And hover over "Account"
|
52
|
+
find(:xpath, "//*[text()='#{text}']", wait: BddHelper.timeout).hover
|
53
|
+
end
|
54
|
+
|
55
|
+
rescue StandardError => e
|
56
|
+
puts e
|
57
|
+
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
When(/^select "([^"]*)" from "([^"]*)" dropdown$/) do |option, dropdown_id_name_or_label_text|
|
3
|
+
"
|
4
|
+
Dropdown can be id, name, label
|
5
|
+
"
|
6
|
+
# E.g : And select "United States" from "Country" dropdown
|
7
|
+
unless has_select?(dropdown_id_name_or_label_text)
|
8
|
+
raise "#{dropdown_id_name_or_label_text} is not a select box."
|
9
|
+
end
|
10
|
+
select(option, from: dropdown_id_name_or_label_text, wait: BddHelper.timeout)
|
11
|
+
page.should have_select(dropdown_id_name_or_label_text, selected: option)
|
12
|
+
end
|
13
|
+
|
14
|
+
rescue StandardError => e
|
15
|
+
puts e
|
16
|
+
end
|
@@ -0,0 +1,202 @@
|
|
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 "([^"]*)" button is displayed$/) do |button|
|
30
|
+
"
|
31
|
+
Button can be id, name, value, or title
|
32
|
+
"
|
33
|
+
# E.g : Then verify "Login" button is displayed
|
34
|
+
page.should have_button(button, wait: BddHelper.timeout)
|
35
|
+
end
|
36
|
+
|
37
|
+
Then(/^verify "([^"]*)" button is not displayed$/) do |button|
|
38
|
+
"
|
39
|
+
Button can be id, name, value, or title
|
40
|
+
"
|
41
|
+
# E.g : Then verify "Login" button is not displayed
|
42
|
+
page.should_not have_button(button, wait: BddHelper.timeout)
|
43
|
+
end
|
44
|
+
|
45
|
+
Then(/^verify "([^"]*)" button is enabled$/) do |button|
|
46
|
+
"
|
47
|
+
Button can be id, name, value, or title
|
48
|
+
"
|
49
|
+
# E.g : Then verify "Login" button is enabled
|
50
|
+
page.should have_button(button, disabled: false, wait: BddHelper.timeout)
|
51
|
+
end
|
52
|
+
|
53
|
+
Then(/^verify "([^"]*)" button is disabled$/) do |button|
|
54
|
+
"
|
55
|
+
Button can be id, name, value, or title
|
56
|
+
"
|
57
|
+
# E.g : Then verify "Login" button is disabled
|
58
|
+
page.should have_button(button, disabled: true, wait: BddHelper.timeout)
|
59
|
+
end
|
60
|
+
|
61
|
+
Then(/^verify current url is "([^"]*)"$/) do |expected_url|
|
62
|
+
"
|
63
|
+
Expected url should be fully URL of the current page
|
64
|
+
"
|
65
|
+
# E.g : Then verify current url is "http:www.example.com"
|
66
|
+
current_url.should == expected_url
|
67
|
+
end
|
68
|
+
|
69
|
+
Then(/^verify current path is "([^"]*)"$/) do |current_path|
|
70
|
+
"
|
71
|
+
Path should be path+query of the current page
|
72
|
+
"
|
73
|
+
# E.g : Then verify current path is "/login"
|
74
|
+
assert_current_path(current_path)
|
75
|
+
end
|
76
|
+
|
77
|
+
Then(/^verify page title is "([^"]*)"$/) do |page_title|
|
78
|
+
"
|
79
|
+
Title should be title of the current page
|
80
|
+
"
|
81
|
+
# E.g : Then verify page title is "Welcome"
|
82
|
+
assert_title(page_title, wait: BddHelper.timeout)
|
83
|
+
end
|
84
|
+
|
85
|
+
Then(/^verify page title contains "([^"]*)"$/) do |text|
|
86
|
+
"
|
87
|
+
Title should be contains of the current page title
|
88
|
+
"
|
89
|
+
# E.g : Then verify page title contains "Welcome"
|
90
|
+
title.should include(text)
|
91
|
+
end
|
92
|
+
|
93
|
+
Then(/^verify below texts are displayed:$/) do |table|
|
94
|
+
# E.g : Then verify below texts are displayed:
|
95
|
+
# | Welcome |
|
96
|
+
# | Thank you |
|
97
|
+
table.raw.each { |raw| page.should have_text(raw[0], wait: BddHelper.timeout) }
|
98
|
+
end
|
99
|
+
|
100
|
+
Then(/^verify below texts are not displayed:$/) do |table|
|
101
|
+
# E.g : Then verify below texts are not displayed:
|
102
|
+
# | Welcome |
|
103
|
+
# | Thank you |
|
104
|
+
table.raw.each { |raw| page.should_not have_text(raw[0], wait: BddHelper.timeout) }
|
105
|
+
end
|
106
|
+
|
107
|
+
Then(/^verify "([^"]*)" alert message is displayed$/) do |text|
|
108
|
+
# E.g : Then verify "Successful" alert message is displayed
|
109
|
+
text.should == page.driver.browser.switch_to.alert.text
|
110
|
+
end
|
111
|
+
|
112
|
+
Then(/^verify "([^"]*)" alert message is not displayed$/) do |text|
|
113
|
+
# E.g : Then verify "Successful" alert message is not displayed
|
114
|
+
text.should_not == page.driver.browser.switch_to.alert.text
|
115
|
+
end
|
116
|
+
|
117
|
+
Then(/^verify "([^"]*)" checkbox is checked$/) do |checkbox|
|
118
|
+
"
|
119
|
+
Checkbox can be name, id and label text
|
120
|
+
"
|
121
|
+
# E.g : Then verify "Terms & Conditions" checkbox is checked
|
122
|
+
expect(page).to have_field(checkbox, checked: true, visible: true, wait: BddHelper.timeout)
|
123
|
+
end
|
124
|
+
|
125
|
+
Then(/^verify "([^"]*)" checkbox is unchecked/) do |checkbox|
|
126
|
+
"
|
127
|
+
Checkbox can be name, id and label text
|
128
|
+
"
|
129
|
+
# E.g : Then verify "Terms & Conditions" checkbox is unchecked
|
130
|
+
expect(page).to have_field(checkbox, checked: false, visible: true, wait: BddHelper.timeout)
|
131
|
+
end
|
132
|
+
|
133
|
+
Then(/^verify "([^"]*)" radio button is selected$/) do |radio_button|
|
134
|
+
"
|
135
|
+
Radio Button can be name, id and label text
|
136
|
+
"
|
137
|
+
# E.g : Then verify "Male" radio button is selected
|
138
|
+
expect(page).to have_field(radio_button, checked: true, visible: true, wait: BddHelper.timeout)
|
139
|
+
end
|
140
|
+
|
141
|
+
Then(/^verify "([^"]*)" radio button is not selected$/) do |radio_button|
|
142
|
+
"
|
143
|
+
Radio Button can be name, id and label text
|
144
|
+
"
|
145
|
+
# E.g : Then verify "Female" radio button is not selected
|
146
|
+
expect(page).to have_field(radio_button, checked: false, visible: true, wait: BddHelper.timeout)
|
147
|
+
end
|
148
|
+
|
149
|
+
Then(/^verify "([^"]*)" dropdown contains "([^"]*)" option$/) do |dropdown, option_text|
|
150
|
+
"
|
151
|
+
Dropdown can be id, name, label
|
152
|
+
"
|
153
|
+
# E.g : Then verify "Country" dropdown contains "United States" option
|
154
|
+
page.should have_select(dropdown, with_options: [option_text], wait: BddHelper.timeout)
|
155
|
+
end
|
156
|
+
|
157
|
+
Then(/^verify "([^"]*)" dropdown does not contain "([^"]*)" option$/) do |dropdown, option_text|
|
158
|
+
"
|
159
|
+
Dropdown can be id, name, label
|
160
|
+
"
|
161
|
+
# E.g : Then verify "Country" dropdown does not contain "United States" option
|
162
|
+
page.should_not have_select(dropdown, with_options: [option_text], wait: BddHelper.timeout)
|
163
|
+
end
|
164
|
+
|
165
|
+
Then(/^verify "([^"]*)" dropdown contains the options below:$/) do |dropdown, table|
|
166
|
+
"
|
167
|
+
Dropdown can be id, name, label
|
168
|
+
"
|
169
|
+
# E.g : Then verify "Country" dropdown contains the options below:
|
170
|
+
# |United States|
|
171
|
+
# |Turkey |
|
172
|
+
table.raw.each { |raw| page.should have_select(dropdown, with_options: [raw[0]], wait: BddHelper.timeout) }
|
173
|
+
end
|
174
|
+
|
175
|
+
Then(/^verify "([^"]*)" dropdown does not contain the options below:$/) do |dropdown, table|
|
176
|
+
"
|
177
|
+
Dropdown can be id, name, label
|
178
|
+
"
|
179
|
+
# E.g : Then verify "Country" dropdown does not contain the options below:
|
180
|
+
# |United States|
|
181
|
+
# |Turkey |
|
182
|
+
table.raw.each { |raw| page.should_not have_select(dropdown, with_options: [raw[0]], wait: BddHelper.timeout) }
|
183
|
+
end
|
184
|
+
|
185
|
+
Then(/^verify "([^"]*)" options is selected from "([^"]*)" dropdown$/) do |option, dropdown|
|
186
|
+
"
|
187
|
+
Dropdown can be id, name, label
|
188
|
+
"
|
189
|
+
# E.g : Then verify "United States" options is selected from "Country" dropdown
|
190
|
+
page.should have_select(dropdown, selected: option, wait: BddHelper.timeout)
|
191
|
+
end
|
192
|
+
|
193
|
+
Then(/^verify "([^"]*)" options is not selected from "([^"]*)" dropdown$/) do |option, dropdown|
|
194
|
+
"
|
195
|
+
Dropdown can be id, name, label
|
196
|
+
"
|
197
|
+
# E.g : Then verify "United States" options is not selected from "Country" dropdown
|
198
|
+
page.should_not have_select(dropdown, selected: option, wait: BddHelper.timeout)
|
199
|
+
end
|
200
|
+
rescue StandardError => e
|
201
|
+
puts e
|
202
|
+
end
|
data/lib/steps/config.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module BddHelper
|
2
|
+
class << self
|
3
|
+
attr_accessor :timeout, :base_url
|
4
|
+
|
5
|
+
def timeout
|
6
|
+
@timeout || 20
|
7
|
+
end
|
8
|
+
|
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
|