Class: Maze::Client::Selenium::BaseClient

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

Direct Known Subclasses

BitBarClient, BrowserStackClient, LocalClient

Instance Method Summary collapse

Instance Method Details

#handle_start_error(config, error) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/maze/client/selenium/base_client.rb', line 41

def handle_start_error(config, error)
  notify = true
  interval = nil

  # Used if we have a want to determine fatal errors later
  case error.class.to_s
  when 'Selenium::WebDriver::Error::WebDriverError'
    interval = 5
    notify = false
  else
    interval = 10
  end

  Bugsnag.notify error if notify

  unless config.browser_list.empty?
    # If the list is empty we have only one browser to continue with
    config.browser = config.browser_list.shift
    config.capabilities = create_capabilities(config)
  end

  interval
end

#log_run_outroObject



65
66
67
# File 'lib/maze/client/selenium/base_client.rb', line 65

def log_run_outro
  raise 'Method not implemented by this class'
end

#start_driver(config, selenium_url, max_attempts = 5) ⇒ Object



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
# File 'lib/maze/client/selenium/base_client.rb', line 9

def start_driver(config, selenium_url, max_attempts = 5)
  attempts = 0

  while attempts < max_attempts && Maze.driver.nil?
    attempts += 1
    start_error = nil

    $logger.trace "Attempting to start Selenium driver with capabilities: #{config.capabilities.to_json}"
    $logger.trace "Attempt #{attempts}"
    begin
      Maze.driver = Maze::Driver::Browser.new(:remote, selenium_url, config.capabilities)
      Maze.driver.start_driver
    rescue => error
      Maze.driver = nil
      $logger.error "Session creation failed: #{error}"
      start_error = error
    end

    unless Maze.driver
      interval = handle_start_error(config, start_error)
      if interval.nil? || attempts >= max_attempts
        $logger.error 'Failed to create Selenium driver, exiting'
        Kernel.exit(::Maze::Api::ExitCode::SESSION_CREATION_FAILURE)
      else
        $logger.warn "Failed to create Selenium driver, retrying in #{interval} seconds"
        $logger.info "Error: #{start_error.message}" if start_error
        Kernel.sleep(interval)
      end
    end
  end
end

#start_sessionObject



5
6
7
# File 'lib/maze/client/selenium/base_client.rb', line 5

def start_session
  raise 'Method not implemented by this class'
end

#stop_sessionObject



69
70
71
# File 'lib/maze/client/selenium/base_client.rb', line 69

def stop_session
  Maze.driver.driver_quit unless Maze.driver.failed?
end