testcentricity_web 4.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,14 +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
18
+ @endpoint = nil
19
+ @capabilities = nil
17
20
  if options.is_a?(String)
18
21
  Capybara.app_host = options
19
22
  elsif options.is_a?(Hash)
20
23
  Capybara.app_host = options[:app_host] if options.key?(:app_host)
21
- desired_caps = options[:desired_capabilities] if options.key?(:desired_capabilities)
24
+ @endpoint = options[:endpoint] if options.key?(:endpoint)
25
+ @capabilities = options[:desired_capabilities] if options.key?(:desired_capabilities)
22
26
  end
23
27
 
24
28
  browser = ENV['WEB_BROWSER']
@@ -44,25 +48,19 @@ module TestCentricity
44
48
 
45
49
  context = case browser.downcase.to_sym
46
50
  when :appium
47
- initialize_appium(desired_caps)
51
+ initialize_appium
48
52
  'mobile device emulator'
49
53
  when :browserstack
50
- initialize_browserstack(desired_caps)
54
+ initialize_browserstack
51
55
  'Browserstack cloud service'
52
- when :crossbrowser
53
- initialize_crossbrowser(desired_caps)
54
- 'CrossBrowserTesting cloud service'
55
- when :gridlastic
56
- initialize_gridlastic(desired_caps)
57
- 'Gridlastic cloud service'
58
56
  when :lambdatest
59
- initialize_lambdatest(desired_caps)
57
+ initialize_lambdatest
60
58
  'LambdaTest cloud service'
61
59
  when :saucelabs
62
- initialize_saucelabs(desired_caps)
60
+ initialize_saucelabs
63
61
  'Sauce Labs cloud service'
64
62
  when :testingbot
65
- initialize_testingbot(desired_caps)
63
+ initialize_testingbot
66
64
  'TestingBot cloud service'
67
65
  else
68
66
  if ENV['SELENIUM'] == 'remote'
@@ -75,7 +73,7 @@ module TestCentricity
75
73
  end
76
74
 
77
75
  # set browser window size only if testing with a desktop web browser
78
- unless Environ.is_device? || Capybara.current_driver == :appium
76
+ unless Environ.is_device? || Environ.is_simulator? || Capybara.current_driver == :appium
79
77
  initialize_browser_size
80
78
  end
81
79
 
@@ -131,7 +129,7 @@ module TestCentricity
131
129
 
132
130
  private
133
131
 
134
- def self.initialize_appium(desired_caps = nil)
132
+ def self.initialize_appium
135
133
  Environ.platform = :mobile
136
134
  Environ.device_name = ENV['APP_DEVICE']
137
135
  Environ.device_os = ENV['APP_PLATFORM_NAME'].downcase.to_sym
@@ -139,7 +137,7 @@ module TestCentricity
139
137
  Environ.device_os_version = ENV['APP_VERSION']
140
138
  Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
141
139
  Capybara.default_driver = :appium
142
- endpoint = 'http://localhost:4723/wd/hub'
140
+ @endpoint = 'http://localhost:4723/wd/hub' if @endpoint.nil?
143
141
  desired_capabilities = {
144
142
  platformName: Environ.device_os,
145
143
  platformVersion: Environ.device_os_version,
@@ -191,12 +189,12 @@ module TestCentricity
191
189
  desired_capabilities[:systemPort] = ENV['SYSTEM_PORT'] if ENV['SYSTEM_PORT']
192
190
  end
193
191
 
194
- unless desired_caps.nil?
195
- desired_capabilities = desired_caps
192
+ unless @capabilities.nil?
193
+ desired_capabilities = @capabilities
196
194
  end
197
195
 
198
196
  Capybara.register_driver :appium do |app|
199
- appium_lib_options = { server_url: endpoint }
197
+ appium_lib_options = { server_url: @endpoint }
200
198
  all_options = {
201
199
  appium_lib: appium_lib_options,
202
200
  caps: desired_capabilities
@@ -231,9 +229,7 @@ module TestCentricity
231
229
 
232
230
  Capybara.register_driver :selenium do |app|
233
231
  case browser
234
- when :safari
235
- Capybara::Selenium::Driver.new(app, browser: browser)
236
- when :ie
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
@@ -291,7 +287,7 @@ module TestCentricity
291
287
  else
292
288
  if ENV['HOST_BROWSER'] && ENV['HOST_BROWSER'].downcase.to_sym == :chrome
293
289
  user_agent = Browsers.mobile_device_agent(ENV['WEB_BROWSER'])
294
- options = Selenium::WebDriver::Chrome::Options.new
290
+ options = Selenium::WebDriver::Chrome::Options.new(options: {'excludeSwitches' => ['enable-automation']})
295
291
  options.add_argument('--disable-infobars')
296
292
  options.add_argument('--disable-dev-shm-usage')
297
293
  options.add_argument("--user-agent='#{user_agent}'")
@@ -305,7 +301,7 @@ module TestCentricity
305
301
  Capybara.default_driver = :selenium
306
302
  end
307
303
 
308
- def self.initialize_browserstack(desired_caps = nil)
304
+ def self.initialize_browserstack
309
305
  browser = ENV['BS_BROWSER']
310
306
  Environ.grid = :browserstack
311
307
 
@@ -323,7 +319,7 @@ module TestCentricity
323
319
  Environ.os = "#{ENV['BS_OS']} #{ENV['BS_OS_VERSION']}"
324
320
  end
325
321
  # specify endpoint url
326
- endpoint = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub-cloud.browserstack.com/wd/hub"
322
+ @endpoint = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub-cloud.browserstack.com/wd/hub" if @endpoint.nil?
327
323
  # enable tunneling if specified
328
324
  if ENV['TUNNELING']
329
325
  @bs_local = BrowserStack::Local.new
@@ -336,7 +332,7 @@ module TestCentricity
336
332
  end
337
333
  end
338
334
  # define BrowserStack options
339
- options = if desired_caps.nil?
335
+ options = if @capabilities.nil?
340
336
  browser_options = {}
341
337
  # define the required set of BrowserStack options
342
338
  bs_options = {
@@ -372,6 +368,7 @@ module TestCentricity
372
368
  bs_options[:deviceOrientation] = ENV['ORIENTATION'] if ENV['ORIENTATION']
373
369
  bs_options[:appiumLogs] = ENV['APPIUM_LOGS'] if ENV['APPIUM_LOGS']
374
370
  bs_options[:realMobile] = ENV['BS_REAL_MOBILE'] if ENV['BS_REAL_MOBILE']
371
+ # define mobile device options
375
372
  if ENV['BS_DEVICE']
376
373
  bs_options[:deviceName] = ENV['BS_DEVICE']
377
374
  bs_options[:appiumVersion] = '1.22.0'
@@ -380,6 +377,7 @@ module TestCentricity
380
377
  'bstack:options': bs_options
381
378
  }
382
379
  else
380
+ # define desktop browser options
383
381
  bs_options[:resolution] = ENV['RESOLUTION'] if ENV['RESOLUTION']
384
382
  bs_options[:seleniumVersion] = '4.1.0'
385
383
  {
@@ -389,123 +387,25 @@ module TestCentricity
389
387
  }
390
388
  end
391
389
  else
392
- desired_caps
390
+ @capabilities
393
391
  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
- end
398
-
399
- Environ.browser = browser
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)
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 = 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
- end
459
-
460
- def self.initialize_gridlastic(desired_caps = nil)
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 = 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
397
  end
498
398
 
499
- def self.initialize_lambdatest(desired_caps = nil)
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
405
  # specify endpoint url
506
- endpoint = "https://#{ENV['LT_USERNAME']}:#{ENV['LT_AUTHKEY']}@hub.lambdatest.com/wd/hub"
406
+ @endpoint = "https://#{ENV['LT_USERNAME']}:#{ENV['LT_AUTHKEY']}@hub.lambdatest.com/wd/hub" if @endpoint.nil?
507
407
  # define LambdaTest options
508
- options = if desired_caps.nil?
408
+ options = if @capabilities.nil?
509
409
  # define the required set of LambdaTest options
510
410
  lt_options = {
511
411
  user: ENV['LT_USERNAME'],
@@ -540,62 +440,89 @@ module TestCentricity
540
440
  'LT:Options': lt_options
541
441
  }
542
442
  else
543
- desired_caps
443
+ @capabilities
544
444
  end
545
- Capybara.register_driver :lambdatest do |app|
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)
548
- end
549
-
550
- Environ.browser = browser
551
-
552
- Capybara.default_driver = :lambdatest
553
- Capybara.run_server = false
445
+ register_remote_driver(:lambdatest, browser, options)
554
446
  # configure file_detector for remote uploads
555
- selenium = Capybara.page.driver.browser
556
- selenium.file_detector = lambda do |args|
557
- str = args.first.to_s
558
- str if File.exist?(str)
559
- end
447
+ config_file_uploads
560
448
  end
561
449
 
562
450
  def self.initialize_remote
563
451
  Environ.grid = :selenium_grid
564
452
  browser = ENV['WEB_BROWSER'].downcase.to_sym
565
- 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?
566
454
  Capybara.register_driver :remote_browser do |app|
567
455
  case browser
568
- when :firefox, :safari, :ie, :edge
569
- 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
570
478
  when :chrome, :chrome_headless
571
- options = %w[--disable-infobars]
572
- options.push('--disable-dev-shm-usage')
573
- 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']
574
488
  if browser == :chrome_headless
575
- Environ.headless = true
576
- options.push('--headless')
577
- options.push('--disable-gpu')
578
- 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')
579
507
  end
580
- capabilities = Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => { args: options })
581
508
  else
582
509
  if ENV['HOST_BROWSER'] && ENV['HOST_BROWSER'].downcase.to_sym == :chrome
583
510
  Environ.platform = :mobile
584
511
  Environ.device_name = Browsers.mobile_device_name(ENV['WEB_BROWSER'])
585
512
  user_agent = Browsers.mobile_device_agent(ENV['WEB_BROWSER'])
586
- options = %w[--disable-infobars]
587
- options.push('--disable-dev-shm-usage')
588
- options.push("--user-agent='#{user_agent}'")
589
- options.push("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
590
- 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']
591
518
  else
592
519
  raise "Requested browser '#{browser}' is not supported on Selenium Grid"
593
520
  end
594
521
  end
595
522
  Capybara::Selenium::Driver.new(app,
596
523
  browser: :remote,
597
- url: endpoint,
598
- desired_capabilities: capabilities).tap do |driver|
524
+ url: @endpoint,
525
+ capabilities: [options]).tap do |driver|
599
526
  # configure file_detector for remote uploads
600
527
  driver.browser.file_detector = lambda do |args|
601
528
  str = args.first.to_s
@@ -607,7 +534,7 @@ module TestCentricity
607
534
  Capybara.default_driver = :remote_browser
608
535
  end
609
536
 
610
- def self.initialize_saucelabs(desired_caps = nil)
537
+ def self.initialize_saucelabs
611
538
  browser = ENV['SL_BROWSER']
612
539
  Environ.grid = :saucelabs
613
540
 
@@ -616,47 +543,54 @@ module TestCentricity
616
543
  Environ.os = ENV['SL_OS']
617
544
  elsif ENV['SL_PLATFORM']
618
545
  Environ.device_name = ENV['SL_DEVICE']
619
- Environ.platform = :mobile
620
- end
621
-
622
- endpoint = "http://#{ENV['SL_USERNAME']}:#{ENV['SL_AUTHKEY']}@ondemand.saucelabs.com:80/wd/hub"
623
- Capybara.register_driver :saucelabs do |app|
624
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
625
- capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
626
- capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
627
- capabilities['browserName'] = browser
628
- capabilities['version'] = ENV['SL_VERSION'] if ENV['SL_VERSION']
629
- capabilities['screenResolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
630
- capabilities['recordVideo'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
631
- if ENV['SL_OS']
632
- capabilities['platform'] = ENV['SL_OS']
633
- elsif ENV['SL_PLATFORM']
634
- capabilities['platform'] = ENV['SL_PLATFORM']
635
- capabilities['deviceName'] = ENV['SL_DEVICE']
636
- capabilities['deviceType'] = ENV['SL_DEVICE_TYPE'] if ENV['SL_DEVICE_TYPE']
637
- capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
638
- end
639
-
640
- unless desired_caps.nil?
641
- capabilities = desired_caps
642
- end
643
-
644
- 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
645
549
  end
646
-
647
- Environ.browser = browser
648
-
649
- Capybara.default_driver = :saucelabs
650
- 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)
651
589
  # configure file_detector for remote uploads
652
- selenium = Capybara.page.driver.browser
653
- selenium.file_detector = lambda do |args|
654
- str = args.first.to_s
655
- str if File.exist?(str)
656
- end
590
+ config_file_uploads
657
591
  end
658
592
 
659
- def self.initialize_testingbot(desired_caps = nil)
593
+ def self.initialize_testingbot
660
594
  browser = ENV['TB_BROWSER']
661
595
  Environ.grid = :testingbot
662
596
 
@@ -671,41 +605,43 @@ module TestCentricity
671
605
  else
672
606
  Environ.platform = :desktop
673
607
  end
674
-
675
- endpoint = ENV['TUNNELING'] ? '@localhost:4445/wd/hub' : '@hub.testingbot.com:4444/wd/hub'
676
- endpoint = "http://#{ENV['TB_USERNAME']}:#{ENV['TB_AUTHKEY']}#{endpoint}"
677
- Capybara.register_driver :testingbot do |app|
678
- capabilities = Selenium::WebDriver::Remote::Capabilities.new
679
- capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
680
- capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
681
- capabilities['browserName'] = browser
682
- capabilities['version'] = ENV['TB_VERSION'] if ENV['TB_VERSION']
683
- capabilities['screen-resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
684
- capabilities['platform'] = ENV['TB_OS']
685
- capabilities['record_video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
686
- if ENV['TB_PLATFORM']
687
- capabilities['orientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
688
- capabilities['platformName'] = ENV['TB_PLATFORM']
689
- capabilities['deviceName'] = ENV['TB_DEVICE']
690
- end
691
-
692
- unless desired_caps.nil?
693
- capabilities = desired_caps
694
- end
695
-
696
- Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
697
- end
698
-
699
- Environ.browser = browser
700
-
701
- Capybara.default_driver = :testingbot
702
- Capybara.run_server = false
703
- # configure file_detector for remote uploads
704
- selenium = Capybara.page.driver.browser
705
- selenium.file_detector = lambda do |args|
706
- str = args.first.to_s
707
- str if File.exist?(str)
708
- 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']
709
645
  end
710
646
 
711
647
  def self.test_context_message
@@ -721,5 +657,26 @@ module TestCentricity
721
657
  end
722
658
  context_message
723
659
  end
660
+
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)
665
+ end
666
+
667
+ Environ.browser = browser
668
+
669
+ Capybara.default_driver = driver
670
+ Capybara.run_server = false
671
+ end
672
+
673
+ def self.config_file_uploads
674
+ # configure file_detector for remote uploads
675
+ selenium = Capybara.page.driver.browser
676
+ selenium.file_detector = lambda do |args|
677
+ str = args.first.to_s
678
+ str if File.exist?(str)
679
+ end
680
+ end
724
681
  end
725
682
  end
@@ -13,12 +13,11 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = 'A Page Object and Data Object Model Framework for desktop and mobile web testing'
14
14
  spec.description = '
15
15
  The TestCentricity™ Web core generic framework for desktop and mobile web browser-based app testing implements
16
- a Page Object Model DSL for use with Cucumber, Capybara, and Selenium-Webdriver. The gem provides support for running
16
+ a Page Object Model DSL for use with Cucumber, Capybara, and Selenium-Webdriver v4.x. The gem provides support for running
17
17
  automated tests against locally hosted desktop browsers, locally hosted emulated mobile browsers (iOS, Android, Windows
18
18
  Phone, Blackberry, Kindle Fire) running within a local instance of Chrome, mobile Safari browsers on iOS device simulators
19
- or physical iOS devices (using Appium and XCode on OS X), mobile Chrome or Android browsers on Android Studio virtual
20
- device emulators (using Appium and Android Studio on OS X), or cloud hosted desktop or mobile web browsers (using the
21
- BrowserStack, Sauce Labs, CrossBrowserTesting, TestingBot, Gridlastic, or LambdaTest services).'
19
+ or physical iOS devices, mobile Chrome or Android browsers on Android Studio virtual device emulators, or cloud hosted
20
+ desktop or mobile web browsers (using the BrowserStack, Sauce Labs, TestingBot, or LambdaTest services).'
22
21
  spec.homepage = ''
23
22
  spec.license = 'BSD-3-Clause'
24
23
 
@@ -39,7 +38,7 @@ Gem::Specification.new do |spec|
39
38
  spec.add_runtime_dependency 'faker'
40
39
  spec.add_runtime_dependency 'i18n'
41
40
  spec.add_runtime_dependency 'os', '~> 1.0'
42
- spec.add_runtime_dependency 'selenium-webdriver'
41
+ spec.add_runtime_dependency 'selenium-webdriver', '>= 4.0', '< 5'
43
42
  spec.add_runtime_dependency 'spreadsheet', '1.1.7'
44
43
  spec.add_runtime_dependency 'test-unit'
45
44
  spec.add_runtime_dependency 'webdrivers', '~> 5.0'