Class: Unobtainium::Drivers::Selenium Private

Inherits:
Object
  • Object
show all
Extended by:
Support::Utility
Defined in:
lib/unobtainium/drivers/selenium.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Driver implementation wrapping the selenium-webdriver gem.

Direct Known Subclasses

Phantom

Constant Summary collapse

LABELS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Recognized labels for matching the driver

{
  firefox: %i[ff],
  internet_explorer: %i[internetexplorer explorer ie],
  safari: [],
  chrome: [],
  chromium: [],
}.freeze
CHROMIUM_EXECUTABLES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

When :chromium is selected, search for these executables. The resulting label will be :chrome, but with an executable path set in the options.

[
  'chromium-browser'
].freeze

Class Method Summary collapse

Methods included from Support::Utility

normalize_label

Class Method Details

.create(label, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create and return a driver instance



85
86
87
88
89
90
# File 'lib/unobtainium/drivers/selenium.rb', line 85

def create(label, options)
  # :nocov:
  driver = ::Selenium::WebDriver.for(normalize_label(label), options)
  return driver
  # :nocov:
end

.ensure_preconditions(_, _) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ensure that the driver’s preconditions are fulfilled.



50
51
52
53
54
55
56
# File 'lib/unobtainium/drivers/selenium.rb', line 50

def ensure_preconditions(_, _)
  require 'selenium-webdriver'
rescue LoadError => err
  raise LoadError, "#{err.message}: you need to add "\
        "'selenium-webdriver' to your Gemfile to use this driver!",
        err.backtrace
end

.matches?(label) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return true if the given label matches this driver implementation, false otherwise.



44
45
46
# File 'lib/unobtainium/drivers/selenium.rb', line 44

def matches?(label)
  return nil != normalize_label(label)
end

.resolve_options(label, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Selenium really wants symbol keys for the options



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/unobtainium/drivers/selenium.rb', line 60

def resolve_options(label, options)
  # Normalize label and options
  normalized = normalize_label(label)
  options = ::Collapsium::UberHash.new(options || {})

  # Merge 'caps' and 'desired_capabilities', letting the latter win
  options[:desired_capabilities] =
    ::Collapsium::UberHash.new(options['caps'])
                          .recursive_merge(options[:caps])
                          .recursive_merge(options[:desired_capabilities])
  options.delete(:caps)
  options.delete('caps')

  # Chromium is chrome, but with a different binary. Help with that.
  label, options = supplement_chromium(normalized, options)

  # Selenium expects the first level keys to be symbols *only*, so
  # indifferent access from UberHash isn't good. We have to fix that.
  options = fix_options(options)

  return label, options
end