Module: TestCentricity::WebDriverConnect

Includes:
Capybara::DSL
Defined in:
lib/testcentricity_web/webdriver_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#bs_local ⇒ Object

Returns the value of attribute bs_local.



11
12
13
# File 'lib/testcentricity_web/webdriver_helper.rb', line 11

def bs_local
  @bs_local
end

#webdriver_path ⇒ Object

Returns the value of attribute webdriver_path.



10
11
12
# File 'lib/testcentricity_web/webdriver_helper.rb', line 10

def webdriver_path
  @webdriver_path
end

Class Method Details

.close_tunnel ⇒ Object



155
156
157
158
159
160
161
162
163
164
# File 'lib/testcentricity_web/webdriver_helper.rb', line 155

def self.close_tunnel
  unless @bs_local.nil?
    @bs_local.stop
    if @bs_local.isRunning
      raise 'BrowserStack Local instance could not be stopped'
    else
      puts 'BrowserStack Local instance has been stopped'
    end
  end
end

.initialize_appium ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/testcentricity_web/webdriver_helper.rb', line 168

def self.initialize_appium
  Environ.device      = true
  Environ.platform    = :mobile
  Environ.device_name = ENV['APP_DEVICE']
  Environ.device_os   = ENV['APP_PLATFORM_NAME']
  Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
  Capybara.default_driver = :appium
  endpoint = 'http://localhost:4723/wd/hub'
  desired_capabilities = {
      platformName:    ENV['APP_PLATFORM_NAME'],
      platformVersion: ENV['APP_VERSION'],
      browserName:     ENV['APP_BROWSER'],
      deviceName:      ENV['APP_DEVICE']
  }
  desired_capabilities['avd'] = ENV['APP_DEVICE'] if ENV['APP_PLATFORM_NAME'].downcase.to_sym == :android
  desired_capabilities['orientation'] = ENV['ORIENTATION'].upcase if ENV['ORIENTATION']
  desired_capabilities['udid'] = ENV['APP_UDID'] if ENV['APP_UDID']
  desired_capabilities['safariInitialUrl'] = ENV['APP_INITIAL_URL'] if ENV['APP_INITIAL_URL']
  desired_capabilities['safariAllowPopups'] = ENV['APP_ALLOW_POPUPS'] if ENV['APP_ALLOW_POPUPS']
  desired_capabilities['safariIgnoreFraudWarning'] = ENV['APP_IGNORE_FRAUD_WARNING'] if ENV['APP_IGNORE_FRAUD_WARNING']
  desired_capabilities['noReset'] = ENV['APP_NO_RESET'] if ENV['APP_NO_RESET']
  desired_capabilities['locale'] = ENV['LOCALE'] if ENV['LOCALE']

  Capybara.register_driver :appium do |app|
    appium_lib_options = { server_url: endpoint }
    all_options = {
        appium_lib:  appium_lib_options,
        caps:        desired_capabilities
    }
    Appium::Capybara::Driver.new app, all_options
  end
end

.initialize_browser_size ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/testcentricity_web/webdriver_helper.rb', line 127

def self.initialize_browser_size
  # tile browser windows if running in multiple parallel threads and BROWSER_TILE environment variable is true
  if ENV['PARALLEL'] && ENV['BROWSER_TILE']
    thread = ENV['TEST_ENV_NUMBER'].to_i
    if thread > 1
      Browsers.set_browser_window_position(100 * thread - 1, 100 * thread - 1)
      sleep(1)
    end
  else
    Browsers.set_browser_window_position(50, 50)
    sleep(1)
  end

  browser = Environ.browser.to_s
  if Environ.is_desktop?
    if ENV['BROWSER_SIZE'] == 'max'
      Browsers.maximize_browser
    elsif ENV['BROWSER_SIZE']
      Browsers.set_browser_window_size(ENV['BROWSER_SIZE'])
    else
      Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
    end
  elsif Environ.is_mobile? && !Environ.is_device?
    Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
  end
  Environ.session_state = :running
end

.initialize_browserstack ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/testcentricity_web/webdriver_helper.rb', line 322

def self.initialize_browserstack
  browser = ENV['BS_BROWSER']

  if ENV['BS_REAL_MOBILE'] || ENV['BS_PLATFORM']
    Environ.platform    = :mobile
    Environ.device      = true
    Environ.device_name = ENV['BS_DEVICE']
    Environ.device_os   = ENV['BS_OS']
    Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
    Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']

  elsif ENV['BS_OS']
    Environ.os = "#{ENV['BS_OS']} #{ENV['BS_OS_VERSION']}"
  end

  endpoint = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub-cloud.browserstack.com/wd/hub"
  Capybara.register_driver :browserstack do |app|
    capabilities = Selenium::WebDriver::Remote::Capabilities.new

    if ENV['BS_REAL_MOBILE']
      capabilities['device'] = ENV['BS_DEVICE']
      capabilities['realMobile'] = true
      capabilities['os_version'] = ENV['BS_OS_VERSION']

    elsif ENV['BS_PLATFORM']
      capabilities[:platform] = ENV['BS_PLATFORM']
      capabilities[:browserName] = browser
      capabilities['device'] = ENV['BS_DEVICE'] if ENV['BS_DEVICE']
      capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']

    elsif ENV['BS_OS']
      capabilities['os'] = ENV['BS_OS']
      capabilities['os_version'] = ENV['BS_OS_VERSION']
      capabilities['browser'] = browser || 'chrome'
      capabilities['browser_version'] = ENV['BS_VERSION'] if ENV['BS_VERSION']
      capabilities['resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
    end

    capabilities['browserstack.timezone'] = ENV['TIME_ZONE'] if ENV['TIME_ZONE']
    capabilities['browserstack.video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
    capabilities['browserstack.debug'] = 'true'
    capabilities['project'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
    capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']

    ENV['TEST_CONTEXT'] ?
        context_message = "#{Environ.test_environment} - #{ENV['TEST_CONTEXT']}" :
        context_message = Environ.test_environment
    if ENV['PARALLEL']
      thread_num = ENV['TEST_ENV_NUMBER']
      thread_num = 1 if thread_num.blank?
      context_message = "#{context_message} - Thread ##{thread_num}"
    end
    capabilities['name'] = context_message

    capabilities['acceptSslCerts'] = 'true'
    capabilities['browserstack.localIdentifier'] = ENV['BS_LOCAL_ID'] if ENV['BS_LOCAL_ID']
    capabilities['browserstack.local'] = 'true' if ENV['TUNNELING']

    case browser.downcase.to_sym
    when :ie
      capabilities['ie.ensureCleanSession'] = 'true'
      capabilities['ie.browserCommandLineSwitches'] = 'true'
      capabilities['nativeEvents'] = 'true'
    when :safari
      capabilities['cleanSession'] = 'true'
    when :iphone, :ipad
      capabilities['javascriptEnabled'] = 'true'
      capabilities['cleanSession'] = 'true'
    end

    if ENV['TUNNELING']
      @bs_local = BrowserStack::Local.new
      bs_local_args = {'key' => "#{ENV['BS_AUTHKEY']}"}
      @bs_local.start(bs_local_args)
      if @bs_local.isRunning
        puts 'BrowserStack Local instance has been started'
      else
        puts 'BrowserStack Local instance failed to start'
      end
    end

    Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
  end

  Environ.browser = browser
  Environ.tunneling = ENV['TUNNELING'] if ENV['TUNNELING']

  Capybara.default_driver = :browserstack
  Capybara.run_server = false
end

.initialize_crossbrowser ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/testcentricity_web/webdriver_helper.rb', line 413

def self.initialize_crossbrowser
  browser = ENV['CB_BROWSER']

  if ENV['CB_OS']
    Environ.os = ENV['CB_OS']
    Environ.platform = :desktop
  elsif ENV['CB_PLATFORM']
    Environ.device_name = ENV['CB_PLATFORM']
    Environ.device      = true
    Environ.platform    = :mobile
    Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
  end

  endpoint = "http://#{ENV['CB_USERNAME']}:#{ENV['CB_AUTHKEY']}@hub.crossbrowsertesting.com:80/wd/hub"
  Capybara.register_driver :crossbrowser do |app|
    capabilities = Selenium::WebDriver::Remote::Capabilities.new
    capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
    capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
    capabilities['browser_api_name'] = browser
    capabilities['screen_resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
    if ENV['CB_OS']
      capabilities['os_api_name'] = ENV['CB_OS']
      Environ.platform = :desktop
    elsif ENV['CB_PLATFORM']
      capabilities['os_api_name'] = ENV['CB_PLATFORM']
    end
    Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
  end

  Environ.browser = browser

  Capybara.default_driver = :crossbrowser
  Capybara.run_server = false
end

.initialize_local_browser ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/testcentricity_web/webdriver_helper.rb', line 201

def self.initialize_local_browser
  if OS.osx?
    Environ.os = 'OS X'
  elsif OS.windows?
    Environ.os = 'Windows'
  end

  browser = ENV['WEB_BROWSER']

  case browser.downcase.to_sym
    when :firefox, :chrome, :ie, :safari, :edge
      Environ.platform = :desktop
    else
      Environ.platform    = :mobile
      Environ.device_name = Browsers.mobile_device_name(browser)
  end

  Capybara.default_driver = :selenium
  Capybara.register_driver :selenium do |app|
    case browser.downcase.to_sym
      when :ie, :safari, :edge
        Capybara::Selenium::Driver.new(app, :browser => browser.to_sym)

      when :firefox
        if ENV['LOCALE']
          profile = Selenium::WebDriver::Firefox::Profile.new
          profile['intl.accept_languages'] = ENV['LOCALE']
          Capybara::Selenium::Driver.new(app, :profile => profile)
        else
          Capybara::Selenium::Driver.new(app, :browser => :firefox)
        end

      when :chrome
        ENV['LOCALE'] ? args = ['--disable-infobars', "--lang=#{ENV['LOCALE']}"] : args = ['--disable-infobars']
        Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args)

      else
        user_agent = Browsers.mobile_device_agent(browser)
        ENV['HOST_BROWSER'] ? host_browser = ENV['HOST_BROWSER'].downcase.to_sym : host_browser = :firefox
        case host_browser
          when :firefox
            profile = Selenium::WebDriver::Firefox::Profile.new
            profile['general.useragent.override'] = user_agent
            profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
            Capybara::Selenium::Driver.new(app, :profile => profile)

          when :chrome
            ENV['LOCALE'] ?
                args = ["--user-agent='#{user_agent}'", "--lang=#{ENV['LOCALE']}", '--disable-infobars'] :
                args = ["--user-agent='#{user_agent}'", '--disable-infobars']
            Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args)
        end
    end
  end
end

.initialize_poltergeist ⇒ Object



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/testcentricity_web/webdriver_helper.rb', line 448

def self.initialize_poltergeist
  if ENV['BROWSER_SIZE']
    resolution = ENV['BROWSER_SIZE'].split(',')
    width  = resolution[0]
    height = resolution[1]
  else
    width  = 1650
    height = 1000
  end
  Capybara.default_driver = :poltergeist
  Capybara.register_driver :poltergeist do |app|
    options = {
        js_errors:         true,
        timeout:           120,
        debug:             false,
        phantomjs_options: ['--load-images=no', '--disk-cache=false'],
        inspector:         true,
        window_size:       [width, height]
    }
    Capybara::Poltergeist::Driver.new(app, options)
  end
end

.initialize_remote ⇒ Object



471
472
473
474
475
476
477
478
479
480
# File 'lib/testcentricity_web/webdriver_helper.rb', line 471

def self.initialize_remote
  browser = ENV['WEB_BROWSER']
  endpoint = ENV['REMOTE_ENDPOINT'] || 'http://127.0.0.1:4444/wd/hub'
  capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser.downcase.to_sym)
  Capybara.register_driver :remote_browser do |app|
    Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
  end
  Capybara.current_driver = :remote_browser
  Capybara.default_driver = :remote_browser
end

.initialize_saucelabs ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/testcentricity_web/webdriver_helper.rb', line 482

def self.initialize_saucelabs
  browser = ENV['SL_BROWSER']

  if ENV['SL_OS']
    Environ.platform = :desktop
    Environ.os = ENV['SL_OS']
  elsif ENV['SL_PLATFORM']
    Environ.device_name = ENV['SL_DEVICE']
    Environ.platform    = :mobile
  end

  endpoint = "http://#{ENV['SL_USERNAME']}:#{ENV['SL_AUTHKEY']}@ondemand.saucelabs.com:80/wd/hub"
  Capybara.register_driver :saucelabs do |app|
    capabilities = Selenium::WebDriver::Remote::Capabilities.new
    capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
    capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
    capabilities['browserName'] = browser
    capabilities['version'] = ENV['SL_VERSION'] if ENV['SL_VERSION']
    capabilities['screenResolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
    capabilities['recordVideo'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
    if ENV['SL_OS']
      capabilities['platform'] = ENV['SL_OS']
    elsif ENV['SL_PLATFORM']
      capabilities['platform'] = ENV['SL_PLATFORM']
      capabilities['deviceName'] = ENV['SL_DEVICE']
      capabilities['deviceType'] = ENV['SL_DEVICE_TYPE'] if ENV['SL_DEVICE_TYPE']
      capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
    end

    Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
  end

  Environ.browser = browser

  Capybara.default_driver = :saucelabs
  Capybara.run_server = false
end

.initialize_testingbot ⇒ Object



520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/testcentricity_web/webdriver_helper.rb', line 520

def self.initialize_testingbot
  browser = ENV['TB_BROWSER']

  Environ.os = ENV['TB_OS']
  if ENV['TB_PLATFORM']
    if ENV['ORIENTATION']
      Environ.device_orientation  = ENV['ORIENTATION']
    end
    Environ.device_os   = ENV['TB_PLATFORM']
    Environ.device_name = ENV['TB_DEVICE']
    Environ.device      = true
    Environ.platform    = :mobile
    Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
  else
    Environ.platform    = :desktop
  end

  ENV['TUNNELING'] ?
      endpoint = '@localhost:4445/wd/hub' :
      endpoint = '@hub.testingbot.com:4444/wd/hub'
  endpoint = "http://#{ENV['TB_USERNAME']}:#{ENV['TB_AUTHKEY']}#{endpoint}"
  Capybara.register_driver :testingbot do |app|
    capabilities = Selenium::WebDriver::Remote::Capabilities.new
    capabilities['name'] = ENV['AUTOMATE_PROJECT'] if ENV['AUTOMATE_PROJECT']
    capabilities['build'] = ENV['AUTOMATE_BUILD'] if ENV['AUTOMATE_BUILD']
    capabilities['browserName'] = browser
    capabilities['version'] = ENV['TB_VERSION'] if ENV['TB_VERSION']
    capabilities['screen-resolution'] = ENV['RESOLUTION'] if ENV['RESOLUTION']
    capabilities['platform'] = ENV['TB_OS']
    capabilities['record_video'] = ENV['RECORD_VIDEO'] if ENV['RECORD_VIDEO']
    if ENV['TB_PLATFORM']
      if ENV['ORIENTATION']
         capabilities['orientation'] = ENV['ORIENTATION']
      end
      capabilities['platformName'] = ENV['TB_PLATFORM']
      capabilities['deviceName'] = ENV['TB_DEVICE']
    end

    Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
  end

  Environ.browser = browser

  Capybara.default_driver = :testingbot
  Capybara.run_server = false

end

.initialize_web_driver(app_host = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/testcentricity_web/webdriver_helper.rb', line 13

def self.initialize_web_driver(app_host = nil)
  Capybara.app_host = app_host unless app_host.nil?
  browser = ENV['WEB_BROWSER']

  # assume that we're testing within a local desktop web browser
  Environ.platform    = :desktop
  Environ.browser     = browser
  Environ.device      = false
  Environ.device_name = 'browser'

  case browser.downcase.to_sym
  when :appium
    initialize_appium
    context = 'mobile device emulator'
  when :browserstack
    initialize_browserstack
    context = 'Browserstack cloud service'
  when :crossbrowser
    initialize_crossbrowser
    context = 'CrossBrowserTesting cloud service'
  when :poltergeist
    initialize_poltergeist
    context = 'PhantomJS'
  when :saucelabs
    initialize_saucelabs
    context = 'Sauce Labs cloud service'
  when :testingbot
    initialize_testingbot
    context = 'TestingBot cloud service'
  else
    if ENV['SELENIUM'] == 'remote'
      initialize_remote
      context = 'Selenium Grid2'
    else
      initialize_local_browser
      context = 'local instance'
    end
  end

  # set browser window size only if testing with a desktop web browser
  unless Environ.is_device? || Capybara.current_driver == :poltergeist
    initialize_browser_size
  end

  Environ.session_state = :running
  puts "Using #{Environ.browser} browser via #{context}"
end

.new_initialize_local_browser ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/testcentricity_web/webdriver_helper.rb', line 257

def self.new_initialize_local_browser
  if OS.osx?
    Environ.os = 'OS X'
  elsif OS.windows?
    Environ.os = 'Windows'
  end

  browser = ENV['WEB_BROWSER']

  case browser.downcase.to_sym
    when :firefox, :chrome, :ie, :safari, :edge
      Environ.platform = :desktop
    else
      Environ.platform    = :mobile
      Environ.device_name = Browsers.mobile_device_name(browser)
  end

  Capybara.default_driver = :selenium
  Capybara.register_driver :selenium do |app|
    case browser.downcase.to_sym
      when :ie, :safari, :edge
        Capybara::Selenium::Driver.new(app, browser: browser.to_sym)
      when :firefox
        profile = Selenium::WebDriver::Firefox::Profile.new
        profile['browser.download.dir'] = '/tmp/webdriver-downloads'
        profile['browser.download.folderList'] = 2
        profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv, application/x-msexcel, application/excel, application/x-excel, application/vnd.ms-excel, image/png, image/jpeg, text/html, text/plain, application/pdf, application/octet-stream'
        profile['pdfjs.disabled'] = true
        profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
        options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
        if @webdriver_path.blank?
          Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
        else
          Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, driver_path: @webdriver_path)
        end
      when :chrome
        options = Selenium::WebDriver::Chrome::Options.new
        options.add_argument('--disable-infobars')
        options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
        Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
      else
        user_agent = Browsers.mobile_device_agent(browser)
        ENV['HOST_BROWSER'] ? host_browser = ENV['HOST_BROWSER'].downcase.to_sym : host_browser = :firefox
        case host_browser
          when :firefox
            profile = Selenium::WebDriver::Firefox::Profile.new
            profile['general.useragent.override'] = user_agent
            profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
            options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
            if @webdriver_path.blank?
              Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
            else
              Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, driver_path: @webdriver_path)
            end
          when :chrome
            options = Selenium::WebDriver::Chrome::Options.new
            options.add_argument('--disable-infobars')
            options.add_argument("--user-agent='#{user_agent}'")
            options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
            Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
        end
    end
  end
end

.set_domain(url) ⇒ Object



61
62
63
# File 'lib/testcentricity_web/webdriver_helper.rb', line 61

def self.set_domain(url)
  Capybara.app_host = url
end

.set_webdriver_path(project_path) ⇒ Object

Set the WebDriver path for Chrome, Firefox, IE, or Edge browsers



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/testcentricity_web/webdriver_helper.rb', line 66

def self.set_webdriver_path(project_path)
  path_to_driver = nil
  # check for existence of /webdrivers or /features/support/drivers folders
  base_path = 'features/support/drivers'
  unless File.directory?(File.join(project_path, base_path))
    base_path = 'webdrivers'
    unless File.directory?(File.join(project_path, base_path))
      raise 'Could not find WebDriver files in /webdrivers or /features/support/drivers folders'
    end
  end
  # set WebDriver path based on browser and operating system
  case ENV['WEB_BROWSER'].downcase.to_sym
  when :chrome
    if OS.osx?
      path_to_driver = 'mac/chromedriver'
    elsif OS.windows?
      path_to_driver = 'windows/chromedriver.exe'
    end
    @webdriver_path = File.join(project_path, base_path, path_to_driver)
    Selenium::WebDriver::Chrome.driver_path = @webdriver_path
  # when :firefox
  #   if OS.osx?
  #     path_to_driver = 'mac/geckodriver'
  #   elsif OS.windows?
  #     path_to_driver = 'windows/geckodriver.exe'
  #   end
  #   @webdriver_path = File.join(project_path, base_path, path_to_driver)
  #   Selenium::WebDriver::Firefox.driver_path = @webdriver_path
  when :ie
    path_to_driver = 'windows/IEDriverServer.exe'
    @webdriver_path = File.join(project_path, base_path, path_to_driver)
    Selenium::WebDriver::IE.driver_path = @webdriver_path
  when :edge
    path_to_driver = 'windows/MicrosoftWebDriver.exe'
    @webdriver_path = File.join(project_path, base_path, path_to_driver)
    Selenium::WebDriver::Edge.driver_path = @webdriver_path
  else
    if ENV['HOST_BROWSER']
      case ENV['HOST_BROWSER'].downcase.to_sym
      when :chrome
        if OS.osx?
          path_to_driver = 'mac/chromedriver'
        elsif OS.windows?
          path_to_driver = 'windows/chromedriver.exe'
        end
        @webdriver_path = File.join(project_path, base_path, path_to_driver)
        Selenium::WebDriver::Chrome.driver_path = @webdriver_path
      # when :firefox
      #   if OS.osx?
      #     path_to_driver = 'mac/geckodriver'
      #   elsif OS.windows?
      #     path_to_driver = 'windows/geckodriver.exe'
      #   end
      #   @webdriver_path = File.join(project_path, base_path, path_to_driver)
      #   Selenium::WebDriver::Firefox.driver_path = @webdriver_path
      end
    end
  end
  puts "The webdriver path is: #{@webdriver_path}" unless path_to_driver.nil?
end