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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6a9e8061724a7fb3583ee4a68f1ce2091760e3e7
4
- data.tar.gz: 146ed89fce2589ef73b93950869a76f1ad21233e
2
+ SHA256:
3
+ metadata.gz: 55509be429c7af805db4bb6f2ba8e84a000379b5c50b60515533596271ee7a9f
4
+ data.tar.gz: fecc456613479d7c1cc70514eb492c26481a6c41491f4a896e22c08c7ae102db
5
5
  SHA512:
6
- metadata.gz: 40719aaef3cd0d06e955c4b5af1939bb7426ed425fc320b6164374b945708f0dbdab9770d8d999a2f35457798d01e4db94ddcf7e0007c39cb22faa2196debec3
7
- data.tar.gz: 1065251038130380666ef0a5a24d5b6e2a84a2ccecc87cb331a6bef9a4310b4bae48be01ef1f3b9dc8000aea387613d38fc1b8ede5871778fb62a3f04906db4c
6
+ metadata.gz: 6f7376af00c34fef3a1437de882166da25d9e8b2a65e2a476875d288429989ce01a9abb671dd682d76465d70261f468672d64e5a5d1be4aefb061f9208fdd9eb
7
+ data.tar.gz: 616b8f799f735b10864851fa8bac2e5c3fb0d24a79f70c863d9d58a85956463db21b460bcc35b1e47bc0bcbf6406441fd587a9b3e2a60b4b0bd6b356b5e68569
data/lib/bdd-helper.rb CHANGED
@@ -1,17 +1,24 @@
1
1
  require 'capybara'
2
- require 'capybara/cucumber'
3
- require 'capybara/dsl'
4
2
  require 'capybara/rspec'
5
3
  require 'rspec'
6
4
  require 'rspec/expectations'
7
5
  require 'rspec/matchers'
8
6
  require 'selenium/webdriver'
9
7
  require 'selenium/webdriver/common/wait'
8
+ require 'faker'
9
+
10
+ require 'steps/action/check_steps'
11
+ require 'steps/action/choose_steps'
12
+ require 'steps/action/click_steps'
13
+ require 'steps/action/fill_steps'
14
+ require 'steps/action/key_action_steps'
15
+ require 'steps/action/select_steps'
16
+ require 'steps/assertion/assertion_steps'
17
+ require 'steps/customized/customized_steps'
18
+ require 'steps/util/browser_util_steps'
19
+ require 'steps/util/browser_util_methods'
20
+ require 'steps/util/fill_in_util'
21
+ require 'steps/config'
22
+ require 'steps/global/global_context'
23
+ require 'steps/config'
10
24
 
11
- require 'steps/assertion'
12
- require 'steps/browser'
13
- require 'steps/check'
14
- require 'steps/click'
15
- require 'steps/fill'
16
- require 'steps/select'
17
- require 'steps/unclassified'
data/lib/demo.feature ADDED
@@ -0,0 +1,172 @@
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
+ When switch to iframe by "123" id
35
+ When switch to parent frame
36
+ When switch to default content
37
+
38
+ When close window
39
+ When maximize window
40
+ When get window size
41
+ When resize window to 123 width 123 height
42
+
43
+ # BROWSER UTIL
44
+ ####################################
45
+
46
+ ########################################################################
47
+
48
+ ####################################
49
+ # ASSERTION
50
+ Then verify below texts are displayed:
51
+ | Welcome |
52
+ | Thank you |
53
+ Then verify below texts are not displayed:
54
+ | Welcome |
55
+ | Thank you |
56
+ Then verify "text" text is displayed
57
+ Then verify "text" text is not displayed
58
+
59
+
60
+ Then verify ".success-message" element has "Welcome" text
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
+
73
+
74
+ Then verify "Login" button is displayed
75
+ Then verify "Sign In " button is not displayed
76
+
77
+ Then verify "Login" button is enabled
78
+ Then verify "Logout" button is disabled
79
+
80
+ Then verify current url is "http:www.example.com"
81
+ Then verify current path is "/login"
82
+
83
+ Then verify page title is "Welcome"
84
+ Then verify page title contains "Welcome"
85
+
86
+ Then verify "Successful Login" alert message is displayed
87
+ Then verify "Incorrect login or password." alert message is not displayed
88
+
89
+
90
+ Then verify "Terms & Conditions" checkbox is checked
91
+ Then verify "Terms & Conditions" checkbox is unchecked
92
+
93
+ Then verify "Male" radio button is selected
94
+ Then verify "Female" radio button is not selected
95
+ Then verify "cars" dropdown contains "audi" option
96
+ Then verify "cars" dropdown does not contain "audi" option
97
+ Then verify "cars" dropdown contains the options below:
98
+ | au |
99
+ | bm |
100
+
101
+ Then verify "audi" options is selected from "cars" dropdown
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
+
114
+ # ASSERTION
115
+ ####################################
116
+
117
+ ########################################################################
118
+
119
+ ####################################
120
+ # ACTION
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"
124
+ When fill "First Name" with random first name
125
+ When fill "Last Name" with random last name
126
+ When fill "Email" with random email
127
+ When fill "Phone Number" with random phone number
128
+ When fill "Address" with random address
129
+ When fill "Zip Code" with random zip code
130
+ When fill inputs:
131
+ | username | test user |
132
+ | password | pas123 |
133
+
134
+ When click "Contact Us" link
135
+ When click "Sign In" button
136
+ When click "#bmwradio" css element
137
+ When click "//*[@id='openwindow']" xpath element
138
+
139
+ When check "Terms & Conditions" checkbox
140
+ When uncheck "Privacy Policy" checkbox
141
+
142
+ When choose "Male" radio button
143
+
144
+ When clear "First Name" input
145
+ When select "audi" from "cars" dropdown
146
+ When select "Honda" from "#carselect" css element
147
+ When select "BMW" from "//*[@id='carselect']" xpath element
148
+
149
+ When press "#login" enter
150
+ When press "#username" delete
151
+ When press ".list-selector" down
152
+ When press ".list-selector" up
153
+ When press ".list-selector" left
154
+ When press ".list-selector" right
155
+
156
+ When click "Logout" under ".account-menu"
157
+ When click "Logout" item 0 under ".account-menu" menu item 0
158
+
159
+ When hover over "Account"
160
+ # ACTION
161
+ ####################################
162
+
163
+ ########################################################################
164
+
165
+ ####################################
166
+ # CUSTOMIZED
167
+ When hover to "css" value ".list_item" web element
168
+ When wait 2 seconds
169
+ When generate 10 char random string and type into type "css" value ".username"
170
+ When execute javascript code "window.location.reload()"
171
+ # CUSTOMIZED
172
+ ####################################
@@ -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,45 @@
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 "([^"]*)" (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
+
26
+ When(/^click "([^"]*)" under "([^"]*)"$/) do |link, menu|
27
+ "
28
+ Finds a element with capybara default_selector, link can be id, text or title
29
+ "
30
+ # E.g : And click "Logout" under ".account-menu"
31
+ find(menu, wait: BddHelper.timeout).hover
32
+ click_link(link, wait: BddHelper.timeout)
33
+ end
34
+
35
+ When(/^click "([^"]*)" item (\d+) under "([^"]*)" menu item (\d+)$/) do |link, link_item, menu, menu_item|
36
+ "
37
+ Link can be id, text or title, menu can be text content
38
+ "
39
+ # E.g : And click "Logout" item 2 under "Account" menu item 1
40
+ (page.all(:xpath, "//*[text()='#{menu}']", wait: BddHelper.timeout)[menu_item]).hover
41
+ (page.all(:link, link, wait: BddHelper.timeout)[link_item]).click
42
+ end
43
+ rescue StandardError => e
44
+ puts e
45
+ end
@@ -0,0 +1,85 @@
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
+ 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)
16
+ end
17
+
18
+ When(/^fill inputs:$/) do |table|
19
+ "
20
+ Fillable field can be name, id, placeholder or label text
21
+ "
22
+ # E.g : And fill inputs:
23
+ # | username | test user |
24
+ # | password | pass123 |
25
+ table.raw.each { |raw| FillInUtil.fill_text_field(raw[0], raw[1]) }
26
+ end
27
+
28
+ When(/^fill "([^"]*)" with random (first name)$/) do |locator, arg|
29
+ "
30
+ Fillable field can be name, id, placeholder or label text
31
+ "
32
+ # E.g : And fill "First Name" with random first name
33
+ FillInUtil.fill_text_field(locator, Faker::Name.first_name)
34
+ end
35
+
36
+ When(/^fill "([^"]*)" with random (last name)$/) do |locator, arg|
37
+ "
38
+ Fillable field can be name, id, placeholder or label text
39
+ "
40
+ # E.g : And fill "Last Name" with random last name
41
+ FillInUtil.fill_text_field(locator, Faker::Name.last_name)
42
+ end
43
+
44
+ When(/^fill "([^"]*)" with random (email)$/) do |locator, arg|
45
+ "
46
+ Fillable field can be name, id, placeholder or label text
47
+ "
48
+ # E.g : And fill "Email" with random email
49
+ FillInUtil.fill_text_field(locator, Faker::Internet.safe_email)
50
+ end
51
+
52
+ When(/^fill "([^"]*)" with random (phone number)$/) do |locator, arg|
53
+ "
54
+ Fillable field can be name, id, placeholder or label text
55
+ "
56
+ # E.g : And fill "Phone Number" with random phone number
57
+ FillInUtil.fill_text_field(locator, Array.new(7) { Array(0..9).sample }.join)
58
+ end
59
+
60
+ When(/^fill "([^"]*)" with random (address)$/) do |locator, arg|
61
+ "
62
+ Fillable field can be name, id, placeholder or label text
63
+ "
64
+ # E.g : And fill "Address" with random address
65
+ FillInUtil.fill_text_field(locator, Faker::Address.full_address)
66
+ end
67
+
68
+ When(/^fill "([^"]*)" with random (zip code)$/) do |locator, arg|
69
+ "
70
+ Fillable field can be name, id, placeholder or label text
71
+ "
72
+ # E.g : And fill "Zip Code" with random zip code
73
+ FillInUtil.fill_text_field(locator, Faker::Address.zip_code)
74
+ end
75
+
76
+ When(/^clear "([^"]*)" input$/) do |locator|
77
+ "
78
+ Fillable field can be name, id, placeholder or label text
79
+ "
80
+ # E.g : And clear "Name" input
81
+ FillInUtil.clear_text_field(locator)
82
+ end
83
+ rescue StandardError => e
84
+ puts e
85
+ 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,24 @@
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
+ 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
+
22
+ rescue StandardError => e
23
+ puts e
24
+ end