selenium-cucumber 1.1.2 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/doc/canned_steps.md +17 -0
  3. data/features-skeleton/support/env.rb +42 -29
  4. data/lib/selenium-cucumber.rb +0 -1
  5. data/lib/selenium-cucumber/assertion_steps.rb +6 -2
  6. data/lib/selenium-cucumber/click_elements_steps.rb +10 -0
  7. data/lib/selenium-cucumber/methods/assertion_methods.rb +78 -8
  8. data/lib/selenium-cucumber/methods/click_elements_methods.rb +8 -0
  9. data/lib/selenium-cucumber/methods/configuration_methods.rb +23 -2
  10. data/lib/selenium-cucumber/methods/error_handling_methods.rb +87 -0
  11. data/lib/selenium-cucumber/methods/misc_methods.rb +9 -0
  12. data/lib/selenium-cucumber/methods/navigate_methods.rb +5 -0
  13. data/lib/selenium-cucumber/methods/required_files.rb +2 -0
  14. data/lib/selenium-cucumber/navigation_steps.rb +4 -0
  15. data/lib/selenium-cucumber/version.rb +1 -1
  16. metadata +68 -51
  17. data/example/Gemfile +0 -5
  18. data/example/Gemfile.lock +0 -36
  19. data/example/features/actual_images/test.png +0 -0
  20. data/example/features/assertion_steps_Ex.feature +0 -149
  21. data/example/features/click_steps_Ex.feature +0 -28
  22. data/example/features/configuration_step_Ex.feature +0 -8
  23. data/example/features/expected_images/logo-PNG.png +0 -0
  24. data/example/features/expected_images/original_image.jpg +0 -0
  25. data/example/features/image_difference/test.png +0 -0
  26. data/example/features/input_steps_Ex.feature +0 -87
  27. data/example/features/javascript_steps_Ex.feature +0 -19
  28. data/example/features/navigation_steps_Ex.feature +0 -45
  29. data/example/features/new.feature +0 -17
  30. data/example/features/progress_step_Ex.feature +0 -18
  31. data/example/features/screenshot_step_Ex.feature +0 -12
  32. data/example/features/screenshots/test.png +0 -0
  33. data/example/features/step_definitions/custom_steps.rb +0 -14
  34. data/example/features/support/env.rb +0 -37
  35. data/example/features/support/hooks.rb +0 -34
  36. data/example/run_features.rb +0 -42
  37. data/example/test_page.html +0 -224
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d724e0e3ee3efebe417033b395869a70825c43e
4
- data.tar.gz: 495d6949f5db99ebc87562ae86ec07934b9c2cab
3
+ metadata.gz: 06ba324f137c7beac5a434968028ac9c2d841a71
4
+ data.tar.gz: c0b17d8c1fc7e82d63a7fd65bf712f6fa3ccb2fc
5
5
  SHA512:
6
- metadata.gz: 7017731725dc4ef15e1f550aaa8c757eaf208922330e914e2d5758e4412091120f2346a1179421bb64ee4f4289927fd07f411e7101a6c9d8337032ae10e644ea
7
- data.tar.gz: ea90be96b6aac6e26d62dce92b5cda714e664cdb2ce4ed9cd3d0dcb6d76a8e44ed65c67a0888e9fd7fad89b2018292d63324c7911117a6d007a423c28604d183
6
+ metadata.gz: 8057e8b7d347b508832c14a95d9170f4b20446b1333e3e5d5422e2e16e46e15ee2427fa911f2e6001b0827d6f3142c95d5910efbfa87619201fba37374040fe6
7
+ data.tar.gz: a42178e44886762fba3784f45d66170cd439705dbc4fc628e626576814ff56369525f12f03a72814a3e513228268660e04b976455fd32dc5f16c738415f57bed
@@ -20,6 +20,7 @@ To open/close URL and to navigate between pages use following steps :
20
20
  Then I navigate back
21
21
  Then I refresh page
22
22
  Then I switch to new window
23
+ Then I close new window
23
24
  Then I switch to previous window
24
25
 
25
26
  To interact with browser use following steps :
@@ -72,7 +73,11 @@ Assertion Steps
72
73
  To assert that page title can be found use following step :
73
74
 
74
75
  Then I should see page title as "(.*?)"
76
+ Then I should not see page title as "(.*?)"
75
77
 
78
+ Then I should see page title having partial text as "(.*?)"
79
+ Then I should not see page title having partial text as "(.*?)"
80
+
76
81
  #### Steps For Asserting Element Text
77
82
 
78
83
  To assert element text use any of the following steps :
@@ -520,3 +525,15 @@ Configuration Steps
520
525
  To print testing configuration use following step :
521
526
 
522
527
  Then I print configuration
528
+
529
+ #Mobile Steps
530
+
531
+ ##Tap Steps
532
+ -----------
533
+ To tap on app element use following steps :
534
+
535
+ Then I tap on element having id "(.*?)"
536
+ Then I tap on element having name "(.*?)"
537
+ Then I tap on element having class "(.*?)"
538
+ Then I tap on element having xpath "(.*?)"
539
+ Then I tap on element having css "(.*?)"
@@ -1,38 +1,51 @@
1
1
  require 'rubygems'
2
- require 'selenium-webdriver'
2
+ require 'selenium-cucumber'
3
3
 
4
- def print_error
5
- puts "\nInappropraite browser \"#{ENV['BROWSER']}\""
6
- puts "\nUsage : cucumber BROWSER=browser_name"
7
- puts "\nbrowser_name can be one of following :"
8
- puts "1.ie\n2.chrome\n3.ff\n4.safari\n5.opera"
9
- puts "\nNow using default browser \"Firefox\""
10
- end
4
+ # Store command line arguments
5
+ $browser_type = ENV['BROWSER'] || 'ff'
6
+ $platform = ENV['PLATFORM'] || 'desktop'
7
+ $os_version = ENV['OS_VERSION']
8
+ $device_name = ENV['DEVICE_NAME']
9
+ $udid = ENV['UDID']
10
+ $app_path = ENV['APP_PATH']
11
11
 
12
- case ENV['BROWSER']
13
- when 'ie'
14
- browser_type = :ie
15
- when 'ff'
16
- browser_type = :ff
17
- when 'chrome'
18
- browser_type = :chrome
19
- when 'opera'
20
- browser_type = :opera
21
- when 'safari'
22
- browser_type = :safari
23
- else
24
- if ENV['BROWSER']
25
- print_error
26
- end
27
- browser_type = :ff
28
- end
12
+ # check for valid parameters
13
+ validate_parameters $platform, $browser_type, $app_path
29
14
 
15
+ # If platform is android or ios create driver instance for mobile browser
16
+ if $platform == 'android' or $platform == 'iOS'
17
+
18
+ if $browser_type == 'native'
19
+ $browser_type = "Browser"
20
+ end
21
+
22
+ if $platform == 'android'
23
+ $device_name, $os_version = get_device_info
24
+ end
25
+
26
+ desired_caps = {
27
+ caps: {
28
+ platformName: $platform,
29
+ browserName: $browser_type,
30
+ versionNumber: $os_version,
31
+ deviceName: $device_name,
32
+ udid: $udid,
33
+ app: ".//#{$app_path}"
34
+ },
35
+ }
30
36
 
31
- begin
32
- $driver = Selenium::WebDriver.for(browser_type)
37
+ begin
38
+ $driver = Appium::Driver.new(desired_caps).start_driver
39
+ rescue Exception => e
40
+ puts e.message
41
+ Process.exit(0)
42
+ end
43
+ else # else create driver instance for desktop browser
44
+ begin
45
+ $driver = Selenium::WebDriver.for(:"#{$browser_type}")
33
46
  $driver.manage().window().maximize()
34
-
35
47
  rescue Exception => e
36
48
  puts e.message
49
+ Process.exit(0)
50
+ end
37
51
  end
38
-
@@ -1,2 +1 @@
1
-
2
1
  Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each { |file| require file }
@@ -1,8 +1,12 @@
1
1
  require_relative 'methods/assertion_methods'
2
2
 
3
3
  # page title checking
4
- Then(/^I should see page title as "(.*?)"$/) do |title|
5
- check_title(title)
4
+ Then(/^I should\s*((?:not)?)\s+see page title as "(.*?)"$/) do |present, title|
5
+ check_title(title, present.empty?)
6
+ end
7
+
8
+ Then(/^I should\s*((?:not)?)\s+see page title having partial text as "(.*?)"$/) do |present, partial_text_title|
9
+ check_partial_title(partial_text_title, present.empty?)
6
10
  end
7
11
 
8
12
  # step to check element text
@@ -25,3 +25,13 @@ end
25
25
  Then(/^I click on link having partial text "(.*?)"$/) do |access_name|
26
26
  click('partial_link_text', access_name)
27
27
  end
28
+
29
+ When(/^I tap on element having (.+) "(.*?)"$/) do |type, access_name|
30
+ validate_locator type
31
+ click(type, access_name)
32
+ end
33
+
34
+ Then(/^I long press on element having (.+) "(.*?)"$/) do |type, access_name|
35
+ validate_locator type
36
+ long_press(type, access_name, duration)
37
+ end
@@ -1,21 +1,57 @@
1
1
  require 'net/https'
2
2
  require_relative 'required_files'
3
3
 
4
- # Page title checking
4
+ # This file contains assertion methods which are called from assertion_steps.rb
5
+
6
+ # Method to return page title
5
7
  def get_page_title
6
8
  $driver.title
7
9
  end
8
10
 
9
- def check_title(title)
10
- raise TestCaseFailed, 'Page Title Not Matched' unless get_page_title == title
11
+ # Method to verify title
12
+ # param 1 : String : expected title
13
+ # param 2 : Boolean : test case [true or flase]
14
+ def check_title(title, test_case)
15
+ page_title = get_page_title
16
+ if test_case
17
+ if page_title != "#{title}"
18
+ raise TestCaseFailed, "Page Title Not Matched, Actual Page Title : #{page_title}"
19
+ end
20
+ else
21
+ if page_title == "#{title}"
22
+ raise TestCaseFailed, "Page Title Matched, Actual Page Title:#{page_title}"
23
+ end
24
+ end
25
+ end
26
+
27
+ # Method to verify partial title
28
+ # param 1 : String : partial title string
29
+ # param 2 : Boolean : test case [true or flase]
30
+ def check_partial_title(partial_text_title, test_case)
31
+ page_title = get_page_title
32
+ if test_case
33
+ if not page_title.include? "#{partial_text_title}"
34
+ raise TestCaseFailed, 'Partial Page Title Not Present'
35
+ end
36
+ else
37
+ if page_title.include? "#{partial_text_title}"
38
+ raise TestCaseFailed, 'Page Title Matched'
39
+ end
40
+ end
11
41
  end
12
42
 
13
43
  # Method to get element text
44
+ # param 1 : String : Locator type (id, name, class, xpath, css)
45
+ # param 2 : String : Locator value
14
46
  def get_element_text(access_type, access_name)
15
47
  WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.text
16
48
  end
17
49
 
18
50
  # Method to check element text
51
+ # param 1 : String : Locator type (id, name, class, xpath, css)
52
+ # param 2 : String : Expected element text
53
+ # param 3 : String : Locator value
54
+ # param 4 : Boolean : test case [true or flase]
19
55
  def check_element_text(access_type, actual_value, access_name, test_case)
20
56
  element_text = get_element_text(access_type, access_name)
21
57
 
@@ -31,6 +67,10 @@ def check_element_text(access_type, actual_value, access_name, test_case)
31
67
  end
32
68
 
33
69
  # Method to check partial element text
70
+ # param 1 : String : Locator type (id, name, class, xpath, css)
71
+ # param 2 : String : Expected element partial text
72
+ # param 3 : String : Locator value
73
+ # param 4 : Boolean : test case [true or flase]
34
74
  def check_element_partial_text(access_type, actual_value, access_name, test_case)
35
75
  element_text = get_element_text(access_type, access_name)
36
76
 
@@ -46,11 +86,16 @@ def check_element_partial_text(access_type, actual_value, access_name, test_case
46
86
  end
47
87
 
48
88
  # Method to return element status - enabled?
89
+ # param 1 : String : Locator type (id, name, class, xpath, css)
90
+ # param 2 : String : Locator value
49
91
  def is_element_enabled(access_type, access_name)
50
92
  WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.enabled?
51
93
  end
52
94
 
53
95
  # Element enabled checking
96
+ # param 1 : String : Locator type (id, name, class, xpath, css)
97
+ # param 2 : String : Expected element text
98
+ # param 4 : Boolean : test case [true or flase]
54
99
  def check_element_enable(access_type, access_name, test_case)
55
100
  result = is_element_enabled(access_type, access_name)
56
101
 
@@ -62,11 +107,19 @@ def check_element_enable(access_type, access_name, test_case)
62
107
  end
63
108
 
64
109
  # method to get attribute value
110
+ # param 1 : String : Locator type (id, name, class, xpath, css)
111
+ # param 2 : String : Expected element text
112
+ # param 3 : String : atrribute name
65
113
  def get_element_attribute(access_type, access_name, attribute_name)
66
114
  WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.attribute("#{attribute_name}")
67
115
  end
68
116
 
69
117
  # method to check attribute value
118
+ # param 1 : String : Locator type (id, name, class, xpath, css)
119
+ # param 2 : String : atrribute name
120
+ # param 3 : String : atrribute value
121
+ # param 4 : String : Locator value
122
+ # param 5 : Boolean : test case [true or flase]
70
123
  def check_element_attribute(access_type, attribute_name, attribute_value, access_name, test_case)
71
124
 
72
125
  attr_val = get_element_attribute(access_type, access_name, attribute_name)
@@ -83,11 +136,16 @@ def check_element_attribute(access_type, attribute_name, attribute_value, access
83
136
  end
84
137
 
85
138
  # method to get element status - displayed?
139
+ # param 1 : String : Locator type (id, name, class, xpath, css)
140
+ # param 2 : String : Locator value
86
141
  def is_element_displayed(access_type, access_name)
87
142
  WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.displayed?
88
143
  end
89
144
 
90
145
  # method to check element presence
146
+ # param 1 : String : Locator type (id, name, class, xpath, css)
147
+ # param 2 : String : Locator value
148
+ # param 3 : Boolean : test case [true or flase]
91
149
  def check_element_presence(access_type, access_name, test_case)
92
150
  if test_case
93
151
  if !is_element_displayed(access_type, access_name)
@@ -96,10 +154,10 @@ def check_element_presence(access_type, access_name, test_case)
96
154
  else
97
155
  begin
98
156
  if is_element_displayed(access_type, access_name)
99
- raise 'Present'
157
+ raise 'Present' # since it is negative test and we found element
100
158
  end
101
159
  rescue Exception => e
102
- if e.message == 'Present'
160
+ if e.message == 'Present' # only raise if it present
103
161
  raise TestCaseFailed, 'Element Present'
104
162
  end
105
163
  end
@@ -107,6 +165,9 @@ def check_element_presence(access_type, access_name, test_case)
107
165
  end
108
166
 
109
167
  # method to assert checkbox check/uncheck
168
+ # param 1 : String : Locator type (id, name, class, xpath, css)
169
+ # param 2 : String : Locator value
170
+ # param 3 : Boolean : test case [true or flase]
110
171
  def is_checkbox_checked(access_type, access_name, should_be_checked = true)
111
172
  checkbox = WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }
112
173
 
@@ -118,6 +179,9 @@ def is_checkbox_checked(access_type, access_name, should_be_checked = true)
118
179
  end
119
180
 
120
181
  # method to assert radio button selected/unselected
182
+ # param 1 : String : Locator type (id, name, class, xpath, css)
183
+ # param 2 : String : Locator value
184
+ # param 3 : Boolean : test case [true or flase]
121
185
  def is_radio_button_selected(access_type, access_name, should_be_selected = true)
122
186
  radio_button = WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }
123
187
 
@@ -180,6 +244,10 @@ def does_images_similar?(actual_img_access_type, actual_img_access_name, excp_im
180
244
  end
181
245
 
182
246
  # Method to compare two images
247
+ # param 1 : String : Locator type (id, name, class, xpath, css, url)
248
+ # param 2 : String : Locator value
249
+ # param 3 : String : Locator type (id, name, class, xpath, css, url, image_name)
250
+ # param 4 : String : Locator value
183
251
  def compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
184
252
  if actual_img_access_type == 'url'
185
253
  actual_img_url = actual_img_access_name
@@ -195,10 +263,12 @@ def compare_image(actual_img_access_type, actual_img_access_name, excp_img_acces
195
263
  expected_img_url = get_element_attribute(excp_img_access_type, excp_img_access_name, 'src')
196
264
  end
197
265
 
266
+ # replace 'https' with 'http' from actual image url
198
267
  if actual_img_url.include? 'https'
199
268
  actual_img_url['https'] = 'http'
200
269
  end
201
270
 
271
+ # replace 'https' with 'http' from expected image url
202
272
  if expected_img_url.include? 'https'
203
273
  expected_img_url['https'] = 'http'
204
274
  end
@@ -209,14 +279,14 @@ def compare_image(actual_img_access_type, actual_img_access_name, excp_img_acces
209
279
  image_type = 'jpg'
210
280
  end
211
281
 
212
- # Storing actual image locally
282
+ # Storing actual image locally
213
283
  open('./features/actual_images/actual_image.' + image_type, 'wb') do |file|
214
284
  file << open(actual_img_url).read
215
285
  end
216
286
 
217
287
  actual_img_url = './features/actual_images/actual_image.' + image_type
218
288
 
219
- # Storing Expected image locally
289
+ # Storing Expected image locally
220
290
  if excp_img_access_type != 'image_name'
221
291
  open('./features/expected_images/expected_image.' + image_type, 'wb') do |file|
222
292
  file << open(expected_img_url).read
@@ -224,7 +294,7 @@ def compare_image(actual_img_access_type, actual_img_access_name, excp_img_acces
224
294
  expected_img_url = './features/expected_images/expected_image.' + image_type
225
295
  end
226
296
 
227
- # Verify image extension and call respective compare function
297
+ # Verify image extension and call respective compare function
228
298
  if image_type == 'png'
229
299
  return compare_png_images(expected_img_url, actual_img_url)
230
300
  end
@@ -17,3 +17,11 @@ end
17
17
  def submit(access_type, access_name)
18
18
  WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.submit
19
19
  end
20
+
21
+ def long_press(type, access_name, duration)
22
+ element = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
23
+ parameters = { "element" => "#{element}", "duration" => "#{duration}" }
24
+ args = parameters.select { |k, v| [:element, :duration].include? k }
25
+ args = args_with_ele_ref(args)
26
+ chain_method(:longPress, args)
27
+ end
@@ -1,14 +1,35 @@
1
1
  require_relative 'required_files'
2
2
 
3
3
  # method to print configuration
4
-
5
4
  def print_congifugartion
6
5
  puts ''
7
6
  puts "Date : #{Time.now.strftime("%d-%B-%Y")}"
8
7
  puts "Time : #{Time.now.strftime("%I:%M:%S:%p")}"
9
- puts 'Operating System : ' + Selenium::WebDriver::Platform.os.to_s.upcase
8
+
9
+ if $platform == 'android' or $platform == 'ios'
10
+ print_mobile_configuration
11
+ else
12
+ print_desktop_configuration
13
+ end
14
+ end
15
+
16
+ # method to print desktop configuration
17
+ def print_desktop_configuration
18
+ puts 'Platform : ' + Selenium::WebDriver::Platform.os.to_s.upcase
10
19
  puts 'Browser : ' + $driver.capabilities.browser_name.to_s.upcase + " " + $driver.capabilities.version.to_s
11
20
  puts ''
12
21
  end
13
22
 
23
+ # method to print mobile configuration
24
+ def print_mobile_configuration
25
+ puts "Platform : #{$platform.upcase}"
26
+ puts "OS version : #{$os_version}"
27
+ puts "Device : #{$device_name}"
14
28
 
29
+ if $app_path.nil?
30
+ puts 'Browser : ' + $driver.capabilities.browser_name.to_s.upcase + " " + $driver.capabilities.version.to_s
31
+ else
32
+ puts "App Tested : #{$app_path}"
33
+ end
34
+ puts ''
35
+ end
@@ -0,0 +1,87 @@
1
+ # Error handling methods
2
+
3
+ # Method to check browser type
4
+ def validate_parameters(platform, browser_type, app_path)
5
+ if platform == 'desktop'
6
+ if !%w(ff ie chrome safari opera).include? browser_type
7
+ print_error_desktop
8
+ end
9
+ elsif platform == 'android'
10
+ print_error_android browser_type, app_path
11
+ elsif platform == 'iOS'
12
+ puts "Not Implemented..."
13
+ # print_error_ios browser_type, app_path
14
+ else
15
+ print_invalid_platform
16
+ end
17
+ end
18
+
19
+ # print error for desktop
20
+ def print_error_desktop
21
+ puts "\nInappropraite desktop browser : \"#{ENV['BROWSER']}\""
22
+ puts "\nUsage : cucumber BROWSER=browser_name"
23
+ puts "\nBrowser Supported :\n"
24
+ puts "\n1.ie\n2.chrome\n3.ff\n4.safari\n5.opera"
25
+ Process.exit(0)
26
+ end
27
+
28
+ # print error for android
29
+ def print_error_android(browser_type, app_path)
30
+ if browser_type=='ff' and app_path==nil
31
+ puts "\nOops... not mentioned \"Browser\" or \"App path\""
32
+ print_error_android_app
33
+ print_error_android_web
34
+ Process.exit(0)
35
+ elsif browser_type!='ff' and !%w(native chrome).include? browser_type
36
+ puts "\nOops... not supported browser"
37
+ print_error_android_web
38
+ Process.exit(0)
39
+ end
40
+ end
41
+
42
+ # print error for android app
43
+ def print_error_android_app
44
+ puts "\nTo run test on android app"
45
+ puts "\n Usage : cucumber PLATFORM=android APP_PATH=path/to/app"
46
+ end
47
+
48
+ # print error for android web
49
+ def print_error_android_web
50
+ puts "\nTo run test on android mobile web"
51
+ puts "\n Usage : cucumber PLATFORM=android BROWSER=browser_name"
52
+ puts "\n Supported browsers are \"chrome\" and \"native\""
53
+ end
54
+
55
+ # print error for ios
56
+ def print_error_ios
57
+ if browser_type=='ff' and app_path==nil
58
+ puts "\nOops... not mentioned \"Browser\" or \"App path\""
59
+ print_error_ios_app
60
+ print_error_ios_web
61
+ Process.exit(0)
62
+ elsif browser_type!='safari'
63
+ puts "\nOops... not supported browser"
64
+ print_error_ios_app_web
65
+ Process.exit(0)
66
+ end
67
+ end
68
+
69
+ # print error for ios app
70
+ def print_error_ios_app
71
+ puts "\nTo run test on iOS App"
72
+ puts "\n Usage : cucumber PLATFORM=iOS APP_PATH=path/to/app"
73
+ end
74
+
75
+ # print error for ios web
76
+ def print_error_ios_web
77
+ puts "\nTo run test on iOS mobile web"
78
+ puts "\n Usage : cucumber PLATFORM=iOS BROWSER=safari"
79
+ end
80
+
81
+ # print error if invalid platform
82
+ def print_invalid_platform
83
+ puts "\nOops... Invalid Platform"
84
+ puts "\nSupported platform are \"android\" and \"iOS\"."
85
+ puts "\nTo run on Desktop no need to mention platform."
86
+ Process.exit(0)
87
+ end