testcentricity_web 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,13 +14,11 @@ module TestCentricity
14
14
 
15
15
  def self.initialize_web_driver(options = nil)
16
16
  desired_caps = nil
17
- merge_caps = nil
18
17
  if options.is_a?(String)
19
18
  Capybara.app_host = options
20
19
  elsif options.is_a?(Hash)
21
20
  Capybara.app_host = options[:app_host] if options.key?(:app_host)
22
21
  desired_caps = options[:desired_capabilities] if options.key?(:desired_capabilities)
23
- merge_caps = options[:merge_capabilities] if options.key?(:merge_capabilities)
24
22
  end
25
23
 
26
24
  browser = ENV['WEB_BROWSER']
@@ -46,25 +44,25 @@ module TestCentricity
46
44
 
47
45
  context = case browser.downcase.to_sym
48
46
  when :appium
49
- initialize_appium(desired_caps, merge_caps)
47
+ initialize_appium(desired_caps)
50
48
  'mobile device emulator'
51
49
  when :browserstack
52
- initialize_browserstack(desired_caps, merge_caps)
50
+ initialize_browserstack(desired_caps)
53
51
  'Browserstack cloud service'
54
52
  when :crossbrowser
55
- initialize_crossbrowser(desired_caps, merge_caps)
53
+ initialize_crossbrowser(desired_caps)
56
54
  'CrossBrowserTesting cloud service'
57
55
  when :gridlastic
58
- initialize_gridlastic(desired_caps, merge_caps)
56
+ initialize_gridlastic(desired_caps)
59
57
  'Gridlastic cloud service'
60
58
  when :lambdatest
61
- initialize_lambdatest(desired_caps, merge_caps)
59
+ initialize_lambdatest(desired_caps)
62
60
  'LambdaTest cloud service'
63
61
  when :saucelabs
64
- initialize_saucelabs(desired_caps, merge_caps)
62
+ initialize_saucelabs(desired_caps)
65
63
  'Sauce Labs cloud service'
66
64
  when :testingbot
67
- initialize_testingbot(desired_caps, merge_caps)
65
+ initialize_testingbot(desired_caps)
68
66
  'TestingBot cloud service'
69
67
  else
70
68
  if ENV['SELENIUM'] == 'remote'
@@ -133,7 +131,7 @@ module TestCentricity
133
131
 
134
132
  private
135
133
 
136
- def self.initialize_appium(desired_caps = nil, merge_caps = false)
134
+ def self.initialize_appium(desired_caps = nil)
137
135
  Environ.platform = :mobile
138
136
  Environ.device_name = ENV['APP_DEVICE']
139
137
  Environ.device_os = ENV['APP_PLATFORM_NAME'].downcase.to_sym
@@ -153,7 +151,6 @@ module TestCentricity
153
151
  if ENV['UDID']
154
152
  Environ.device = :device
155
153
  desired_capabilities[:udid] = ENV['UDID']
156
- desired_capabilities[:startIWDP] = true
157
154
  desired_capabilities[:xcodeOrgId] = ENV['TEAM_ID'] if ENV['TEAM_ID']
158
155
  desired_capabilities[:xcodeSigningId] = ENV['TEAM_NAME'] if ENV['TEAM_NAME']
159
156
  else
@@ -161,24 +158,26 @@ module TestCentricity
161
158
  desired_capabilities[:orientation] = Environ.device_orientation.upcase if Environ.device_orientation
162
159
  if Environ.device_os == :ios
163
160
  desired_capabilities[:language] = Environ.language if Environ.language
164
- desired_capabilities[:locale] = Environ.locale.gsub('-', '_') if Environ.locale
161
+ desired_capabilities[:locale] = Environ.locale.gsub('-', '_') if Environ.locale
165
162
  end
166
163
  end
167
164
  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']
165
+ desired_capabilities[:safariInitialUrl] = ENV['APP_INITIAL_URL'] if ENV['APP_INITIAL_URL']
166
+ desired_capabilities[:safariAllowPopups] = ENV['APP_ALLOW_POPUPS'] if ENV['APP_ALLOW_POPUPS']
167
+ desired_capabilities[:shutdownOtherSimulators] = ENV['SHUTDOWN_OTHER_SIMS'] if ENV['SHUTDOWN_OTHER_SIMS']
168
+ desired_capabilities[:forceSimulatorSoftwareKeyboardPresence] = ENV['SHOW_SIM_KEYBOARD'] if ENV['SHOW_SIM_KEYBOARD']
169
+
170
+ desired_capabilities[:autoAcceptAlerts] = ENV['AUTO_ACCEPT_ALERTS'] if ENV['AUTO_ACCEPT_ALERTS']
171
+ desired_capabilities[:autoDismissAlerts] = ENV['AUTO_DISMISS_ALERTS'] if ENV['AUTO_DISMISS_ALERTS']
172
+ desired_capabilities[:isHeadless] = ENV['HEADLESS'] if ENV['HEADLESS']
173
+
174
+ desired_capabilities[:newCommandTimeout] = ENV['NEW_COMMAND_TIMEOUT'] if ENV['NEW_COMMAND_TIMEOUT']
175
+ desired_capabilities[:noReset] = ENV['APP_NO_RESET'] if ENV['APP_NO_RESET']
176
+ desired_capabilities[:fullReset] = ENV['APP_FULL_RESET'] if ENV['APP_FULL_RESET']
177
+ desired_capabilities[:webkitDebugProxyPort] = ENV['WEBKIT_DEBUG_PROXY_PORT'] if ENV['WEBKIT_DEBUG_PROXY_PORT']
178
+ desired_capabilities[:webDriverAgentUrl] = ENV['WEBDRIVER_AGENT_URL'] if ENV['WEBDRIVER_AGENT_URL']
179
+ desired_capabilities[:usePrebuiltWDA] = ENV['USE_PREBUILT_WDA'] if ENV['USE_PREBUILT_WDA']
180
+ desired_capabilities[:useNewWDA] = ENV['USE_NEW_WDA'] if ENV['USE_NEW_WDA']
182
181
  desired_capabilities[:chromedriverExecutable] = ENV['CHROMEDRIVER_EXECUTABLE'] if ENV['CHROMEDRIVER_EXECUTABLE']
183
182
  # set wdaLocalPort (iOS) or systemPort (Android) if PARALLEL_PORT is true
184
183
  if ENV['PARALLEL'] && ENV['PARALLEL_PORT']
@@ -193,7 +192,7 @@ module TestCentricity
193
192
  end
194
193
 
195
194
  unless desired_caps.nil?
196
- desired_capabilities = merge_caps ? desired_capabilities.merge(desired_caps) : desired_caps
195
+ desired_capabilities = desired_caps
197
196
  end
198
197
 
199
198
  Capybara.register_driver :appium do |app|
@@ -202,25 +201,27 @@ module TestCentricity
202
201
  appium_lib: appium_lib_options,
203
202
  caps: desired_capabilities
204
203
  }
205
- Appium::Capybara::Driver.new app, all_options
204
+ Appium::Capybara::Driver.new(app, all_options)
206
205
  end
207
206
  end
208
207
 
209
208
  def self.initialize_local_browser
210
- Environ.os = if OS.osx?
209
+ Environ.os = case
210
+ when OS.osx?
211
211
  'OS X'
212
- elsif OS.windows?
212
+ when OS.windows?
213
213
  'Windows'
214
- elsif OS.linux?
214
+ when OS.linux?
215
215
  'Linux'
216
+ else
217
+ 'unknown'
216
218
  end
217
-
218
219
  browser = ENV['WEB_BROWSER'].downcase.to_sym
219
220
 
220
221
  case browser
221
222
  when :firefox, :chrome, :ie, :safari, :edge
222
223
  Environ.platform = :desktop
223
- when :chrome_headless, :firefox_headless
224
+ when :chrome_headless, :firefox_headless, :edge_headless
224
225
  Environ.platform = :desktop
225
226
  Environ.headless = true
226
227
  else
@@ -231,9 +232,8 @@ module TestCentricity
231
232
  Capybara.register_driver :selenium do |app|
232
233
  case browser
233
234
  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
235
+ Capybara::Selenium::Driver.new(app, browser: browser)
236
+ when :ie
237
237
  Capybara::Selenium::Driver.new(app, browser: browser)
238
238
  when :firefox, :firefox_headless
239
239
  profile = Selenium::WebDriver::Firefox::Profile.new
@@ -253,16 +253,15 @@ module TestCentricity
253
253
  profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
254
254
  options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
255
255
  options.args << '--headless' if browser == :firefox_headless
256
- Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
256
+ Capybara::Selenium::Driver.new(app, browser: :firefox, capabilities: [options])
257
257
  when :chrome, :chrome_headless
258
- options = Selenium::WebDriver::Chrome::Options.new
258
+ options = Selenium::WebDriver::Chrome::Options.new(options: {'excludeSwitches' => ['enable-automation']})
259
259
  prefs = {
260
260
  prompt_for_download: false,
261
261
  directory_upgrade: true,
262
262
  default_directory: @downloads_path
263
263
  }
264
264
  options.add_preference(:download, prefs)
265
- options.add_argument('--disable-infobars')
266
265
  options.add_argument('--disable-dev-shm-usage')
267
266
  options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
268
267
  if browser == :chrome_headless
@@ -271,7 +270,24 @@ module TestCentricity
271
270
  options.add_argument('--no-sandbox')
272
271
  end
273
272
 
274
- Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
273
+ Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: [options])
274
+ when :edge, :edge_headless
275
+ options = Selenium::WebDriver::Edge::Options.new(options: {'excludeSwitches' => ['enable-automation']})
276
+ prefs = {
277
+ prompt_for_download: false,
278
+ directory_upgrade: true,
279
+ default_directory: @downloads_path
280
+ }
281
+ options.add_preference(:download, prefs)
282
+ options.add_argument('--disable-dev-shm-usage')
283
+ options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
284
+ if browser == :edge_headless
285
+ options.add_argument('--headless')
286
+ options.add_argument('--disable-gpu')
287
+ options.add_argument('--no-sandbox')
288
+ end
289
+
290
+ Capybara::Selenium::Driver.new(app, browser: :edge, capabilities: [options])
275
291
  else
276
292
  if ENV['HOST_BROWSER'] && ENV['HOST_BROWSER'].downcase.to_sym == :chrome
277
293
  user_agent = Browsers.mobile_device_agent(ENV['WEB_BROWSER'])
@@ -280,7 +296,7 @@ module TestCentricity
280
296
  options.add_argument('--disable-dev-shm-usage')
281
297
  options.add_argument("--user-agent='#{user_agent}'")
282
298
  options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
283
- Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
299
+ Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: [options])
284
300
  else
285
301
  raise "Requested browser '#{browser}' is not supported"
286
302
  end
@@ -289,111 +305,95 @@ module TestCentricity
289
305
  Capybara.default_driver = :selenium
290
306
  end
291
307
 
292
- def self.initialize_browserstack(desired_caps = nil, merge_caps = false)
308
+ def self.initialize_browserstack(desired_caps = nil)
293
309
  browser = ENV['BS_BROWSER']
294
310
  Environ.grid = :browserstack
295
311
 
296
- if ENV['BS_REAL_MOBILE'] || ENV['BS_PLATFORM']
312
+ if ENV['BS_REAL_MOBILE'] || ENV['BS_DEVICE']
297
313
  Environ.platform = :mobile
298
314
  Environ.device_name = ENV['BS_DEVICE']
299
315
  Environ.device_os = ENV['BS_OS']
300
316
  Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
317
+ Environ.device = if ENV['BS_REAL_MOBILE']
318
+ :device
319
+ else
320
+ :simulator
321
+ end
301
322
  elsif ENV['BS_OS']
302
323
  Environ.os = "#{ENV['BS_OS']} #{ENV['BS_OS_VERSION']}"
303
324
  end
304
- Environ.device = if ENV['BS_REAL_MOBILE']
305
- :device
306
- elsif ENV['BS_PLATFORM']
307
- :simulator
308
- end
309
-
325
+ # specify endpoint url
310
326
  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
327
+ # enable tunneling if specified
328
+ if ENV['TUNNELING']
329
+ @bs_local = BrowserStack::Local.new
330
+ bs_local_args = {'key' => "#{ENV['BS_AUTHKEY']}"}
331
+ @bs_local.start(bs_local_args)
332
+ if @bs_local.isRunning
333
+ puts 'BrowserStack Local instance has been started'
334
+ else
335
+ puts 'BrowserStack Local instance failed to start'
394
336
  end
395
-
396
- Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
337
+ end
338
+ # define BrowserStack options
339
+ options = if desired_caps.nil?
340
+ browser_options = {}
341
+ # define the required set of BrowserStack options
342
+ bs_options = {
343
+ userName: ENV['BS_USERNAME'],
344
+ accessKey: ENV['BS_AUTHKEY'],
345
+ sessionName: test_context_message,
346
+ os: ENV['BS_OS'],
347
+ osVersion: ENV['BS_OS_VERSION']
348
+ }
349
+ # define browser specific BrowserStack options
350
+ case browser.downcase.to_sym
351
+ when :safari
352
+ browser_options[:enablePopups] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
353
+ browser_options[:allowAllCookies] = ENV['ALLOW_COOKIES'] if ENV['ALLOW_COOKIES']
354
+ bs_options[:safari] = browser_options unless browser_options.empty?
355
+ when :ie
356
+ browser_options[:enablePopups] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
357
+ bs_options[:ie] = browser_options unless browser_options.empty?
358
+ when :edge
359
+ browser_options[:enablePopups] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
360
+ bs_options[:edge] = browser_options unless browser_options.empty?
361
+ end
362
+ # define the optional BrowserStack options
363
+ bs_options[:projectName] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
364
+ bs_options[:buildName] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
365
+ bs_options[:headless] = ENV['HEADLESS'] if ENV['HEADLESS']
366
+ bs_options[:timezone] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
367
+ bs_options[:geoLocation] = ENV['IP_GEOLOCATION'] if ENV['IP_GEOLOCATION']
368
+ bs_options[:video] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
369
+ bs_options[:debug] = ENV['SCREENSHOTS'] if ENV['SCREENSHOTS']
370
+ bs_options[:networkLogs] = ENV['NETWORK_LOGS'] if ENV['NETWORK_LOGS']
371
+ bs_options[:local] = ENV['TUNNELING'] if ENV['TUNNELING']
372
+ bs_options[:deviceOrientation] = ENV['ORIENTATION'] if ENV['ORIENTATION']
373
+ bs_options[:appiumLogs] = ENV['APPIUM_LOGS'] if ENV['APPIUM_LOGS']
374
+ bs_options[:realMobile] = ENV['BS_REAL_MOBILE'] if ENV['BS_REAL_MOBILE']
375
+ if ENV['BS_DEVICE']
376
+ bs_options[:deviceName] = ENV['BS_DEVICE']
377
+ bs_options[:appiumVersion] = '1.22.0'
378
+ {
379
+ browserName: browser,
380
+ 'bstack:options': bs_options
381
+ }
382
+ else
383
+ bs_options[:resolution] = ENV['RESOLUTION'] if ENV['RESOLUTION']
384
+ bs_options[:seleniumVersion] = '4.1.0'
385
+ {
386
+ browserName: browser,
387
+ browserVersion: ENV['BS_VERSION'],
388
+ 'bstack:options': bs_options
389
+ }
390
+ end
391
+ else
392
+ desired_caps
393
+ end
394
+ Capybara.register_driver :browserstack do |app|
395
+ capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser.gsub(/\s+/, '_').downcase.to_sym, options)
396
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, capabilities: capabilities)
397
397
  end
398
398
 
399
399
  Environ.browser = browser
@@ -410,7 +410,7 @@ module TestCentricity
410
410
  end
411
411
  end
412
412
 
413
- def self.initialize_crossbrowser(desired_caps = nil, merge_caps = false)
413
+ def self.initialize_crossbrowser(desired_caps = nil)
414
414
  browser = ENV['CB_BROWSER']
415
415
  Environ.grid = :crossbrowser
416
416
 
@@ -439,7 +439,7 @@ module TestCentricity
439
439
  end
440
440
 
441
441
  unless desired_caps.nil?
442
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
442
+ capabilities = desired_caps
443
443
  end
444
444
 
445
445
  Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
@@ -457,7 +457,7 @@ module TestCentricity
457
457
  end
458
458
  end
459
459
 
460
- def self.initialize_gridlastic(desired_caps = nil, merge_caps = false)
460
+ def self.initialize_gridlastic(desired_caps = nil)
461
461
  browser = ENV['GL_BROWSER']
462
462
  Environ.grid = :gridlastic
463
463
  Environ.os = ENV['GL_OS']
@@ -470,7 +470,7 @@ module TestCentricity
470
470
  capabilities['video'] = ENV['RECORD_VIDEO'].capitalize if ENV['RECORD_VIDEO']
471
471
 
472
472
  unless desired_caps.nil?
473
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
473
+ capabilities = desired_caps
474
474
  end
475
475
 
476
476
  Capybara.register_driver :selenium do |app|
@@ -496,50 +496,55 @@ module TestCentricity
496
496
  end
497
497
  end
498
498
 
499
- def self.initialize_lambdatest(desired_caps = nil, merge_caps = false)
499
+ def self.initialize_lambdatest(desired_caps = nil)
500
500
  browser = ENV['LT_BROWSER']
501
501
  Environ.grid = :lambdatest
502
502
  Environ.os = ENV['LT_OS']
503
503
  Environ.platform = :desktop
504
504
  Environ.tunneling = ENV['TUNNELING'] if ENV['TUNNELING']
505
-
506
- endpoint = "http://#{ENV['LT_USERNAME']}:#{ENV['LT_AUTHKEY']}@hub.lambdatest.com/wd/hub"
505
+ # specify endpoint url
506
+ endpoint = "https://#{ENV['LT_USERNAME']}:#{ENV['LT_AUTHKEY']}@hub.lambdatest.com/wd/hub"
507
+ # define LambdaTest options
508
+ options = if desired_caps.nil?
509
+ # define the required set of LambdaTest options
510
+ lt_options = {
511
+ user: ENV['LT_USERNAME'],
512
+ accessKey: ENV['LT_AUTHKEY'],
513
+ build: test_context_message,
514
+ platformName: ENV['LT_OS'],
515
+ resolution: ENV['RESOLUTION'],
516
+ selenium_version: '4.0.0',
517
+ }
518
+ # define the optional LambdaTest options
519
+ lt_options[:name] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
520
+ lt_options[:headless] = ENV['HEADLESS'] if ENV['HEADLESS']
521
+ lt_options[:timezone] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
522
+ lt_options[:geoLocation] = ENV['GEO_LOCATION'] if ENV['GEO_LOCATION']
523
+ lt_options[:video] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
524
+ lt_options[:visual] = ENV['SCREENSHOTS'] if ENV['SCREENSHOTS']
525
+ lt_options[:network] = ENV['NETWORK_LOGS'] if ENV['NETWORK_LOGS']
526
+ lt_options[:tunnel] = ENV['TUNNELING'] if ENV['TUNNELING']
527
+ # define browser specific LambdaTest options
528
+ case browser.downcase.to_sym
529
+ when :safari
530
+ lt_options['safari.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
531
+ lt_options['safari.cookies'] = ENV['ALLOW_COOKIES'] if ENV['ALLOW_COOKIES']
532
+ when :ie
533
+ lt_options['ie.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
534
+ when :microsoftedge
535
+ lt_options['edge.popups'] = ENV['ALLOW_POPUPS'] if ENV['ALLOW_POPUPS']
536
+ end
537
+ {
538
+ browserName: browser,
539
+ browserVersion: ENV['LT_VERSION'],
540
+ 'LT:Options': lt_options
541
+ }
542
+ else
543
+ desired_caps
544
+ end
507
545
  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)
546
+ capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser.gsub(/\s+/, '_').downcase.to_sym, options)
547
+ Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, capabilities: capabilities)
543
548
  end
544
549
 
545
550
  Environ.browser = browser
@@ -602,7 +607,7 @@ module TestCentricity
602
607
  Capybara.default_driver = :remote_browser
603
608
  end
604
609
 
605
- def self.initialize_saucelabs(desired_caps = nil, merge_caps = false)
610
+ def self.initialize_saucelabs(desired_caps = nil)
606
611
  browser = ENV['SL_BROWSER']
607
612
  Environ.grid = :saucelabs
608
613
 
@@ -633,7 +638,7 @@ module TestCentricity
633
638
  end
634
639
 
635
640
  unless desired_caps.nil?
636
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
641
+ capabilities = desired_caps
637
642
  end
638
643
 
639
644
  Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
@@ -651,7 +656,7 @@ module TestCentricity
651
656
  end
652
657
  end
653
658
 
654
- def self.initialize_testingbot(desired_caps = nil, merge_caps = false)
659
+ def self.initialize_testingbot(desired_caps = nil)
655
660
  browser = ENV['TB_BROWSER']
656
661
  Environ.grid = :testingbot
657
662
 
@@ -685,7 +690,7 @@ module TestCentricity
685
690
  end
686
691
 
687
692
  unless desired_caps.nil?
688
- capabilities = merge_caps ? capabilities.merge(desired_caps) : desired_caps
693
+ capabilities = desired_caps
689
694
  end
690
695
 
691
696
  Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
@@ -702,5 +707,19 @@ module TestCentricity
702
707
  str if File.exist?(str)
703
708
  end
704
709
  end
710
+
711
+ def self.test_context_message
712
+ context_message = if ENV['TEST_CONTEXT']
713
+ "#{Environ.test_environment.to_s.upcase} - #{ENV['TEST_CONTEXT']}"
714
+ else
715
+ Environ.test_environment.to_s.upcase
716
+ end
717
+ if ENV['PARALLEL']
718
+ thread_num = ENV['TEST_ENV_NUMBER']
719
+ thread_num = 1 if thread_num.blank?
720
+ context_message = "#{context_message} - Thread ##{thread_num}"
721
+ end
722
+ context_message
723
+ end
705
724
  end
706
725
  end