testcentricity 2.3.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +93 -0
  8. data/LICENSE.txt +28 -0
  9. data/README.md +1634 -0
  10. data/Rakefile +1 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/devices/devices.yml +344 -0
  14. data/lib/testcentricity.rb +144 -0
  15. data/lib/testcentricity/app_core/appium_connect_helper.rb +154 -0
  16. data/lib/testcentricity/app_core/appium_server.rb +69 -0
  17. data/lib/testcentricity/app_core/screen_objects_helper.rb +180 -0
  18. data/lib/testcentricity/app_core/screen_sections_helper.rb +332 -0
  19. data/lib/testcentricity/app_elements/app_element_helper.rb +293 -0
  20. data/lib/testcentricity/app_elements/button.rb +8 -0
  21. data/lib/testcentricity/app_elements/checkbox.rb +20 -0
  22. data/lib/testcentricity/app_elements/label.rb +8 -0
  23. data/lib/testcentricity/app_elements/list.rb +25 -0
  24. data/lib/testcentricity/app_elements/switch.rb +20 -0
  25. data/lib/testcentricity/app_elements/textfield.rb +12 -0
  26. data/lib/testcentricity/browser_helper.rb +174 -0
  27. data/lib/testcentricity/data_objects/data_objects_helper.rb +78 -0
  28. data/lib/testcentricity/data_objects/environment.rb +281 -0
  29. data/lib/testcentricity/data_objects/excel_helper.rb +242 -0
  30. data/lib/testcentricity/exception_queue_helper.rb +51 -0
  31. data/lib/testcentricity/utility_helpers.rb +28 -0
  32. data/lib/testcentricity/version.rb +3 -0
  33. data/lib/testcentricity/web_core/drag_drop_helper.rb +15 -0
  34. data/lib/testcentricity/web_core/page_objects_helper.rb +669 -0
  35. data/lib/testcentricity/web_core/page_sections_helper.rb +866 -0
  36. data/lib/testcentricity/web_core/webdriver_helper.rb +579 -0
  37. data/lib/testcentricity/web_elements/button.rb +8 -0
  38. data/lib/testcentricity/web_elements/cell_button.rb +8 -0
  39. data/lib/testcentricity/web_elements/cell_checkbox.rb +38 -0
  40. data/lib/testcentricity/web_elements/cell_element.rb +69 -0
  41. data/lib/testcentricity/web_elements/cell_image.rb +8 -0
  42. data/lib/testcentricity/web_elements/cell_radio.rb +31 -0
  43. data/lib/testcentricity/web_elements/checkbox.rb +100 -0
  44. data/lib/testcentricity/web_elements/file_field.rb +45 -0
  45. data/lib/testcentricity/web_elements/image.rb +34 -0
  46. data/lib/testcentricity/web_elements/label.rb +8 -0
  47. data/lib/testcentricity/web_elements/link.rb +8 -0
  48. data/lib/testcentricity/web_elements/list.rb +73 -0
  49. data/lib/testcentricity/web_elements/list_button.rb +8 -0
  50. data/lib/testcentricity/web_elements/list_checkbox.rb +38 -0
  51. data/lib/testcentricity/web_elements/list_element.rb +61 -0
  52. data/lib/testcentricity/web_elements/list_radio.rb +31 -0
  53. data/lib/testcentricity/web_elements/radio.rb +74 -0
  54. data/lib/testcentricity/web_elements/select_list.rb +197 -0
  55. data/lib/testcentricity/web_elements/siebel_open_ui_helper.rb +15 -0
  56. data/lib/testcentricity/web_elements/table.rb +612 -0
  57. data/lib/testcentricity/web_elements/textfield.rb +114 -0
  58. data/lib/testcentricity/web_elements/ui_elements_helper.rb +502 -0
  59. data/lib/testcentricity/world_extensions.rb +26 -0
  60. data/my_templates/default/method_details/setup.rb +3 -0
  61. data/spec/spec_helper.rb +14 -0
  62. data/spec/testcentricity_spec.rb +9 -0
  63. data/testcentricity.gemspec +47 -0
  64. metadata +328 -0
@@ -0,0 +1,579 @@
1
+ require 'selenium-webdriver'
2
+ require 'os'
3
+ require 'browserstack/local'
4
+
5
+
6
+ module TestCentricity
7
+ module WebDriverConnect
8
+ include Capybara::DSL
9
+
10
+ attr_accessor :webdriver_path
11
+ attr_accessor :bs_local
12
+
13
+ def self.initialize_web_driver(app_host = nil)
14
+ Capybara.app_host = app_host unless app_host.nil?
15
+ browser = ENV['WEB_BROWSER']
16
+
17
+ # assume that we're testing within a local desktop web browser
18
+ Environ.driver = :webdriver
19
+ Environ.platform = :desktop
20
+ Environ.browser = browser
21
+ Environ.device = :web
22
+ Environ.device_name = 'browser'
23
+
24
+ case browser.downcase.to_sym
25
+ when :appium
26
+ initialize_appium
27
+ context = 'mobile device emulator'
28
+ when :browserstack
29
+ initialize_browserstack
30
+ context = 'Browserstack cloud service'
31
+ when :crossbrowser
32
+ initialize_crossbrowser
33
+ context = 'CrossBrowserTesting cloud service'
34
+ when :poltergeist
35
+ initialize_poltergeist
36
+ context = 'PhantomJS'
37
+ when :saucelabs
38
+ initialize_saucelabs
39
+ context = 'Sauce Labs cloud service'
40
+ when :testingbot
41
+ initialize_testingbot
42
+ context = 'TestingBot cloud service'
43
+ else
44
+ if ENV['SELENIUM'] == 'remote'
45
+ initialize_remote
46
+ context = 'Selenium Grid2'
47
+ else
48
+ initialize_local_browser
49
+ context = 'local instance'
50
+ end
51
+ end
52
+
53
+ # set browser window size only if testing with a desktop web browser
54
+ unless Environ.is_device? || [:poltergeist, :appium].include?(Capybara.current_driver)
55
+ initialize_browser_size
56
+ end
57
+
58
+ Environ.session_state = :running
59
+ puts "Using #{Environ.browser} browser via #{context}"
60
+ end
61
+
62
+ def self.set_domain(url)
63
+ Capybara.app_host = url
64
+ end
65
+
66
+ # Set the WebDriver path for Chrome, Firefox, IE, or Edge browsers
67
+ def self.set_webdriver_path(project_path)
68
+ path_to_driver = nil
69
+ # check for existence of /webdrivers or /features/support/drivers folders
70
+ base_path = 'features/support/drivers'
71
+ unless File.directory?(File.join(project_path, base_path))
72
+ base_path = 'webdrivers'
73
+ unless File.directory?(File.join(project_path, base_path))
74
+ raise 'Could not find WebDriver files in /webdrivers or /features/support/drivers folders'
75
+ end
76
+ end
77
+ # set WebDriver path based on browser and operating system
78
+ case ENV['WEB_BROWSER'].downcase.to_sym
79
+ when :chrome
80
+ if OS.osx?
81
+ path_to_driver = 'mac/chromedriver'
82
+ elsif OS.windows?
83
+ path_to_driver = 'windows/chromedriver.exe'
84
+ end
85
+ @webdriver_path = File.join(project_path, base_path, path_to_driver)
86
+ Selenium::WebDriver::Chrome.driver_path = @webdriver_path
87
+ # when :firefox
88
+ # if OS.osx?
89
+ # path_to_driver = 'mac/geckodriver'
90
+ # elsif OS.windows?
91
+ # path_to_driver = 'windows/geckodriver.exe'
92
+ # end
93
+ # @webdriver_path = File.join(project_path, base_path, path_to_driver)
94
+ # Selenium::WebDriver::Firefox.driver_path = @webdriver_path
95
+ when :ie
96
+ path_to_driver = 'windows/IEDriverServer.exe'
97
+ @webdriver_path = File.join(project_path, base_path, path_to_driver)
98
+ Selenium::WebDriver::IE.driver_path = @webdriver_path
99
+ when :edge
100
+ path_to_driver = 'windows/MicrosoftWebDriver.exe'
101
+ @webdriver_path = File.join(project_path, base_path, path_to_driver)
102
+ Selenium::WebDriver::Edge.driver_path = @webdriver_path
103
+ else
104
+ if ENV['HOST_BROWSER']
105
+ case ENV['HOST_BROWSER'].downcase.to_sym
106
+ when :chrome
107
+ if OS.osx?
108
+ path_to_driver = 'mac/chromedriver'
109
+ elsif OS.windows?
110
+ path_to_driver = 'windows/chromedriver.exe'
111
+ end
112
+ @webdriver_path = File.join(project_path, base_path, path_to_driver)
113
+ Selenium::WebDriver::Chrome.driver_path = @webdriver_path
114
+ # when :firefox
115
+ # if OS.osx?
116
+ # path_to_driver = 'mac/geckodriver'
117
+ # elsif OS.windows?
118
+ # path_to_driver = 'windows/geckodriver.exe'
119
+ # end
120
+ # @webdriver_path = File.join(project_path, base_path, path_to_driver)
121
+ # Selenium::WebDriver::Firefox.driver_path = @webdriver_path
122
+ end
123
+ end
124
+ end
125
+ puts "The webdriver path is: #{@webdriver_path}" unless path_to_driver.nil?
126
+ end
127
+
128
+ def self.initialize_browser_size
129
+ # tile browser windows if running in multiple parallel threads and BROWSER_TILE environment variable is true
130
+ if ENV['PARALLEL'] && ENV['BROWSER_TILE']
131
+ thread = ENV['TEST_ENV_NUMBER'].to_i
132
+ if thread > 1
133
+ Browsers.set_browser_window_position(100 * thread - 1, 100 * thread - 1)
134
+ sleep(1)
135
+ end
136
+ else
137
+ Browsers.set_browser_window_position(10, 10)
138
+ sleep(1)
139
+ end
140
+
141
+ browser = Environ.browser.to_s
142
+ if Environ.is_desktop?
143
+ if ENV['BROWSER_SIZE'] == 'max'
144
+ Browsers.maximize_browser
145
+ elsif ENV['BROWSER_SIZE']
146
+ Browsers.set_browser_window_size(ENV['BROWSER_SIZE'])
147
+ else
148
+ Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
149
+ end
150
+ elsif Environ.is_mobile? && !Environ.is_device?
151
+ Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
152
+ end
153
+ Environ.session_state = :running
154
+ end
155
+
156
+ def self.close_tunnel
157
+ unless @bs_local.nil?
158
+ @bs_local.stop
159
+ if @bs_local.isRunning
160
+ raise 'BrowserStack Local instance could not be stopped'
161
+ else
162
+ puts 'BrowserStack Local instance has been stopped'
163
+ end
164
+ end
165
+ end
166
+
167
+ private
168
+
169
+ def self.initialize_appium
170
+ Environ.platform = :mobile
171
+ Environ.device_name = ENV['APP_DEVICE']
172
+ Environ.device_os = ENV['APP_PLATFORM_NAME']
173
+ Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
174
+ Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
175
+ Capybara.default_driver = :appium
176
+ endpoint = 'http://localhost:4723/wd/hub'
177
+ desired_capabilities = {
178
+ platformName: ENV['APP_PLATFORM_NAME'],
179
+ platformVersion: ENV['APP_VERSION'],
180
+ browserName: ENV['APP_BROWSER'],
181
+ deviceName: ENV['APP_DEVICE']
182
+ }
183
+ desired_capabilities[:avd] = ENV['APP_DEVICE'] if ENV['APP_PLATFORM_NAME'].downcase.to_sym == :android
184
+ desired_capabilities[:automationName] = ENV['AUTOMATION_ENGINE'] if ENV['AUTOMATION_ENGINE']
185
+ desired_capabilities[:orientation] = ENV['ORIENTATION'].upcase if ENV['ORIENTATION']
186
+ if ENV['UDID']
187
+ Environ.device = :device
188
+ desired_capabilities[:udid] = ENV['UDID']
189
+ desired_capabilities[:startIWDP] = true
190
+ desired_capabilities[:xcodeOrgId] = ENV['TEAM_ID'] if ENV['TEAM_ID']
191
+ desired_capabilities[:xcodeSigningId] = ENV['TEAM_NAME'] if ENV['TEAM_NAME']
192
+ else
193
+ Environ.device = :simulator
194
+ end
195
+ desired_capabilities[:safariInitialUrl] = ENV['APP_INITIAL_URL'] if ENV['APP_INITIAL_URL']
196
+ desired_capabilities[:safariAllowPopups] = ENV['APP_ALLOW_POPUPS'] if ENV['APP_ALLOW_POPUPS']
197
+ desired_capabilities[:safariIgnoreFraudWarning] = ENV['APP_IGNORE_FRAUD_WARNING'] if ENV['APP_IGNORE_FRAUD_WARNING']
198
+ desired_capabilities[:noReset] = ENV['APP_NO_RESET'] if ENV['APP_NO_RESET']
199
+ desired_capabilities[:language] = ENV['LANGUAGE'] if ENV['LANGUAGE']
200
+ desired_capabilities[:locale] = ENV['LOCALE'].gsub('-', '_') if ENV['LOCALE']
201
+
202
+ Capybara.register_driver :appium do |app|
203
+ appium_lib_options = { server_url: endpoint }
204
+ all_options = {
205
+ appium_lib: appium_lib_options,
206
+ caps: desired_capabilities
207
+ }
208
+ Appium::Capybara::Driver.new app, all_options
209
+ end
210
+ end
211
+
212
+ def self.initialize_local_browser
213
+ if OS.osx?
214
+ Environ.os = 'OS X'
215
+ elsif OS.windows?
216
+ Environ.os = 'Windows'
217
+ end
218
+
219
+ browser = ENV['WEB_BROWSER']
220
+
221
+ case browser.downcase.to_sym
222
+ when :firefox, :chrome, :ie, :safari, :edge
223
+ Environ.platform = :desktop
224
+ else
225
+ Environ.platform = :mobile
226
+ Environ.device_name = Browsers.mobile_device_name(browser)
227
+ end
228
+
229
+ Capybara.default_driver = :selenium
230
+ Capybara.register_driver :selenium do |app|
231
+ case browser.downcase.to_sym
232
+ when :ie, :safari, :edge
233
+ Capybara::Selenium::Driver.new(app, :browser => browser.to_sym)
234
+
235
+ when :firefox
236
+ if ENV['LOCALE']
237
+ profile = Selenium::WebDriver::Firefox::Profile.new
238
+ profile['intl.accept_languages'] = ENV['LOCALE']
239
+ Capybara::Selenium::Driver.new(app, :profile => profile)
240
+ else
241
+ Capybara::Selenium::Driver.new(app, :browser => :firefox)
242
+ end
243
+
244
+ when :chrome
245
+ ENV['LOCALE'] ? args = ['--disable-infobars', "--lang=#{ENV['LOCALE']}"] : args = ['--disable-infobars']
246
+ Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args)
247
+
248
+ else
249
+ user_agent = Browsers.mobile_device_agent(browser)
250
+ ENV['HOST_BROWSER'] ? host_browser = ENV['HOST_BROWSER'].downcase.to_sym : host_browser = :chrome
251
+ case host_browser
252
+ when :firefox
253
+ profile = Selenium::WebDriver::Firefox::Profile.new
254
+ profile['general.useragent.override'] = user_agent
255
+ profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
256
+ Capybara::Selenium::Driver.new(app, :profile => profile)
257
+
258
+ when :chrome
259
+ ENV['LOCALE'] ?
260
+ args = ["--user-agent='#{user_agent}'", "--lang=#{ENV['LOCALE']}", '--disable-infobars'] :
261
+ args = ["--user-agent='#{user_agent}'", '--disable-infobars']
262
+ Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args)
263
+ end
264
+ end
265
+ end
266
+ end
267
+
268
+ def self.new_initialize_local_browser
269
+ if OS.osx?
270
+ Environ.os = 'OS X'
271
+ elsif OS.windows?
272
+ Environ.os = 'Windows'
273
+ end
274
+
275
+ browser = ENV['WEB_BROWSER']
276
+
277
+ case browser.downcase.to_sym
278
+ when :firefox, :chrome, :ie, :safari, :edge
279
+ Environ.platform = :desktop
280
+ else
281
+ Environ.platform = :mobile
282
+ Environ.device_name = Browsers.mobile_device_name(browser)
283
+ end
284
+
285
+ Capybara.default_driver = :selenium
286
+ Capybara.register_driver :selenium do |app|
287
+ case browser.downcase.to_sym
288
+ when :ie, :safari, :edge
289
+ Capybara::Selenium::Driver.new(app, browser: browser.to_sym)
290
+ when :firefox
291
+ profile = Selenium::WebDriver::Firefox::Profile.new
292
+ profile['browser.download.dir'] = '/tmp/webdriver-downloads'
293
+ profile['browser.download.folderList'] = 2
294
+ profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv, application/x-msexcel, application/excel, application/x-excel, application/vnd.ms-excel, image/png, image/jpeg, text/html, text/plain, application/pdf, application/octet-stream'
295
+ profile['pdfjs.disabled'] = true
296
+ profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
297
+ options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
298
+ if @webdriver_path.blank?
299
+ Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
300
+ else
301
+ Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, driver_path: @webdriver_path)
302
+ end
303
+ when :chrome
304
+ options = Selenium::WebDriver::Chrome::Options.new
305
+ options.add_argument('--disable-infobars')
306
+ options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
307
+ Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
308
+ else
309
+ user_agent = Browsers.mobile_device_agent(browser)
310
+ ENV['HOST_BROWSER'] ? host_browser = ENV['HOST_BROWSER'].downcase.to_sym : host_browser = :firefox
311
+ case host_browser
312
+ when :firefox
313
+ profile = Selenium::WebDriver::Firefox::Profile.new
314
+ profile['general.useragent.override'] = user_agent
315
+ profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
316
+ options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
317
+ if @webdriver_path.blank?
318
+ Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
319
+ else
320
+ Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, driver_path: @webdriver_path)
321
+ end
322
+ when :chrome
323
+ options = Selenium::WebDriver::Chrome::Options.new
324
+ options.add_argument('--disable-infobars')
325
+ options.add_argument("--user-agent='#{user_agent}'")
326
+ options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
327
+ Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
328
+ end
329
+ end
330
+ end
331
+ end
332
+
333
+ def self.initialize_browserstack
334
+ browser = ENV['BS_BROWSER']
335
+
336
+ if ENV['BS_REAL_MOBILE'] || ENV['BS_PLATFORM']
337
+ Environ.platform = :mobile
338
+ Environ.device_name = ENV['BS_DEVICE']
339
+ Environ.device_os = ENV['BS_OS']
340
+ Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
341
+ elsif ENV['BS_OS']
342
+ Environ.os = "#{ENV['BS_OS']} #{ENV['BS_OS_VERSION']}"
343
+ end
344
+
345
+ endpoint = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub-cloud.browserstack.com/wd/hub"
346
+ Capybara.register_driver :browserstack do |app|
347
+ capabilities = Selenium::WebDriver::Remote::Capabilities.new
348
+
349
+ if ENV['BS_REAL_MOBILE']
350
+ Environ.device = :device
351
+ capabilities['device'] = ENV['BS_DEVICE']
352
+ capabilities['realMobile'] = true
353
+ capabilities['os_version'] = ENV['BS_OS_VERSION']
354
+
355
+ elsif ENV['BS_PLATFORM']
356
+ Environ.device = :simulator
357
+ capabilities[:platform] = ENV['BS_PLATFORM']
358
+ capabilities[:browserName] = browser
359
+ capabilities['device'] = ENV['BS_DEVICE'] if ENV['BS_DEVICE']
360
+ capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
361
+
362
+ elsif ENV['BS_OS']
363
+ capabilities['os'] = ENV['BS_OS']
364
+ capabilities['os_version'] = ENV['BS_OS_VERSION']
365
+ capabilities['browser'] = browser || 'chrome'
366
+ capabilities['browser_version'] = ENV['BS_VERSION'] if ENV['BS_VERSION']
367
+ capabilities['resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
368
+ end
369
+
370
+ capabilities['browserstack.timezone'] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
371
+ capabilities['browserstack.video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
372
+ capabilities['browserstack.debug'] = 'true'
373
+ capabilities['project'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
374
+ capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
375
+
376
+ ENV['TEST_CONTEXT'] ?
377
+ context_message = "#{Environ.test_environment} - #{ENV['TEST_CONTEXT']}" :
378
+ context_message = Environ.test_environment
379
+ if ENV['PARALLEL']
380
+ thread_num = ENV['TEST_ENV_NUMBER']
381
+ thread_num = 1 if thread_num.blank?
382
+ context_message = "#{context_message} - Thread ##{thread_num}"
383
+ end
384
+ capabilities['name'] = context_message
385
+
386
+ capabilities['acceptSslCerts'] = 'true'
387
+ capabilities['browserstack.localIdentifier'] = ENV['BS_LOCAL_ID'] if ENV['BS_LOCAL_ID']
388
+ capabilities['browserstack.local'] = 'true' if ENV['TUNNELING']
389
+
390
+ case browser.downcase.to_sym
391
+ when :ie
392
+ capabilities['ie.ensureCleanSession'] = 'true'
393
+ capabilities['ie.browserCommandLineSwitches'] = 'true'
394
+ capabilities['nativeEvents'] = 'true'
395
+ when :safari
396
+ capabilities['cleanSession'] = 'true'
397
+ when :iphone, :ipad
398
+ capabilities['javascriptEnabled'] = 'true'
399
+ capabilities['cleanSession'] = 'true'
400
+ end
401
+
402
+ if ENV['TUNNELING']
403
+ @bs_local = BrowserStack::Local.new
404
+ bs_local_args = {'key' => "#{ENV['BS_AUTHKEY']}"}
405
+ @bs_local.start(bs_local_args)
406
+ if @bs_local.isRunning
407
+ puts 'BrowserStack Local instance has been started'
408
+ else
409
+ puts 'BrowserStack Local instance failed to start'
410
+ end
411
+ end
412
+
413
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
414
+ end
415
+
416
+ Environ.browser = browser
417
+ Environ.tunneling = ENV['TUNNELING'] if ENV['TUNNELING']
418
+ Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
419
+
420
+ Capybara.default_driver = :browserstack
421
+ Capybara.run_server = false
422
+ end
423
+
424
+ def self.initialize_crossbrowser
425
+ browser = ENV['CB_BROWSER']
426
+
427
+ if ENV['CB_OS']
428
+ Environ.os = ENV['CB_OS']
429
+ Environ.platform = :desktop
430
+ elsif ENV['CB_PLATFORM']
431
+ Environ.device_name = ENV['CB_PLATFORM']
432
+ Environ.device = :device
433
+ Environ.platform = :mobile
434
+ Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
435
+ end
436
+
437
+ endpoint = "http://#{ENV['CB_USERNAME']}:#{ENV['CB_AUTHKEY']}@hub.crossbrowsertesting.com:80/wd/hub"
438
+ Capybara.register_driver :crossbrowser do |app|
439
+ capabilities = Selenium::WebDriver::Remote::Capabilities.new
440
+ capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
441
+ capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
442
+ capabilities['browser_api_name'] = browser
443
+ capabilities['screen_resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
444
+ if ENV['CB_OS']
445
+ capabilities['os_api_name'] = ENV['CB_OS']
446
+ Environ.platform = :desktop
447
+ elsif ENV['CB_PLATFORM']
448
+ capabilities['os_api_name'] = ENV['CB_PLATFORM']
449
+ end
450
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
451
+ end
452
+
453
+ Environ.browser = browser
454
+
455
+ Capybara.default_driver = :crossbrowser
456
+ Capybara.run_server = false
457
+ end
458
+
459
+ def self.initialize_poltergeist
460
+ if ENV['BROWSER_SIZE']
461
+ resolution = ENV['BROWSER_SIZE'].split(',')
462
+ width = resolution[0]
463
+ height = resolution[1]
464
+ else
465
+ width = 1650
466
+ height = 1000
467
+ end
468
+ Capybara.default_driver = :poltergeist
469
+ Capybara.register_driver :poltergeist do |app|
470
+ options = {
471
+ js_errors: true,
472
+ timeout: 120,
473
+ debug: false,
474
+ phantomjs_options: ['--load-images=no', '--disk-cache=false'],
475
+ inspector: true,
476
+ window_size: [width, height]
477
+ }
478
+ Capybara::Poltergeist::Driver.new(app, options)
479
+ end
480
+ end
481
+
482
+ def self.initialize_remote
483
+ browser = ENV['WEB_BROWSER']
484
+ endpoint = ENV['REMOTE_ENDPOINT'] || 'http://127.0.0.1:4444/wd/hub'
485
+ capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser.downcase.to_sym)
486
+ Capybara.register_driver :remote_browser do |app|
487
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
488
+ end
489
+ Capybara.current_driver = :remote_browser
490
+ Capybara.default_driver = :remote_browser
491
+ end
492
+
493
+ def self.initialize_saucelabs
494
+ browser = ENV['SL_BROWSER']
495
+
496
+ if ENV['SL_OS']
497
+ Environ.platform = :desktop
498
+ Environ.os = ENV['SL_OS']
499
+ elsif ENV['SL_PLATFORM']
500
+ Environ.device_name = ENV['SL_DEVICE']
501
+ Environ.platform = :mobile
502
+ end
503
+
504
+ endpoint = "http://#{ENV['SL_USERNAME']}:#{ENV['SL_AUTHKEY']}@ondemand.saucelabs.com:80/wd/hub"
505
+ Capybara.register_driver :saucelabs do |app|
506
+ capabilities = Selenium::WebDriver::Remote::Capabilities.new
507
+ capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
508
+ capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
509
+ capabilities['browserName'] = browser
510
+ capabilities['version'] = ENV['SL_VERSION'] if ENV['SL_VERSION']
511
+ capabilities['screenResolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
512
+ capabilities['recordVideo'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
513
+ if ENV['SL_OS']
514
+ capabilities['platform'] = ENV['SL_OS']
515
+ elsif ENV['SL_PLATFORM']
516
+ capabilities['platform'] = ENV['SL_PLATFORM']
517
+ capabilities['deviceName'] = ENV['SL_DEVICE']
518
+ capabilities['deviceType'] = ENV['SL_DEVICE_TYPE'] if ENV['SL_DEVICE_TYPE']
519
+ capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
520
+ end
521
+
522
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
523
+ end
524
+
525
+ Environ.browser = browser
526
+
527
+ Capybara.default_driver = :saucelabs
528
+ Capybara.run_server = false
529
+ end
530
+
531
+ def self.initialize_testingbot
532
+ browser = ENV['TB_BROWSER']
533
+
534
+ Environ.os = ENV['TB_OS']
535
+ if ENV['TB_PLATFORM']
536
+ if ENV['ORIENTATION']
537
+ Environ.device_orientation = ENV['ORIENTATION']
538
+ end
539
+ Environ.device_os = ENV['TB_PLATFORM']
540
+ Environ.device_name = ENV['TB_DEVICE']
541
+ Environ.device = :device
542
+ Environ.platform = :mobile
543
+ Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
544
+ else
545
+ Environ.platform = :desktop
546
+ end
547
+
548
+ ENV['TUNNELING'] ?
549
+ endpoint = '@localhost:4445/wd/hub' :
550
+ endpoint = '@hub.testingbot.com:4444/wd/hub'
551
+ endpoint = "http://#{ENV['TB_USERNAME']}:#{ENV['TB_AUTHKEY']}#{endpoint}"
552
+ Capybara.register_driver :testingbot do |app|
553
+ capabilities = Selenium::WebDriver::Remote::Capabilities.new
554
+ capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
555
+ capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
556
+ capabilities['browserName'] = browser
557
+ capabilities['version'] = ENV['TB_VERSION'] if ENV['TB_VERSION']
558
+ capabilities['screen-resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
559
+ capabilities['platform'] = ENV['TB_OS']
560
+ capabilities['record_video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
561
+ if ENV['TB_PLATFORM']
562
+ if ENV['ORIENTATION']
563
+ capabilities['orientation'] = ENV['ORIENTATION']
564
+ end
565
+ capabilities['platformName'] = ENV['TB_PLATFORM']
566
+ capabilities['deviceName'] = ENV['TB_DEVICE']
567
+ end
568
+
569
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
570
+ end
571
+
572
+ Environ.browser = browser
573
+
574
+ Capybara.default_driver = :testingbot
575
+ Capybara.run_server = false
576
+
577
+ end
578
+ end
579
+ end