selenium-cucumber 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ To open/close URL and to navigate between pages use following steps
14
14
 
15
15
  To interact with browser use following steps
16
16
 
17
- Then I resize browser with width (\d+) and heigth (\d+)
17
+ Then I resize browser window size to width (\d+) and heigth (\d+)
18
18
  Then I close browser
19
19
 
20
20
  To zoom in/out webpage use following steps
@@ -36,31 +36,41 @@ To reset webpage view use following step
36
36
 
37
37
  To scroll webpage use following step
38
38
 
39
- Then I scroll to the element having id "(.*?)"
40
- Then I scroll to the element having name "(.*?)"
41
- Then I scroll to the element having class "(.*?)"
42
- Then I scroll to the element having xpath "(.*?)"
43
- Then I scroll to the element having css "(.*?)"
39
+ Then I scroll to element having id "(.*?)"
40
+ Then I scroll to element having name "(.*?)"
41
+ Then I scroll to element having class "(.*?)"
42
+ Then I scroll to element having xpath "(.*?)"
43
+ Then I scroll to element having css "(.*?)"
44
+
45
+ To hover over a element use following step
46
+
47
+ Then I hover over element having id "(.*?)"
48
+ Then I hover over element having name "(.*?)"
49
+ Then I hover over element having class "(.*?)"
50
+ Then I hover over element having xpath "(.*?)"
51
+ Then I hover over element having css "(.*?)"
52
+
44
53
 
45
54
  Assertion Steps
46
55
  ---------------
47
56
  To assert that page title can be found use following step.
48
57
 
49
- Then I see page title as "(.*?)"
58
+ Then I should see page title as "(.*?)"
50
59
 
51
60
  To assert element text use any of the following steps.
52
61
 
53
- Then I should see text as "(.*?)" for element having id "(.*?)"
54
- Then I should see text as "(.*?)" for element having class "(.*?)"
55
- Then I should see text as "(.*?)" for element having name "(.*?)"
56
- Then I should see text as "(.*?)" for element having xpath "(.*?)"
57
- Then I should see text as "(.*?)" for element having css "(.*?)"
58
-
59
- Then I should not see text as "(.*?)" for element having id "(.*?)"
60
- Then I should not see text as "(.*?)" for element having class "(.*?)"
61
- Then I should not see text as "(.*?)" for element having name "(.*?)"
62
- Then I should not see text as "(.*?)" for element having xpath "(.*?)"
63
- Then I should not see text as "(.*?)" for element having css "(.*?)"
62
+ Then element having id "([^\"]*)" should have text as "(.*?)"
63
+ Then element having name "([^\"]*)" should have text as "(.*?)"
64
+ Then element having class "([^\"]*)" should have text as "(.*?)"
65
+ Then element having xpath "([^\"]*)" should have text as "(.*?)"
66
+ Then element having css "([^\"]*)" should have text as "(.*?)"
67
+
68
+ Then element having id "([^\"]*)" should not have text as "(.*?)"
69
+ Then element having name "([^\"]*)" should not have text as "(.*?)"
70
+ Then element having class "([^\"]*)" should not have text as "(.*?)"
71
+ Then element having xpath "([^\"]*)" should not have text as "(.*?)"
72
+ Then element having css "([^\"]*)" should not have text as "(.*?)"
73
+
64
74
 
65
75
  To assert element attribute use any of the following steps.
66
76
 
@@ -94,92 +104,97 @@ To assert that element is disabled use any of the following steps.
94
104
 
95
105
  To assert that element is present use any of the following steps.
96
106
 
97
- Then I should see element present having id "(.*?)"
98
- Then I should see element present having name "(.*?)"
99
- Then I should see element present having class "(.*?)"
100
- Then I should see element present having xpath "(.*?)"
101
- Then I should see element present having css "(.*?)"
107
+ Then element having id "([^\"]*)" should be present
108
+ Then element having name "([^\"]*)" should be present
109
+ Then element having class "([^\"]*)" should be present
110
+ Then element having xpath "([^\"]*)" should be present
111
+ Then element having css "([^\"]*)" should be present
102
112
 
103
113
  To assert that element is not present use any of the following steps.
104
114
 
105
- Then I should not see element present having id "(.*?)"
106
- Then I should not see element present having name "(.*?)"
107
- Then I should not see element present having class "(.*?)"
108
- Then I should not see element present having xpath "(.*?)"
109
- Then I should not see element present having css "(.*?)"
115
+ Then element having id "([^\"]*)" should not be present
116
+ Then element having name "([^\"]*)" should not be present
117
+ Then element having class "([^\"]*)" should not be present
118
+ Then element having xpath "([^\"]*)" should not be present
119
+ Then element having css "([^\"]*)" should not be present
110
120
 
111
121
 
112
122
  To assert that checkbox is checked use any of the following steps.
113
123
 
114
- Then I should see checkbox having id "(.*?)" checked
115
- Then I should see checkbox having name "(.*?)" checked
116
- Then I should see checkbox having class "(.*?)" checked
117
- Then I should see checkbox having xpath "(.*?)" checked
118
- Then I should see checkbox having css "(.*?)" checked
124
+ Then checkbox having id "(.*?)" should be checked
125
+ Then checkbox having name "(.*?)" should be checked
126
+ Then checkbox having class "(.*?)" should be checked
127
+ Then checkbox having xpath "(.*?)" should be checked
128
+ Then checkbox having css "(.*?)" should be checked
119
129
 
120
130
  To assert that checkbox is unchecked use any of the following steps.
121
131
 
122
- Then I should see checkbox having id "(.*?)" unchecked
123
- Then I should see checkbox having name "(.*?)" unchecked
124
- Then I should see checkbox having class "(.*?)" unchecked
125
- Then I should see checkbox having xpath "(.*?)" unchecked
126
- Then I should see checkbox having css "(.*?)" unchecked
132
+ Then checkbox having id "(.*?)" should be unchecked
133
+ Then checkbox having name "(.*?)" should be unchecked
134
+ Then checkbox having class "(.*?)" should be unchecked
135
+ Then checkbox having xpath "(.*?)" should be unchecked
136
+ Then checkbox having css "(.*?)" should be unchecked
127
137
 
128
138
  To assert that radio button selected use any of the following steps.
129
139
 
130
- Then I should see radio button having id "(.*?)" selected
131
- Then I should see radio button having name "(.*?)" selected
132
- Then I should see radio button having class "(.*?)" selected
133
- Then I should see radio button having xpath "(.*?)" selected
134
- Then I should see radio button having css "(.*?)" selected
140
+ Then radio button having id "(.*?)" should be selected
141
+ Then radio button having name "(.*?)" should be selected
142
+ Then radio button having class "(.*?)" should be selected
143
+ Then radio button having xpath "(.*?)" should be selected
144
+ Then radio button having css "(.*?)" should be selected
135
145
 
136
146
  To assert that radio button not selected use any of the following steps.
137
147
 
138
- Then I should see radio button having id "(.*?)" unselected
139
- Then I should see radio button having name "(.*?)" unselected
140
- Then I should see radio button having class "(.*?)" unselected
141
- Then I should see radio button having xpath "(.*?)" unselected
142
- Then I should see radio button having css "(.*?)" unselected
148
+ Then radio button having id "(.*?)" should be unselected
149
+ Then radio button having name "(.*?)" should be unselected
150
+ Then radio button having class "(.*?)" should be unselected
151
+ Then radio button having xpath "(.*?)" should be unselected
152
+ Then radio button having css "(.*?)" should be unselected
143
153
 
144
154
  To assert that radio button group selected by text use any of the following steps.
145
155
 
146
- Then I should see "(.*?)" option by text from radio button group having id "(.*?)" selected
147
- Then I should see "(.*?)" option by text from radio button group having name "(.*?)" selected
148
- Then I should see "(.*?)" option by text from radio button group having class "(.*?)" selected
149
- Then I should see "(.*?)" option by text from radio button group having xpath "(.*?)" selected
150
- Then I should see "(.*?)" option by text from radio button group having css "(.*?)" selected
151
-
156
+ Then option "(.*?)" by text from radio button group having id "(.*?)" should be selected
157
+ Then option "(.*?)" by text from radio button group having name "(.*?)" should be selected
158
+ Then option "(.*?)" by text from radio button group having class "(.*?)" should be selected
159
+ Then option "(.*?)" by text from radio button group having xpath "(.*?)" should be selected
160
+ Then option "(.*?)" by text from radio button group having css "(.*?)" should be selected
161
+
152
162
  To assert that radio button group selected by value use any of the following steps.
153
163
 
154
- Then I should see "(.*?)" option by value from radio button group having id "(.*?)" selected
155
- Then I should see "(.*?)" option by value from radio button group having name "(.*?)" selected
156
- Then I should see "(.*?)" option by value from radio button group having class "(.*?)" selected
157
- Then I should see "(.*?)" option by value from radio button group having xpath "(.*?)" selected
158
- Then I should see "(.*?)" option by value from radio button group having css "(.*?)" selected
164
+ Then option "(.*?)" by value from radio button group having id "(.*?)" should be selected
165
+ Then option "(.*?)" by value from radio button group having name "(.*?)" should be selected
166
+ Then option "(.*?)" by value from radio button group having class "(.*?)" should be selected
167
+ Then option "(.*?)" by value from radio button group having xpath "(.*?)" should be selected
168
+ Then option "(.*?)" by value from radio button group having css "(.*?)" should be selected
159
169
 
160
170
  To assert that radio button group not selected by text use any of the following steps.
161
171
 
162
- Then I should see "(.*?)" option by text from radio button group having id "(.*?)" unselected
163
- Then I should see "(.*?)" option by text from radio button group having name "(.*?)" unselected
164
- Then I should see "(.*?)" option by text from radio button group having class "(.*?)" unselected
165
- Then I should see "(.*?)" option by text from radio button group having xpath "(.*?)" unselected
166
- Then I should see "(.*?)" option by text from radio button group having css "(.*?)" unselected
172
+ Then option "(.*?)" by text from radio button group having id "(.*?)" should be unselected
173
+ Then option "(.*?)" by text from radio button group having name "(.*?)" should be unselected
174
+ Then option "(.*?)" by text from radio button group having class "(.*?)" should be unselected
175
+ Then option "(.*?)" by text from radio button group having xpath "(.*?)" should be unselected
176
+ Then option "(.*?)" by text from radio button group having css "(.*?)" should be unselected
167
177
 
168
178
  To assert that radio button group not selected by value use any of the following steps.
169
179
 
170
- Then I should see "(.*?)" option by value from radio button group having id "(.*?)" unselected
171
- Then I should see "(.*?)" option by value from radio button group having name "(.*?)" unselected
172
- Then I should see "(.*?)" option by value from radio button group having class "(.*?)" unselected
173
- Then I should see "(.*?)" option by value from radio button group having xpath "(.*?)" unselected
174
- Then I should see "(.*?)" option by value from radio button group having css "(.*?)" unselected
180
+ Then option "(.*?)" by value from radio button group having id "(.*?)" should be unselected
181
+ Then option "(.*?)" by value from radio button group having name "(.*?)" should be unselected
182
+ Then option "(.*?)" by value from radio button group having class "(.*?)" should be unselected
183
+ Then option "(.*?)" by value from radio button group having xpath "(.*?)" should be unselected
184
+ Then option "(.*?)" by value from radio button group having css "(.*?)" should be unselected
175
185
 
176
186
  To assert that link is present use following steps
177
187
 
178
- Then I should see link present having text "(.*?)"
179
- Then I should see link present having partial text "(.*?)"
180
-
181
- Then I should see link not present having text "(.*?)"
182
- Then I should see link not present having partial text "(.*?)"
188
+ Then link having text "(.*?)" should be present
189
+ Then link having partial text "(.*?)" should be present
190
+
191
+ Then link having text "(.*?)" should not be present
192
+ Then link having partial text "(.*?)" should not be present
193
+
194
+ To assert text on javascipt pop-up alert
195
+
196
+ Then I should see alert text as "(.*?)"
197
+
183
198
 
184
199
  Input Steps
185
200
  -----------
@@ -249,11 +264,11 @@ To uncheck checkbox use following steps
249
264
 
250
265
  To toggle checkbox use following steps
251
266
 
252
- Then toggle checkbox having id "(.*?)"
253
- Then toggle checkbox having name "(.*?)"
254
- Then toggle checkbox having class "(.*?)"
255
- Then toggle checkbox having xpath "(.*?)"
256
- Then toggle checkbox having css "(.*?)"
267
+ Then I toggle checkbox having id "(.*?)"
268
+ Then I toggle checkbox having name "(.*?)"
269
+ Then I toggle checkbox having class "(.*?)"
270
+ Then I toggle checkbox having xpath "(.*?)"
271
+ Then I toggle checkbox having css "(.*?)"
257
272
 
258
273
  To select radio button use following steps
259
274
 
@@ -291,6 +306,14 @@ To click on web element use following steps
291
306
  Then I click on element having xpath "(.*?)"
292
307
  Then I click on element having css "(.*?)"
293
308
 
309
+ To forcefully click on web element use following steps (if above steps not worked)
310
+
311
+ Then I forcefully click on element having id "(.*?)"
312
+ Then I forcefully click on element having name "(.*?)"
313
+ Then I forcefully click on element having class "(.*?)"
314
+ Then I forcefully click on element having xpath "(.*?)"
315
+ Then I forcefully click on element having css "(.*?)"
316
+
294
317
  To click on links use following steps
295
318
 
296
319
  Then I click on link having text "(.*?)"
@@ -61,6 +61,8 @@ Javascript Handling API
61
61
 
62
62
  handle_alert(decesion) # accept or dismiss
63
63
 
64
+ get_alert_text
65
+
64
66
 
65
67
  Progress API's
66
68
  --------------
@@ -1,8 +1,2 @@
1
1
 
2
- require 'selenium-cucumber/assertion_steps'
3
- require 'selenium-cucumber/input_steps'
4
- require 'selenium-cucumber/navigation_steps'
5
- require 'selenium-cucumber/click_elements_steps'
6
- require 'selenium-cucumber/progress_steps'
7
- require 'selenium-cucumber/screenshot_steps'
8
- require 'selenium-cucumber/configuration_steps'
2
+ Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each {|file| require file }
@@ -2,12 +2,12 @@ require_relative 'methods/assertion_methods'
2
2
 
3
3
 
4
4
  #Page title checking
5
- Then(/^I see page title as "(.*?)"$/) do |title|
5
+ Then(/^I should see page title as "(.*?)"$/) do |title|
6
6
  check_title(title)
7
7
  end
8
8
 
9
9
  #Step to check element text
10
- Then(/^I should\s*((?:not)?)\s+see text as "(.*?)" for element having (.+) "(.*?)"$/) do |present, value, type, access_name|
10
+ Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have text as "(.*?)"$/) do |type, access_name,present, value |
11
11
  validate_locator type
12
12
  check_element_text(type, value, access_name, present.empty?)
13
13
  end
@@ -27,42 +27,43 @@ Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+be (enabled|disabled
27
27
  end
28
28
 
29
29
  #Step to check element present or not
30
- Then(/^I should\s*((?:not)?)\s+see element present having (.+) "(.*?)"$/) do |present, type, access_name|
30
+ Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+be present"$/) do |type, access_name, present|
31
31
  validate_locator type
32
32
  check_element_presence(type, access_name, present.empty?)
33
33
  end
34
34
 
35
35
  #Step to assert checkbox is checked or unchecked
36
- Then(/^I should\s*((?:not)?)\s+see checkbox having (.+) "(.*?)" (checked|unchecked)$/) do |present, type, access_name, state|
36
+ Then(/^checkbox having (.+) "(.*?)" should be (checked|unchecked)$/) do |type, access_name, state|
37
37
  validate_locator type
38
38
  flag = state == "checked"
39
- flag = !flag unless present.empty?
40
39
  is_checkbox_checked(type, access_name, flag)
41
40
  end
42
41
 
43
42
  #steps to assert radio button checked or unchecked
44
- Then(/^I should\s*((?:not)?)\s+see radio button having (.+) "(.*?)" (selected|unselected)$/) do |present, type, access_name, state|
43
+ Then(/^radio button having (.+) "(.*?)" should be (selected|unselected)$/) do |type, access_name, state|
45
44
  validate_locator type
46
45
  flag = state == "checked"
47
- flag = !flag unless present.empty?
48
46
  is_radio_button_selected(type, access_name, flag)
49
47
  end
50
48
 
51
- #steps to assert option by text from radio button group selected
52
- Then(/^I should\s*((?:not)?)\s+see "(.*?)" option by (.+) from radio button group having (.+) "(.*?)" (selected|unselected)$/) do |present, option, attr, access_name, type, state|
49
+ #steps to assert option by text from radio button group selected/unselected
50
+ Then(/^option "(.*?)" by (.+) from radio button group having (.+) "(.*?)" should be (selected|unselected)$/) do |option, attrb, type, access_name, state|
53
51
  validate_locator type
54
52
  flag = state == "selected"
55
- flag = !flag unless present.empty?
56
- is_option_from_radio_button_group_selected(type, attr, option, access_name, flag)
53
+ is_option_from_radio_button_group_selected(type, attrb, option, access_name, flag)
57
54
  end
58
55
 
59
56
  #steps to check link presence
60
- Then(/^I should see link\s*((?:not)?)\s+present having text "(.*?)"$/) do |present,access_name|
61
- check_element_presence("link", access_name, present.empty?)
57
+ Then(/^link having text "(.*?)" should\s*((?:not)?)\s+be present$/) do |present,access_name|
58
+ check_element_presence("link", access_name, present.empty?)
62
59
  end
63
60
 
64
-
65
- Then(/^I should see link\s*((?:not)?)\s+present having partial text "(.*?)"$/) do |present,access_name|
66
- check_element_presence("partial_link_text", access_name, present.empty?)
61
+ Then(/^link having partial text "(.*?)" should\s*((?:not)?)\s+be present$/) do |present,access_name|
62
+ check_element_presence("partial_link_text", access_name, present.empty?)
67
63
  end
68
64
 
65
+ #Step to assert javascript pop-up alert text
66
+
67
+ Then(/^I should see alert text as "(.*?)"$/) do |actual_value|
68
+ check_alert_text(actual_value)
69
+ end
@@ -4,7 +4,12 @@ require_relative 'methods/click_elements_methods'
4
4
 
5
5
  When(/^I click on element having (.+) "(.*?)"$/) do |type, access_name|
6
6
  validate_locator type
7
- click("id",access_name)
7
+ click(type,access_name)
8
+ end
9
+
10
+ Then(/^I forcefully click on element having (.+) "(.*?)"$/) do |type, access_name|
11
+ validate_locator type
12
+ click_forcefully(type, access_name)
8
13
  end
9
14
 
10
15
  #steps to click on link
@@ -50,7 +50,7 @@ end
50
50
 
51
51
  #Steps to toggle checkbox
52
52
 
53
- Then(/^toggle checkbox having (.+) "(.*?)"$/) do |type, access_name|
53
+ Then(/^I toggle checkbox having (.+) "(.*?)"$/) do |type, access_name|
54
54
  validate_locator type
55
55
  toggle_checkbox(type,access_name)
56
56
  end
@@ -1,4 +1,4 @@
1
- require_relative 'methods/javascript_handling_steps'
1
+ require_relative 'methods/javascript_handling_methods'
2
2
 
3
3
  Then(/^I accept alert$/) do
4
4
  handle_alert("accept")
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  def check_title(title)
10
10
  if(get_page_title!=title)
11
- raise "Page Title Not Matched"
11
+ raise TestCaseFailed ,"Page Title Not Matched"
12
12
  end
13
13
  end
14
14
 
@@ -23,11 +23,11 @@ def check_element_text(access_type, actual_value, access_name, test_case)
23
23
 
24
24
  if test_case
25
25
  if(element_text!=actual_value)
26
- raise "Text Not Matched"
26
+ raise TestCaseFailed ,"Text Not Matched"
27
27
  end
28
28
  else
29
29
  if(element_text==actual_value)
30
- raise "Text Matched"
30
+ raise TestCaseFailed ,"Text Matched"
31
31
  end
32
32
  end
33
33
  end
@@ -44,11 +44,11 @@ def check_element_enable(access_type, access_name, test_case)
44
44
 
45
45
  if test_case
46
46
  if(!result)
47
- raise "Element not enabled"
47
+ raise TestCaseFailed ,"Element Not Enabled"
48
48
  end
49
49
  else
50
50
  if(result)
51
- raise "Element enabled"
51
+ raise TestCaseFailed ,"Element Enabled"
52
52
  end
53
53
  end
54
54
  end
@@ -65,11 +65,11 @@ def check_element_attribute(access_type, attribute_name, attribute_value, access
65
65
 
66
66
  if test_case
67
67
  if(attr_val!=attribute_value)
68
- raise "Attribute Not Matched"
68
+ raise TestCaseFailed ,"Attribute Value Not Matched"
69
69
  end
70
70
  else
71
71
  if(attr_val==attribute_value)
72
- raise "Attribute Matched"
72
+ raise TestCaseFailed ,"Attribute Value Matched"
73
73
  end
74
74
  end
75
75
  end
@@ -83,7 +83,7 @@ end
83
83
  def check_element_presence(access_type, access_name, test_case)
84
84
  if test_case
85
85
  if !is_element_displayed(access_type,access_name)
86
- raise "Exception : Element Not Present"
86
+ raise TestCaseFailed ,"Element Not Present"
87
87
  end
88
88
  else
89
89
  begin
@@ -92,45 +92,36 @@ def check_element_presence(access_type, access_name, test_case)
92
92
  end
93
93
  rescue Exception => e
94
94
  if e.message=="present"
95
- raise "Exception : Element Present"
95
+ raise TestCaseFailed ,"Element Present"
96
96
  end
97
97
  end
98
98
  end
99
99
  end
100
100
 
101
- #method to assert checkbox check
101
+ #method to assert checkbox check/uncheck
102
102
  def is_checkbox_checked(access_type, access_name, should_be_checked=true)
103
103
  checkbox = WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}
104
104
 
105
105
  if !checkbox.selected? && should_be_checked
106
- raise "Checkbox not checked"
106
+ raise TestCaseFailed ,"Checkbox is not checked"
107
107
  elsif checkbox.selected? && !should_be_checked
108
- raise "Checkbox is checked"
108
+ raise TestCaseFailed ,"Checkbox is checked"
109
109
  end
110
110
  end
111
111
 
112
- #method to assert checkbox uncheck
113
- def is_checkbox_unchecked(access_type, access_name)
114
- checkbox = WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}
115
-
116
- if checkbox.selected?
117
- raise "Checkbox checked"
118
- end
119
- end
120
-
121
- #method to assert checkbox check
112
+ #method to assert radio button selected/unselected
122
113
  def is_radio_button_selected(access_type, access_name, should_be_selected=true)
123
114
  radio_button = WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}
124
115
 
125
116
  if !radio_button.selected? && should_be_selected
126
- raise "Radio Button not selected"
117
+ raise TestCaseFailed ,"Radio Button not selected"
127
118
  elsif radio_button.selected? && !should_be_selected
128
- raise "Radio Button is selected"
119
+ raise TestCaseFailed ,"Radio Button is selected"
129
120
  end
130
121
  end
131
122
 
132
123
 
133
- #method to assert option from radio button group is selected
124
+ #method to assert option from radio button group is selected/unselected
134
125
  def is_option_from_radio_button_group_selected(access_type, by, option, access_name, should_be_selected=true)
135
126
  radio_button_group = WAIT.until{$driver.find_elements(:"#{access_type}" => "#{access_name}")}
136
127
 
@@ -138,10 +129,21 @@ def is_option_from_radio_button_group_selected(access_type, by, option, access_n
138
129
 
139
130
  ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
140
131
 
141
- if !ele.selected && should_be_selected
142
- raise 'Radio button is not selected'
143
- elsif ele.selected && !should_be_selected
144
- raise 'Radio button is selected'
132
+ if !ele.selected? && should_be_selected
133
+ raise TestCaseFailed ,'Radio button is not selected'
134
+ elsif ele.selected? && !should_be_selected
135
+ raise TestCaseFailed ,'Radio button is selected'
145
136
  end
146
137
  end
147
138
 
139
+ #method to get javascript pop-up alert text
140
+ def get_alert_text
141
+ $driver.switch_to.alert.text
142
+ end
143
+
144
+ #method to check javascript pop-up alert text
145
+ def check_alert_text text
146
+ if get_alert_text!=text
147
+ raise TestCaseFailed , "Text on alert pop up not matched"
148
+ end
149
+ end
@@ -5,6 +5,10 @@ def click(access_type,access_name)
5
5
  element = WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")}.click
6
6
  end
7
7
 
8
+ def click_forcefully(access_type, access_name)
9
+ $driver.execute_script('arguments[0].click();', WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")})
10
+ end
11
+
8
12
  def submit(access_type,access_name)
9
13
  element = WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")}.submit
10
14
  end
@@ -58,29 +58,16 @@ end
58
58
 
59
59
  #method to select option from radio button group
60
60
  def select_option_from_radio_button_group(access_type, by, option, access_name)
61
- radio_button_group = WAIT.until {$driver.find_elements(:"#{access_type}" => "#{access_name}")}
62
-
63
- i=0
64
-
65
- if by=="value"
66
- while i<radio_button_group.length
67
- if radio_button_group[i].attribute("value")==option
68
- if !radio_button_group[i].selected?
69
- radio_button_group[i].click
70
- end
71
- break
72
- end
73
- i=i+1
74
- end
75
- else
76
- while i<radio_button_group.length
77
- if radio_button_group[i].text==option
78
- if !radio_button_group[i].selected?
79
- radio_button_group[i].click
80
- end
81
- break
82
- end
83
- i=i+1
84
- end
85
- end
86
- end
61
+
62
+ radio_button_group = WAIT.until{$driver.find_elements(:"#{access_type}" => "#{access_name}")}
63
+
64
+ getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text }
65
+
66
+ ele = radio_button_group.find { |rb| puts getter.call(rb, by) }
67
+
68
+ if !ele.selected?
69
+ ele.click
70
+ end
71
+ end
72
+
73
+
@@ -1,5 +1,9 @@
1
1
  require_relative 'required_files'
2
2
 
3
- def handle_alert "decesion"
4
- $driver.switch_to.alert.decesion
3
+ def handle_alert (decesion)
4
+ if decesion=="accept"
5
+ $driver.switch_to.alert.accept
6
+ else
7
+ $driver.switch_to.alert.dismiss
8
+ end
5
9
  end
@@ -1,4 +1,8 @@
1
1
 
2
+ #custome exception class
3
+ class TestCaseFailed < Exception
4
+ end
5
+
2
6
  # WAIT instance for explicit wait
3
7
  WAIT = Selenium::WebDriver::Wait.new(:timeout => 30)
4
8
 
@@ -17,5 +21,5 @@ def valid_option_by? option_by
17
21
  end
18
22
 
19
23
  def validate_option_by option_by
20
- raise "Invalid option by - #{option_by}" unless valid_locator_type? option_by
24
+ raise "Invalid option by - #{option_by}" unless valid_option_by? option_by
21
25
  end
@@ -2,7 +2,7 @@ require_relative 'required_files'
2
2
 
3
3
 
4
4
  def navigate_to(link)
5
- $driver.get link
5
+ $driver.get link
6
6
  end
7
7
 
8
8
  def navigate(direction)
@@ -14,7 +14,7 @@ def navigate(direction)
14
14
  end
15
15
 
16
16
  def close_driver
17
- $driver.quit
17
+ $driver.close
18
18
  end
19
19
 
20
20
  def scroll_to_element(access_type,access_name)
@@ -56,6 +56,12 @@ def resize_browser(width,heigth)
56
56
  $driver.manage.window.resize_to(width,heigth)
57
57
  end
58
58
 
59
+ #Method to hover on element
60
+ def hover_over_element(access_type,access_name)
61
+ element = WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")}
62
+ $driver.action.move_to(element).perform
63
+ end
64
+
59
65
  def get_os
60
66
  case CONFIG['host_os']
61
67
  when /mingw32|windows/i
@@ -17,8 +17,8 @@ Then(/^I close browser$/) do
17
17
  end
18
18
 
19
19
  #step to resize browser
20
- Then(/^I resize browser with width (\d+) and heigth (\d+)$/) do |width, heigth|
21
- resize_browser(width,heigth)
20
+ Then(/^I resize browser window size to width (\d+) and heigth (\d+)$/) do |width, heigth|
21
+ resize_browser(width, heigth)
22
22
  end
23
23
 
24
24
  #steps to refresh page
@@ -26,11 +26,16 @@ Then(/^I refresh page$/) do
26
26
  $driver.navigate.refresh
27
27
  end
28
28
 
29
-
30
29
  #steps to scroll to element
31
- Then(/^I scroll to the element having (.+) "(.*?)"$/) do |type, access_name|
30
+ Then(/^I scroll to element having (.+) "(.*?)"$/) do |type, access_name|
32
31
  validate_locator type
33
- scroll_to_element(type,access_name)
32
+ scroll_to_element(type, access_name)
33
+ end
34
+
35
+ #Step to hover over a element # Not work on windows firefox
36
+ When(/^I hover over element having (.+) "(.*?)"$/) do |type, access_name|
37
+ validate_locator type
38
+ hover_over_element(type, access_name)
34
39
  end
35
40
 
36
41
  #steps to zoom in page
@@ -1,5 +1,5 @@
1
1
  module Selenium
2
2
  module Cucumber
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-16 00:00:00.000000000 Z
12
+ date: 2014-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -59,7 +59,6 @@ files:
59
59
  - lib/selenium-cucumber/input_steps.rb
60
60
  - lib/selenium-cucumber/javascript_handling_steps.rb
61
61
  - lib/selenium-cucumber/navigation_steps.rb
62
- - lib/selenium-cucumber/press_button_steps.rb
63
62
  - lib/selenium-cucumber/progress_steps.rb
64
63
  - lib/selenium-cucumber/screenshot_steps.rb
65
64
  - lib/selenium-cucumber/version.rb
@@ -70,7 +69,6 @@ files:
70
69
  - lib/selenium-cucumber/methods/javascript_handling_methods.rb
71
70
  - lib/selenium-cucumber/methods/misc_methods.rb
72
71
  - lib/selenium-cucumber/methods/navigate_methods.rb
73
- - lib/selenium-cucumber/methods/press_button_methods.rb
74
72
  - lib/selenium-cucumber/methods/progress_methods.rb
75
73
  - lib/selenium-cucumber/methods/required_files.rb
76
74
  - lib/selenium-cucumber/methods/screenshot_methods.rb
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- require "selenium-webdriver"
3
-
4
- def click(access_type,access_name)
5
- element = $driver.find_element(:"#{access_type}" => "#{access_name}").click
6
- end
@@ -1,19 +0,0 @@
1
- require_relative 'methods/press_button_methods'
2
-
3
- # click on web element
4
-
5
- When(/^I click on element having (.+) "(.*?)"$/) do |type, access_name|
6
- validate_locator type
7
- click(type,access_name)
8
- end
9
-
10
-
11
- #steps to click on link
12
-
13
- Then(/^I click on link having text "(.*?)"$/) do |access_name|
14
- click("link",access_name)
15
- end
16
-
17
- Then(/^I click on link having partial text "(.*?)"$/) do |access_name|
18
- click("partial_link_text",access_name)
19
- end