testcentricity_web 4.0.3 → 4.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,16 +11,18 @@ module TestCentricity
11
11
 
12
12
  attr_accessor :bs_local
13
13
  attr_accessor :downloads_path
14
+ attr_accessor :endpoint
15
+ attr_accessor :capabilities
14
16
 
15
17
  def self.initialize_web_driver(options = nil)
16
- desired_caps = nil
17
- merge_caps = nil
18
+ @endpoint = nil
19
+ @capabilities = nil
18
20
  if options.is_a?(String)
19
21
  Capybara.app_host = options
20
22
  elsif options.is_a?(Hash)
21
23
  Capybara.app_host = options[:app_host] if options.key?(:app_host)
22
- desired_caps = options[:desired_capabilities] if options.key?(:desired_capabilities)
23
- merge_caps = options[:merge_capabilities] if options.key?(:merge_capabilities)
24
+ @endpoint = options[:endpoint] if options.key?(:endpoint)
25
+ @capabilities = options[:desired_capabilities] if options.key?(:desired_capabilities)
24
26
  end
25
27
 
26
28
  browser = ENV['WEB_BROWSER']
@@ -46,25 +48,19 @@ module TestCentricity
46
48
 
47
49
  context = case browser.downcase.to_sym
48
50
  when :appium
49
- initialize_appium(desired_caps, merge_caps)
51
+ initialize_appium
50
52
  'mobile device emulator'
51
53
  when :browserstack
52
- initialize_browserstack(desired_caps, merge_caps)
54
+ initialize_browserstack
53
55
  'Browserstack cloud service'
54
- when :crossbrowser
55
- initialize_crossbrowser(desired_caps, merge_caps)
56
- 'CrossBrowserTesting cloud service'
57
- when :gridlastic
58
- initialize_gridlastic(desired_caps, merge_caps)
59
- 'Gridlastic cloud service'
60
56
  when :lambdatest
61
- initialize_lambdatest(desired_caps, merge_caps)
57
+ initialize_lambdatest
62
58
  'LambdaTest cloud service'
63
59
  when :saucelabs
64
- initialize_saucelabs(desired_caps, merge_caps)
60
+ initialize_saucelabs
65
61
  'Sauce Labs cloud service'
66
62
  when :testingbot
67
- initialize_testingbot(desired_caps, merge_caps)
63
+ initialize_testingbot
68
64
  'TestingBot cloud service'
69
65
  else
70
66
  if ENV['SELENIUM'] == 'remote'
@@ -77,7 +73,7 @@ module TestCentricity
77
73
  end
78
74
 
79
75
  # set browser window size only if testing with a desktop web browser
80
- unless Environ.is_device? || Capybara.current_driver == :appium
76
+ unless Environ.is_device? || Environ.is_simulator? || Capybara.current_driver == :appium
81
77
  initialize_browser_size
82
78
  end
83
79
 
@@ -133,7 +129,7 @@ module TestCentricity
133
129
 
134
130
  private
135
131
 
136
- def self.initialize_appium(desired_caps = nil, merge_caps = false)
132
+ def self.initialize_appium
137
133
  Environ.platform = :mobile
138
134
  Environ.device_name = ENV['APP_DEVICE']
139
135
  Environ.device_os = ENV['APP_PLATFORM_NAME'].downcase.to_sym
@@ -141,7 +137,7 @@ module TestCentricity
141
137
  Environ.device_os_version = ENV['APP_VERSION']
142
138
  Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
143
139
  Capybara.default_driver = :appium
144
- endpoint = 'http://localhost:4723/wd/hub'
140
+ @endpoint = 'http://localhost:4723/wd/hub' if @endpoint.nil?
145
141
  desired_capabilities = {
146
142
  platformName: Environ.device_os,
147
143
  platformVersion: Environ.device_os_version,
@@ -153,7 +149,6 @@ module TestCentricity
153
149
  if ENV['UDID']
154
150
  Environ.device = :device
155
151
  desired_capabilities[:udid] = ENV['UDID']
156
- desired_capabilities[:startIWDP] = true
157
152
  desired_capabilities[:xcodeOrgId] = ENV['TEAM_ID'] if ENV['TEAM_ID']
158
153
  desired_capabilities[:xcodeSigningId] = ENV['TEAM_NAME'] if ENV['TEAM_NAME']
159
154
  else
@@ -161,24 +156,26 @@ module TestCentricity
161
156
  desired_capabilities[:orientation] = Environ.device_orientation.upcase if Environ.device_orientation
162
157
  if Environ.device_os == :ios
163
158
  desired_capabilities[:language] = Environ.language if Environ.language
164
- desired_capabilities[:locale] = Environ.locale.gsub('-', '_') if Environ.locale
159
+ desired_capabilities[:locale] = Environ.locale.gsub('-', '_') if Environ.locale
165
160
  end
166
161
  end
167
162
  desired_capabilities[:safariIgnoreFraudWarning] = ENV['APP_IGNORE_FRAUD_WARNING'] if ENV['APP_IGNORE_FRAUD_WARNING']
168
- desired_capabilities[:safariInitialUrl] = ENV['APP_INITIAL_URL'] if ENV['APP_INITIAL_URL']
169
- desired_capabilities[:safariAllowPopups] = ENV['APP_ALLOW_POPUPS'] if ENV['APP_ALLOW_POPUPS']
170
-
171
- desired_capabilities[:autoAcceptAlerts] = ENV['AUTO_ACCEPT_ALERTS'] if ENV['AUTO_ACCEPT_ALERTS']
172
- desired_capabilities[:autoDismissAlerts] = ENV['AUTO_DISMISS_ALERTS'] if ENV['AUTO_DISMISS_ALERTS']
173
- desired_capabilities[:isHeadless] = ENV['HEADLESS'] if ENV['HEADLESS']
174
-
175
- desired_capabilities[:newCommandTimeout] = ENV['NEW_COMMAND_TIMEOUT'] if ENV['NEW_COMMAND_TIMEOUT']
176
- desired_capabilities[:noReset] = ENV['APP_NO_RESET'] if ENV['APP_NO_RESET']
177
- desired_capabilities[:fullReset] = ENV['APP_FULL_RESET'] if ENV['APP_FULL_RESET']
178
- desired_capabilities[:webkitDebugProxyPort] = ENV['WEBKIT_DEBUG_PROXY_PORT'] if ENV['WEBKIT_DEBUG_PROXY_PORT']
179
- desired_capabilities[:webDriverAgentUrl] = ENV['WEBDRIVER_AGENT_URL'] if ENV['WEBDRIVER_AGENT_URL']
180
- desired_capabilities[:usePrebuiltWDA] = ENV['USE_PREBUILT_WDA'] if ENV['USE_PREBUILT_WDA']
181
- desired_capabilities[:useNewWDA] = ENV['USE_NEW_WDA'] if ENV['USE_NEW_WDA']
163
+ desired_capabilities[:safariInitialUrl] = ENV['APP_INITIAL_URL'] if ENV['APP_INITIAL_URL']
164
+ desired_capabilities[:safariAllowPopups] = ENV['APP_ALLOW_POPUPS'] if ENV['APP_ALLOW_POPUPS']
165
+ desired_capabilities[:shutdownOtherSimulators] = ENV['SHUTDOWN_OTHER_SIMS'] if ENV['SHUTDOWN_OTHER_SIMS']
166
+ desired_capabilities[:forceSimulatorSoftwareKeyboardPresence] = ENV['SHOW_SIM_KEYBOARD'] if ENV['SHOW_SIM_KEYBOARD']
167
+
168
+ desired_capabilities[:autoAcceptAlerts] = ENV['AUTO_ACCEPT_ALERTS'] if ENV['AUTO_ACCEPT_ALERTS']
169
+ desired_capabilities[:autoDismissAlerts] = ENV['AUTO_DISMISS_ALERTS'] if ENV['AUTO_DISMISS_ALERTS']
170
+ desired_capabilities[:isHeadless] = ENV['HEADLESS'] if ENV['HEADLESS']
171
+
172
+ desired_capabilities[:newCommandTimeout] = ENV['NEW_COMMAND_TIMEOUT'] if ENV['NEW_COMMAND_TIMEOUT']
173
+ desired_capabilities[:noReset] = ENV['APP_NO_RESET'] if ENV['APP_NO_RESET']
174
+ desired_capabilities[:fullReset] = ENV['APP_FULL_RESET'] if ENV['APP_FULL_RESET']
175
+ desired_capabilities[:webkitDebugProxyPort] = ENV['WEBKIT_DEBUG_PROXY_PORT'] if ENV['WEBKIT_DEBUG_PROXY_PORT']
176
+ desired_capabilities[:webDriverAgentUrl] = ENV['WEBDRIVER_AGENT_URL'] if ENV['WEBDRIVER_AGENT_URL']
177
+ desired_capabilities[:usePrebuiltWDA] = ENV['USE_PREBUILT_WDA'] if ENV['USE_PREBUILT_WDA']
178
+ desired_capabilities[:useNewWDA] = ENV['USE_NEW_WDA'] if ENV['USE_NEW_WDA']
182
179
  desired_capabilities[:chromedriverExecutable] = ENV['CHROMEDRIVER_EXECUTABLE'] if ENV['CHROMEDRIVER_EXECUTABLE']
183
180
  # set wdaLocalPort (iOS) or systemPort (Android) if PARALLEL_PORT is true
184
181
  if ENV['PARALLEL'] && ENV['PARALLEL_PORT']
@@ -192,35 +189,37 @@ module TestCentricity
192
189
  desired_capabilities[:systemPort] = ENV['SYSTEM_PORT'] if ENV['SYSTEM_PORT']
193
190
  end
194
191
 
195
- unless desired_caps.nil?
196
- desired_capabilities = merge_caps ? desired_capabilities.merge(desired_caps) : desired_caps
192
+ unless @capabilities.nil?
193
+ desired_capabilities = @capabilities
197
194
  end
198
195
 
199
196
  Capybara.register_driver :appium do |app|
200
- appium_lib_options = { server_url: endpoint }
197
+ appium_lib_options = { server_url: @endpoint }
201
198
  all_options = {
202
199
  appium_lib: appium_lib_options,
203
200
  caps: desired_capabilities
204
201
  }
205
- Appium::Capybara::Driver.new app, all_options
202
+ Appium::Capybara::Driver.new(app, all_options)
206
203
  end
207
204
  end
208
205
 
209
206
  def self.initialize_local_browser
210
- Environ.os = if OS.osx?
207
+ Environ.os = case
208
+ when OS.osx?
211
209
  'OS X'
212
- elsif OS.windows?
210
+ when OS.windows?
213
211
  'Windows'
214
- elsif OS.linux?
212
+ when OS.linux?
215
213
  'Linux'
214
+ else
215
+ 'unknown'
216
216
  end
217
-
218
217
  browser = ENV['WEB_BROWSER'].downcase.to_sym
219
218
 
220
219
  case browser
221
220
  when :firefox, :chrome, :ie, :safari, :edge
222
221
  Environ.platform = :desktop
223
- when :chrome_headless, :firefox_headless
222
+ when :chrome_headless, :firefox_headless, :edge_headless
224
223
  Environ.platform = :desktop
225
224
  Environ.headless = true
226
225
  else
@@ -230,10 +229,7 @@ module TestCentricity
230
229
 
231
230
  Capybara.register_driver :selenium do |app|
232
231
  case browser
233
- when :safari
234
- caps = Selenium::WebDriver::Remote::Capabilities.safari(cleanSession: true)
235
- Capybara::Selenium::Driver.new(app, browser: browser, desired_capabilities: caps)
236
- when :ie, :edge
232
+ when :safari, :ie
237
233
  Capybara::Selenium::Driver.new(app, browser: browser)
238
234
  when :firefox, :firefox_headless
239
235
  profile = Selenium::WebDriver::Firefox::Profile.new
@@ -253,16 +249,15 @@ module TestCentricity
253
249
  profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
254
250
  options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
255
251
  options.args << '--headless' if browser == :firefox_headless
256
- Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
252
+ Capybara::Selenium::Driver.new(app, browser: :firefox, capabilities: [options])
257
253
  when :chrome, :chrome_headless
258
- options = Selenium::WebDriver::Chrome::Options.new
254
+ options = Selenium::WebDriver::Chrome::Options.new(options: {'excludeSwitches' => ['enable-automation']})
259
255
  prefs = {
260
256
  prompt_for_download: false,
261
257
  directory_upgrade: true,
262
258
  default_directory: @downloads_path
263
259
  }
264
260
  options.add_preference(:download, prefs)
265
- options.add_argument('--disable-infobars')
266
261
  options.add_argument('--disable-dev-shm-usage')
267
262
  options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
268
263
  if browser == :chrome_headless
@@ -271,16 +266,33 @@ module TestCentricity
271
266
  options.add_argument('--no-sandbox')
272
267
  end
273
268
 
274
- Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
269
+ Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: [options])
270
+ when :edge, :edge_headless
271
+ options = Selenium::WebDriver::Edge::Options.new(options: {'excludeSwitches' => ['enable-automation']})
272
+ prefs = {
273
+ prompt_for_download: false,
274
+ directory_upgrade: true,
275
+ default_directory: @downloads_path
276
+ }
277
+ options.add_preference(:download, prefs)
278
+ options.add_argument('--disable-dev-shm-usage')
279
+ options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
280
+ if browser == :edge_headless
281
+ options.add_argument('--headless')
282
+ options.add_argument('--disable-gpu')
283
+ options.add_argument('--no-sandbox')
284
+ end
285
+
286
+ Capybara::Selenium::Driver.new(app, browser: :edge, capabilities: [options])
275
287
  else
276
288
  if ENV['HOST_BROWSER'] && ENV['HOST_BROWSER'].downcase.to_sym == :chrome
277
289
  user_agent = Browsers.mobile_device_agent(ENV['WEB_BROWSER'])
278
- options = Selenium::WebDriver::Chrome::Options.new
290
+ options = Selenium::WebDriver::Chrome::Options.new(options: {'excludeSwitches' => ['enable-automation']})
279
291
  options.add_argument('--disable-infobars')
280
292
  options.add_argument('--disable-dev-shm-usage')
281
293
  options.add_argument("--user-agent='#{user_agent}'")
282
294
  options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
283
- Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
295
+ Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: [options])
284
296
  else
285
297
  raise "Requested browser '#{browser}' is not supported"
286
298
  end
@@ -289,308 +301,228 @@ module TestCentricity
289
301
  Capybara.default_driver = :selenium
290
302
  end
291
303
 
292
- def self.initialize_browserstack(desired_caps = nil, merge_caps = false)
304
+ def self.initialize_browserstack
293
305
  browser = ENV['BS_BROWSER']
294
306
  Environ.grid = :browserstack
295
307
 
296
- if ENV['BS_REAL_MOBILE'] || ENV['BS_PLATFORM']
308
+ if ENV['BS_REAL_MOBILE'] || ENV['BS_DEVICE']
297
309
  Environ.platform = :mobile
298
310
  Environ.device_name = ENV['BS_DEVICE']
299
311
  Environ.device_os = ENV['BS_OS']
300
312
  Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
313
+ Environ.device = if ENV['BS_REAL_MOBILE']
314
+ :device
315
+ else
316
+ :simulator
317
+ end
301
318
  elsif ENV['BS_OS']
302
319
  Environ.os = "#{ENV['BS_OS']} #{ENV['BS_OS_VERSION']}"
303
320
  end
304
- Environ.device = if ENV['BS_REAL_MOBILE']
305
- :device
306
- elsif ENV['BS_PLATFORM']
307
- :simulator
308
- end
309
-
310
- endpoint = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub-cloud.browserstack.com/wd/hub"
311
- Capybara.register_driver :browserstack do |app|
312
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
313
-
314
- if ENV['BS_REAL_MOBILE']
315
- capabilities['device'] = ENV['BS_DEVICE']
316
- capabilities['realMobile'] = true
317
- capabilities['os_version'] = ENV['BS_OS_VERSION']
318
-
319
- elsif ENV['BS_PLATFORM']
320
- capabilities[:platform] = ENV['BS_PLATFORM']
321
- capabilities[:browserName] = browser
322
- capabilities['device'] = ENV['BS_DEVICE'] if ENV['BS_DEVICE']
323
- capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
324
-
325
- elsif ENV['BS_OS']
326
- capabilities['os'] = ENV['BS_OS']
327
- capabilities['os_version'] = ENV['BS_OS_VERSION']
328
- capabilities['browser'] = browser || 'chrome'
329
- capabilities['browser_version'] = ENV['BS_VERSION'] if ENV['BS_VERSION']
330
- capabilities['resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
331
- end
332
-
333
- capabilities['browserstack.selenium_version'] = ENV['SELENIUM_VERSION'] if ENV['SELENIUM_VERSION']
334
- capabilities['browserstack.console'] = ENV['CONSOLE_LOGS'] if ENV['CONSOLE_LOGS']
335
- capabilities['browserstack.timezone'] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
336
- capabilities['browserstack.geoLocation'] = ENV['IP_GEOLOCATION'] if ENV['IP_GEOLOCATION']
337
- capabilities['browserstack.video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
338
- capabilities['browserstack.debug'] = 'true'
339
- capabilities['project'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
340
- capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
341
-
342
- context_message = ENV['TEST_CONTEXT'] ? "#{Environ.test_environment.upcase} - #{ENV['TEST_CONTEXT']}" : Environ.test_environment.upcase
343
- if ENV['PARALLEL']
344
- thread_num = ENV['TEST_ENV_NUMBER']
345
- thread_num = 1 if thread_num.blank?
346
- context_message = "#{context_message} - Thread ##{thread_num}"
347
- end
348
- capabilities['name'] = context_message
349
-
350
- capabilities['acceptSslCerts'] = 'true'
351
- capabilities['browserstack.localIdentifier'] = ENV['BS_LOCAL_ID'] if ENV['BS_LOCAL_ID']
352
- capabilities['browserstack.local'] = 'true' if ENV['TUNNELING']
353
-
354
- case browser.downcase.to_sym
355
- when :ie
356
- capabilities['ie.fileUploadDialogTimeout'] = 10000
357
- capabilities['ie.ensureCleanSession'] = 'true'
358
- capabilities['ie.browserCommandLineSwitches'] = 'true'
359
- capabilities['nativeEvents'] = 'true'
360
- capabilities['browserstack.ie.driver'] = ENV['WD_VERSION'] if ENV['WD_VERSION']
361
- capabilities['browserstack.ie.enablePopups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
362
- when :edge
363
- capabilities['ie.fileUploadDialogTimeout'] = 10000
364
- capabilities['ie.ensureCleanSession'] = 'true'
365
- capabilities['ie.browserCommandLineSwitches'] = 'true'
366
- capabilities['nativeEvents'] = 'true'
367
- capabilities['browserstack.ie.driver'] = ENV['WD_VERSION'] if ENV['WD_VERSION']
368
- capabilities['browserstack.edge.enablePopups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
369
- when :firefox
370
- capabilities['browserstack.geckodriver'] = ENV['WD_VERSION'] if ENV['WD_VERSION']
371
- when :safari
372
- capabilities['cleanSession'] = 'true'
373
- capabilities['browserstack.safari.driver'] = ENV['WD_VERSION'] if ENV['WD_VERSION']
374
- capabilities['browserstack.safari.enablePopups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
375
- capabilities['browserstack.safari.allowAllCookies'] = ENV['ALLOW_COOKIES'] if ENV['ALLOW_COOKIES']
376
- when :iphone, :ipad
377
- capabilities['javascriptEnabled'] = 'true'
378
- capabilities['cleanSession'] = 'true'
379
- end
380
-
381
- unless desired_caps.nil?
382
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
383
- end
384
-
385
- if ENV['TUNNELING']
386
- @bs_local = BrowserStack::Local.new
387
- bs_local_args = {'key' => "#{ENV['BS_AUTHKEY']}"}
388
- @bs_local.start(bs_local_args)
389
- if @bs_local.isRunning
390
- puts 'BrowserStack Local instance has been started'
391
- else
392
- puts 'BrowserStack Local instance failed to start'
393
- end
321
+ # specify endpoint url
322
+ @endpoint = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub-cloud.browserstack.com/wd/hub" if @endpoint.nil?
323
+ # enable tunneling if specified
324
+ if ENV['TUNNELING']
325
+ @bs_local = BrowserStack::Local.new
326
+ bs_local_args = {'key' => "#{ENV['BS_AUTHKEY']}"}
327
+ @bs_local.start(bs_local_args)
328
+ if @bs_local.isRunning
329
+ puts 'BrowserStack Local instance has been started'
330
+ else
331
+ puts 'BrowserStack Local instance failed to start'
394
332
  end
395
-
396
- Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
397
333
  end
398
-
399
- Environ.browser = browser
334
+ # define BrowserStack options
335
+ options = if @capabilities.nil?
336
+ browser_options = {}
337
+ # define the required set of BrowserStack options
338
+ bs_options = {
339
+ userName: ENV['BS_USERNAME'],
340
+ accessKey: ENV['BS_AUTHKEY'],
341
+ sessionName: test_context_message,
342
+ os: ENV['BS_OS'],
343
+ osVersion: ENV['BS_OS_VERSION']
344
+ }
345
+ # define browser specific BrowserStack options
346
+ case browser.downcase.to_sym
347
+ when :safari
348
+ browser_options[:enablePopups] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
349
+ browser_options[:allowAllCookies] = ENV['ALLOW_COOKIES'] if ENV['ALLOW_COOKIES']
350
+ bs_options[:safari] = browser_options unless browser_options.empty?
351
+ when :ie
352
+ browser_options[:enablePopups] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
353
+ bs_options[:ie] = browser_options unless browser_options.empty?
354
+ when :edge
355
+ browser_options[:enablePopups] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
356
+ bs_options[:edge] = browser_options unless browser_options.empty?
357
+ end
358
+ # define the optional BrowserStack options
359
+ bs_options[:projectName] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
360
+ bs_options[:buildName] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
361
+ bs_options[:headless] = ENV['HEADLESS'] if ENV['HEADLESS']
362
+ bs_options[:timezone] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
363
+ bs_options[:geoLocation] = ENV['IP_GEOLOCATION'] if ENV['IP_GEOLOCATION']
364
+ bs_options[:video] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
365
+ bs_options[:debug] = ENV['SCREENSHOTS'] if ENV['SCREENSHOTS']
366
+ bs_options[:networkLogs] = ENV['NETWORK_LOGS'] if ENV['NETWORK_LOGS']
367
+ bs_options[:local] = ENV['TUNNELING'] if ENV['TUNNELING']
368
+ bs_options[:deviceOrientation] = ENV['ORIENTATION'] if ENV['ORIENTATION']
369
+ bs_options[:appiumLogs] = ENV['APPIUM_LOGS'] if ENV['APPIUM_LOGS']
370
+ bs_options[:realMobile] = ENV['BS_REAL_MOBILE'] if ENV['BS_REAL_MOBILE']
371
+ # define mobile device options
372
+ if ENV['BS_DEVICE']
373
+ bs_options[:deviceName] = ENV['BS_DEVICE']
374
+ bs_options[:appiumVersion] = '1.22.0'
375
+ {
376
+ browserName: browser,
377
+ 'bstack:options': bs_options
378
+ }
379
+ else
380
+ # define desktop browser options
381
+ bs_options[:resolution] = ENV['RESOLUTION'] if ENV['RESOLUTION']
382
+ bs_options[:seleniumVersion] = '4.1.0'
383
+ {
384
+ browserName: browser,
385
+ browserVersion: ENV['BS_VERSION'],
386
+ 'bstack:options': bs_options
387
+ }
388
+ end
389
+ else
390
+ @capabilities
391
+ end
392
+ register_remote_driver(:browserstack, browser, options)
393
+ # configure file_detector for remote uploads
394
+ config_file_uploads
400
395
  Environ.tunneling = ENV['TUNNELING'] if ENV['TUNNELING']
401
396
  Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
402
-
403
- Capybara.default_driver = :browserstack
404
- Capybara.run_server = false
405
- # configure file_detector for remote uploads
406
- selenium = Capybara.page.driver.browser
407
- selenium.file_detector = lambda do |args|
408
- str = args.first.to_s
409
- str if File.exist?(str)
410
- end
411
- end
412
-
413
- def self.initialize_crossbrowser(desired_caps = nil, merge_caps = false)
414
- browser = ENV['CB_BROWSER']
415
- Environ.grid = :crossbrowser
416
-
417
- if ENV['CB_OS']
418
- Environ.os = ENV['CB_OS']
419
- Environ.platform = :desktop
420
- elsif ENV['CB_PLATFORM']
421
- Environ.device_name = ENV['CB_PLATFORM']
422
- Environ.device = :device
423
- Environ.platform = :mobile
424
- Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
425
- end
426
-
427
- endpoint = "http://#{ENV['CB_USERNAME']}:#{ENV['CB_AUTHKEY']}@hub.crossbrowsertesting.com:80/wd/hub"
428
- Capybara.register_driver :crossbrowser do |app|
429
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
430
- capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
431
- capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
432
- capabilities['browser_api_name'] = browser
433
- capabilities['screen_resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
434
- if ENV['CB_OS']
435
- capabilities['os_api_name'] = ENV['CB_OS']
436
- Environ.platform = :desktop
437
- elsif ENV['CB_PLATFORM']
438
- capabilities['os_api_name'] = ENV['CB_PLATFORM']
439
- end
440
-
441
- unless desired_caps.nil?
442
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
443
- end
444
-
445
- Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
446
- end
447
-
448
- Environ.browser = browser
449
-
450
- Capybara.default_driver = :crossbrowser
451
- Capybara.run_server = false
452
- # configure file_detector for remote uploads
453
- selenium = Capybara.page.driver.browser
454
- selenium.file_detector = lambda do |args|
455
- str = args.first.to_s
456
- str if File.exist?(str)
457
- end
458
397
  end
459
398
 
460
- def self.initialize_gridlastic(desired_caps = nil, merge_caps = false)
461
- browser = ENV['GL_BROWSER']
462
- Environ.grid = :gridlastic
463
- Environ.os = ENV['GL_OS']
464
- endpoint = "http://#{ENV['GL_USERNAME']}:#{ENV['GL_AUTHKEY']}@#{ENV['GL_SUBDOMAIN']}.gridlastic.com:80/wd/hub"
465
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
466
- capabilities['browserName'] = browser
467
- capabilities['version'] = ENV['GL_VERSION'] if ENV['GL_VERSION']
468
- capabilities['platform'] = ENV['GL_OS']
469
- capabilities['platformName'] = ENV['GL_PLATFORM']
470
- capabilities['video'] = ENV['RECORD_VIDEO'].capitalize if ENV['RECORD_VIDEO']
471
-
472
- unless desired_caps.nil?
473
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
474
- end
475
-
476
- Capybara.register_driver :selenium do |app|
477
- client = Selenium::WebDriver::Remote::Http::Default.new
478
- client.timeout = 1200
479
- Capybara::Selenium::Driver.new(app, http_client: client, browser: :remote, url: endpoint, desired_capabilities: capabilities)
480
- end
481
-
482
- Environ.browser = browser
483
-
484
- Capybara.default_driver = :selenium
485
- Capybara.run_server = false
486
-
487
- if ENV['RECORD_VIDEO']
488
- session_id = Capybara.current_session.driver.browser.instance_variable_get(:@bridge).session_id
489
- puts "TEST VIDEO URL: #{ENV['VIDEO_URL']}#{session_id}"
490
- end
491
- # configure file_detector for remote uploads
492
- selenium = Capybara.page.driver.browser
493
- selenium.file_detector = lambda do |args|
494
- str = args.first.to_s
495
- str if File.exist?(str)
496
- end
497
- end
498
-
499
- def self.initialize_lambdatest(desired_caps = nil, merge_caps = false)
399
+ def self.initialize_lambdatest
500
400
  browser = ENV['LT_BROWSER']
501
401
  Environ.grid = :lambdatest
502
402
  Environ.os = ENV['LT_OS']
503
403
  Environ.platform = :desktop
504
404
  Environ.tunneling = ENV['TUNNELING'] if ENV['TUNNELING']
505
-
506
- endpoint = "http://#{ENV['LT_USERNAME']}:#{ENV['LT_AUTHKEY']}@hub.lambdatest.com/wd/hub"
507
- Capybara.register_driver :lambdatest do |app|
508
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
509
- capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
510
- capabilities['browserName'] = browser
511
- capabilities['version'] = ENV['LT_VERSION'] if ENV['LT_VERSION']
512
- capabilities['platform'] = ENV['LT_OS']
513
- capabilities['resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
514
- capabilities['video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
515
- capabilities['console'] = ENV['CONSOLE_LOGS'] if ENV['CONSOLE_LOGS']
516
- capabilities['network'] = true
517
- capabilities['visual'] = true
518
- capabilities['tunnel'] = ENV['TUNNELING'] if ENV['TUNNELING']
519
-
520
- case browser.downcase.to_sym
521
- when :safari
522
- capabilities['safari.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
523
- capabilities['safari.cookies'] = ENV['ALLOW_COOKIES'] if ENV['ALLOW_COOKIES']
524
- when :ie
525
- capabilities['ie.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
526
- when :edge
527
- capabilities['edge.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
528
- end
529
-
530
- context_message = ENV['TEST_CONTEXT'] ? "#{Environ.test_environment.upcase} - #{ENV['TEST_CONTEXT']}" : Environ.test_environment.upcase
531
- if ENV['PARALLEL']
532
- thread_num = ENV['TEST_ENV_NUMBER']
533
- thread_num = 1 if thread_num.blank?
534
- context_message = "#{context_message} - Thread ##{thread_num}"
535
- end
536
- capabilities['build'] = context_message
537
-
538
- unless desired_caps.nil?
539
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
540
- end
541
-
542
- Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
543
- end
544
-
545
- Environ.browser = browser
546
-
547
- Capybara.default_driver = :lambdatest
548
- Capybara.run_server = false
405
+ # specify endpoint url
406
+ @endpoint = "https://#{ENV['LT_USERNAME']}:#{ENV['LT_AUTHKEY']}@hub.lambdatest.com/wd/hub" if @endpoint.nil?
407
+ # define LambdaTest options
408
+ options = if @capabilities.nil?
409
+ # define the required set of LambdaTest options
410
+ lt_options = {
411
+ user: ENV['LT_USERNAME'],
412
+ accessKey: ENV['LT_AUTHKEY'],
413
+ build: test_context_message,
414
+ platformName: ENV['LT_OS'],
415
+ resolution: ENV['RESOLUTION'],
416
+ selenium_version: '4.0.0',
417
+ }
418
+ # define the optional LambdaTest options
419
+ lt_options[:name] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
420
+ lt_options[:headless] = ENV['HEADLESS'] if ENV['HEADLESS']
421
+ lt_options[:timezone] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
422
+ lt_options[:geoLocation] = ENV['GEO_LOCATION'] if ENV['GEO_LOCATION']
423
+ lt_options[:video] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
424
+ lt_options[:visual] = ENV['SCREENSHOTS'] if ENV['SCREENSHOTS']
425
+ lt_options[:network] = ENV['NETWORK_LOGS'] if ENV['NETWORK_LOGS']
426
+ lt_options[:tunnel] = ENV['TUNNELING'] if ENV['TUNNELING']
427
+ # define browser specific LambdaTest options
428
+ case browser.downcase.to_sym
429
+ when :safari
430
+ lt_options['safari.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
431
+ lt_options['safari.cookies'] = ENV['ALLOW_COOKIES'] if ENV['ALLOW_COOKIES']
432
+ when :ie
433
+ lt_options['ie.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
434
+ when :microsoftedge
435
+ lt_options['edge.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
436
+ end
437
+ {
438
+ browserName: browser,
439
+ browserVersion: ENV['LT_VERSION'],
440
+ 'LT:Options': lt_options
441
+ }
442
+ else
443
+ @capabilities
444
+ end
445
+ register_remote_driver(:lambdatest, browser, options)
549
446
  # configure file_detector for remote uploads
550
- selenium = Capybara.page.driver.browser
551
- selenium.file_detector = lambda do |args|
552
- str = args.first.to_s
553
- str if File.exist?(str)
554
- end
447
+ config_file_uploads
555
448
  end
556
449
 
557
450
  def self.initialize_remote
558
451
  Environ.grid = :selenium_grid
559
452
  browser = ENV['WEB_BROWSER'].downcase.to_sym
560
- endpoint = ENV['REMOTE_ENDPOINT'] || 'http://127.0.0.1:4444/wd/hub'
453
+ @endpoint = ENV['REMOTE_ENDPOINT'] || 'http://127.0.0.1:4444/wd/hub' if @endpoint.nil?
561
454
  Capybara.register_driver :remote_browser do |app|
562
455
  case browser
563
- when :firefox, :safari, :ie, :edge
564
- capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser)
456
+ when :safari
457
+ options = Selenium::WebDriver::Safari::Options.new
458
+ when :ie
459
+ options = Selenium::WebDriver::IE::Options.new
460
+ when :firefox, :firefox_headless
461
+ profile = Selenium::WebDriver::Firefox::Profile.new
462
+ profile['browser.download.dir'] = @downloads_path
463
+ profile['browser.download.folderList'] = 2
464
+ profile['browser.download.manager.showWhenStarting'] = false
465
+ profile['browser.download.manager.closeWhenDone'] = true
466
+ profile['browser.download.manager.showAlertOnComplete'] = false
467
+ profile['browser.download.manager.alertOnEXEOpen'] = false
468
+ profile['browser.download.manager.useWindow'] = false
469
+ profile['browser.helperApps.alwaysAsk.force'] = false
470
+ profile['pdfjs.disabled'] = true
471
+
472
+ mime_types = ENV['MIME_TYPES'] || 'images/jpeg, application/pdf, application/octet-stream'
473
+ profile['browser.helperApps.neverAsk.saveToDisk'] = mime_types
474
+
475
+ profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
476
+ options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
477
+ options.args << '--headless' if browser == :firefox_headless
565
478
  when :chrome, :chrome_headless
566
- options = %w[--disable-infobars]
567
- options.push('--disable-dev-shm-usage')
568
- options.push("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
479
+ options = Selenium::WebDriver::Chrome::Options.new(options: {'excludeSwitches' => ['enable-automation']})
480
+ prefs = {
481
+ prompt_for_download: false,
482
+ directory_upgrade: true,
483
+ default_directory: @downloads_path
484
+ }
485
+ options.add_preference(:download, prefs)
486
+ options.add_argument('--disable-dev-shm-usage')
487
+ options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
569
488
  if browser == :chrome_headless
570
- Environ.headless = true
571
- options.push('--headless')
572
- options.push('--disable-gpu')
573
- options.push('--no-sandbox')
489
+ options.add_argument('--headless')
490
+ options.add_argument('--disable-gpu')
491
+ options.add_argument('--no-sandbox')
492
+ end
493
+ when :edge, :edge_headless
494
+ options = Selenium::WebDriver::Edge::Options.new(options: {'excludeSwitches' => ['enable-automation']})
495
+ prefs = {
496
+ prompt_for_download: false,
497
+ directory_upgrade: true,
498
+ default_directory: @downloads_path
499
+ }
500
+ options.add_preference(:download, prefs)
501
+ options.add_argument('--disable-dev-shm-usage')
502
+ options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
503
+ if browser == :edge_headless
504
+ options.add_argument('--headless')
505
+ options.add_argument('--disable-gpu')
506
+ options.add_argument('--no-sandbox')
574
507
  end
575
- capabilities = Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => { args: options })
576
508
  else
577
509
  if ENV['HOST_BROWSER'] && ENV['HOST_BROWSER'].downcase.to_sym == :chrome
578
510
  Environ.platform = :mobile
579
511
  Environ.device_name = Browsers.mobile_device_name(ENV['WEB_BROWSER'])
580
512
  user_agent = Browsers.mobile_device_agent(ENV['WEB_BROWSER'])
581
- options = %w[--disable-infobars]
582
- options.push('--disable-dev-shm-usage')
583
- options.push("--user-agent='#{user_agent}'")
584
- options.push("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
585
- capabilities = Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => { args: options })
513
+ options = Selenium::WebDriver::Chrome::Options.new(options: {'excludeSwitches' => ['enable-automation']})
514
+ options.add_argument('--disable-infobars')
515
+ options.add_argument('--disable-dev-shm-usage')
516
+ options.add_argument("--user-agent='#{user_agent}'")
517
+ options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
586
518
  else
587
519
  raise "Requested browser '#{browser}' is not supported on Selenium Grid"
588
520
  end
589
521
  end
590
522
  Capybara::Selenium::Driver.new(app,
591
523
  browser: :remote,
592
- url: endpoint,
593
- desired_capabilities: capabilities).tap do |driver|
524
+ url: @endpoint,
525
+ capabilities: [options]).tap do |driver|
594
526
  # configure file_detector for remote uploads
595
527
  driver.browser.file_detector = lambda do |args|
596
528
  str = args.first.to_s
@@ -602,7 +534,7 @@ module TestCentricity
602
534
  Capybara.default_driver = :remote_browser
603
535
  end
604
536
 
605
- def self.initialize_saucelabs(desired_caps = nil, merge_caps = false)
537
+ def self.initialize_saucelabs
606
538
  browser = ENV['SL_BROWSER']
607
539
  Environ.grid = :saucelabs
608
540
 
@@ -611,47 +543,54 @@ module TestCentricity
611
543
  Environ.os = ENV['SL_OS']
612
544
  elsif ENV['SL_PLATFORM']
613
545
  Environ.device_name = ENV['SL_DEVICE']
614
- Environ.platform = :mobile
615
- end
616
-
617
- endpoint = "http://#{ENV['SL_USERNAME']}:#{ENV['SL_AUTHKEY']}@ondemand.saucelabs.com:80/wd/hub"
618
- Capybara.register_driver :saucelabs do |app|
619
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
620
- capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
621
- capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
622
- capabilities['browserName'] = browser
623
- capabilities['version'] = ENV['SL_VERSION'] if ENV['SL_VERSION']
624
- capabilities['screenResolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
625
- capabilities['recordVideo'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
626
- if ENV['SL_OS']
627
- capabilities['platform'] = ENV['SL_OS']
628
- elsif ENV['SL_PLATFORM']
629
- capabilities['platform'] = ENV['SL_PLATFORM']
630
- capabilities['deviceName'] = ENV['SL_DEVICE']
631
- capabilities['deviceType'] = ENV['SL_DEVICE_TYPE'] if ENV['SL_DEVICE_TYPE']
632
- capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
633
- end
634
-
635
- unless desired_caps.nil?
636
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
637
- end
638
-
639
- Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
546
+ Environ.platform = :mobile
547
+ Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
548
+ Environ.device = :simulator
640
549
  end
641
-
642
- Environ.browser = browser
643
-
644
- Capybara.default_driver = :saucelabs
645
- Capybara.run_server = false
550
+ # specify endpoint url
551
+ @endpoint = "https://#{ENV['SL_USERNAME']}:#{ENV['SL_AUTHKEY']}@ondemand.#{ENV['DATA_CENTER']}.saucelabs.com/wd/hub" if @endpoint.nil?
552
+ # define SauceLab options
553
+ options = if @capabilities.nil?
554
+ # define the required set of SauceLab options
555
+ sl_options = {
556
+ userName: ENV['SL_USERNAME'],
557
+ accessKey: ENV['SL_AUTHKEY'],
558
+ build: test_context_message
559
+ }
560
+ # define the optional SauceLab options
561
+ sl_options[:name] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
562
+ sl_options[:recordVideo] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
563
+ sl_options[:recordScreenshots] = ENV['SCREENSHOTS'] if ENV['SCREENSHOTS']
564
+ # define mobile device options
565
+ if ENV['SL_PLATFORM']
566
+ sl_options[:deviceOrientation] = ENV['ORIENTATION'].upcase if ENV['ORIENTATION']
567
+ sl_options[:appiumVersion] = '1.22.0'
568
+ {
569
+ browserName: browser,
570
+ platformName: ENV['SL_PLATFORM'],
571
+ 'appium:deviceName': ENV['SL_DEVICE'],
572
+ 'appium:platformVersion': ENV['SL_VERSION'],
573
+ 'sauce:options': sl_options
574
+ }
575
+ else
576
+ # define desktop browser options
577
+ sl_options[:screenResolution] = ENV['RESOLUTION'] if ENV['RESOLUTION']
578
+ {
579
+ browserName: browser,
580
+ browserVersion: ENV['SL_VERSION'],
581
+ platformName: ENV['SL_OS'],
582
+ 'sauce:options': sl_options
583
+ }
584
+ end
585
+ else
586
+ @capabilities
587
+ end
588
+ register_remote_driver(:saucelabs, browser, options)
646
589
  # configure file_detector for remote uploads
647
- selenium = Capybara.page.driver.browser
648
- selenium.file_detector = lambda do |args|
649
- str = args.first.to_s
650
- str if File.exist?(str)
651
- end
590
+ config_file_uploads
652
591
  end
653
592
 
654
- def self.initialize_testingbot(desired_caps = nil, merge_caps = false)
593
+ def self.initialize_testingbot
655
594
  browser = ENV['TB_BROWSER']
656
595
  Environ.grid = :testingbot
657
596
 
@@ -666,35 +605,72 @@ module TestCentricity
666
605
  else
667
606
  Environ.platform = :desktop
668
607
  end
608
+ # specify endpoint url
609
+ if @endpoint.nil?
610
+ url = ENV['TUNNELING'] ? '@localhost:4445/wd/hub' : '@hub.testingbot.com/wd/hub'
611
+ @endpoint = "http://#{ENV['TB_USERNAME']}:#{ENV['TB_AUTHKEY']}#{url}"
612
+ end
613
+ # define TestingBot options
614
+ options = if @capabilities.nil?
615
+ # define the required set of TestingBot options
616
+ tb_options = { build: test_context_message }
617
+ # define the optional TestingBot options
618
+ tb_options[:name] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
619
+ tb_options[:timeZone] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
620
+ tb_options['testingbot.geoCountryCode'] = ENV['GEO_LOCATION'] if ENV['GEO_LOCATION']
621
+ tb_options[:screenrecorder] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
622
+ tb_options[:screenshot] = ENV['SCREENSHOTS'] if ENV['SCREENSHOTS']
623
+ # define mobile device options
624
+ if ENV['TB_PLATFORM']
625
+ tb_options[:platform] = ENV['TB_PLATFORM']
626
+ tb_options[:orientation] = ENV['ORIENTATION'].upcase if ENV['ORIENTATION']
627
+ tb_options[:deviceName] = ENV['TB_DEVICE'] if ENV['TB_DEVICE']
628
+ else
629
+ # define desktop browser options
630
+ tb_options['screen-resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
631
+ tb_options['selenium-version'] = '4.1.0'
632
+ end
633
+ {
634
+ browserName: browser,
635
+ browserVersion: ENV['TB_VERSION'],
636
+ platformName: ENV['TB_OS'],
637
+ 'tb:options': tb_options
638
+ }
639
+ else
640
+ @capabilities
641
+ end
642
+ register_remote_driver(:testingbot, browser, options)
643
+ # configure file_detector for remote uploads if target is desktop web browser
644
+ config_file_uploads unless ENV['TB_PLATFORM']
645
+ end
669
646
 
670
- endpoint = ENV['TUNNELING'] ? '@localhost:4445/wd/hub' : '@hub.testingbot.com:4444/wd/hub'
671
- endpoint = "http://#{ENV['TB_USERNAME']}:#{ENV['TB_AUTHKEY']}#{endpoint}"
672
- Capybara.register_driver :testingbot do |app|
673
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
674
- capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
675
- capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
676
- capabilities['browserName'] = browser
677
- capabilities['version'] = ENV['TB_VERSION'] if ENV['TB_VERSION']
678
- capabilities['screen-resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
679
- capabilities['platform'] = ENV['TB_OS']
680
- capabilities['record_video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
681
- if ENV['TB_PLATFORM']
682
- capabilities['orientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
683
- capabilities['platformName'] = ENV['TB_PLATFORM']
684
- capabilities['deviceName'] = ENV['TB_DEVICE']
685
- end
686
-
687
- unless desired_caps.nil?
688
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
689
- end
647
+ def self.test_context_message
648
+ context_message = if ENV['TEST_CONTEXT']
649
+ "#{Environ.test_environment.to_s.upcase} - #{ENV['TEST_CONTEXT']}"
650
+ else
651
+ Environ.test_environment.to_s.upcase
652
+ end
653
+ if ENV['PARALLEL']
654
+ thread_num = ENV['TEST_ENV_NUMBER']
655
+ thread_num = 1 if thread_num.blank?
656
+ context_message = "#{context_message} - Thread ##{thread_num}"
657
+ end
658
+ context_message
659
+ end
690
660
 
691
- Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
661
+ def self.register_remote_driver(driver, browser, options)
662
+ Capybara.register_driver driver do |app|
663
+ capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser.gsub(/\s+/, '_').downcase.to_sym, options)
664
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: @endpoint, capabilities: capabilities)
692
665
  end
693
666
 
694
667
  Environ.browser = browser
695
668
 
696
- Capybara.default_driver = :testingbot
669
+ Capybara.default_driver = driver
697
670
  Capybara.run_server = false
671
+ end
672
+
673
+ def self.config_file_uploads
698
674
  # configure file_detector for remote uploads
699
675
  selenium = Capybara.page.driver.browser
700
676
  selenium.file_detector = lambda do |args|