Class: Maze::Client::Selenium::BrowserStackClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/maze/client/selenium/bs_client.rb

Instance Method Summary collapse

Instance Method Details

#log_run_outroObject



64
65
66
# File 'lib/maze/client/selenium/bs_client.rb', line 64

def log_run_outro
  log_session_info
end

#start_sessionObject



7
8
9
10
11
12
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
# File 'lib/maze/client/selenium/bs_client.rb', line 7

def start_session
  # Set up the capabilities
  browsers = YAML.safe_load(File.read("#{__dir__}/bs_browsers.yml"))

  config = Maze.config
  browser = browsers[config.browser]

  if config.legacy_driver?
    capabilities = ::Selenium::WebDriver::Remote::Capabilities.new
    capabilities['browserstack.local'] = 'true'
    capabilities['browserstack.localIdentifier'] = Maze.run_uuid
    capabilities['browserstack.console'] = 'errors'
    capabilities['acceptInsecureCerts'] = 'true'

    # Convert W3S capabilities to JSON-WP
    capabilities['browser'] = browser['browserName']
    capabilities['browser_version'] = browser['browserVersion']
    capabilities['device'] = browser['device']
    capabilities['os'] = browser['os']
    capabilities['os_version'] = browser['osVersion']

    capabilities.merge! JSON.parse(config.capabilities_option)
    capabilities.merge! project_name_capabilities
    config.capabilities = capabilities
  else
    capabilities = {
      'acceptInsecureCerts' => true,
      'bstack:options' => {
        'local' => 'true',
        'localIdentifier' => Maze.run_uuid
      }
    }
    capabilities.deep_merge! browser
    capabilities.deep_merge! JSON.parse(config.capabilities_option)
    capabilities.merge! project_name_capabilities
    config.capabilities = ::Selenium::WebDriver::Remote::Capabilities.new capabilities
  end

  # Start the tunnel
  Maze::Client::BrowserStackClientUtils.start_local_tunnel config.bs_local,
                                                           Maze.run_uuid,
                                                           config.access_key

  # Start the driver
  selenium_url = "https://#{config.username}:#{config.access_key}@hub.browserstack.com/wd/hub"
  Maze.driver = Maze::Driver::Browser.new :remote, selenium_url, config.capabilities
  Maze.driver.start_driver

  # Log details for the session
  log_session_info
end

#stop_sessionObject



59
60
61
62
# File 'lib/maze/client/selenium/bs_client.rb', line 59

def stop_session
  super
  Maze::Client::BrowserStackClientUtils.stop_local_tunnel
end