Class: SaucelabsAdapter::SeleniumConfig

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/saucelabs_adapter/selenium_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#debug, #diagnostics_prefix, #find_unused_port, #raise_with_message, #say

Constructor Details

#initialize(configuration_name = nil, selenium_yml_path = nil) ⇒ SeleniumConfig

Returns a new instance of SeleniumConfig.



8
9
10
11
12
# File 'lib/saucelabs_adapter/selenium_config.rb', line 8

def initialize(configuration_name = nil, selenium_yml_path = nil)
  selenium_yml_path = selenium_yml_path || File.join(ENV['RAILS_ROOT'] || RAILS_ROOT, 'config', 'selenium.yml')
  SeleniumConfig.parse_yaml(selenium_yml_path)
  build_configuration(configuration_name)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



6
7
8
# File 'lib/saucelabs_adapter/selenium_config.rb', line 6

def configuration
  @configuration
end

Class Method Details

.parse_yaml(selenium_yml_path) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/saucelabs_adapter/selenium_config.rb', line 105

def self.parse_yaml(selenium_yml_path)
  raise "[saucelabs-adapter] could not open #{selenium_yml_path}" unless File.exist?(selenium_yml_path)
  file_contents = File.open(selenium_yml_path).read
  erb_parsed_file_contents = ERB.new(%{#{file_contents}}).result
  configs = YAML.load(erb_parsed_file_contents)
  @@selenium_configs ||= configs
end

Instance Method Details

#[]=(attribute, value) ⇒ Object



14
15
16
# File 'lib/saucelabs_adapter/selenium_config.rb', line 14

def []=(attribute, value)
  @configuration[attribute.to_s] = value
end

#application_addressObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/saucelabs_adapter/selenium_config.rb', line 48

def application_address
  if start_tunnel? && @configuration['tunnel_method'].to_sym == :saucetunnel
    # We are using Sauce Labs and Sauce Tunnel.
    # We need to use a masquerade hostname on the EC2 end of the tunnel that will be unique within the scope of
    # this account (e.g. pivotallabs).  Therefore we mint a fairly unique hostname here.
    hostname = Socket.gethostname.split(".").first
    "#{hostname}-#{Process.pid}.com"
  else
    @configuration['application_address']
  end

end

#configure_polonium(polonium_configuration_object) ⇒ Object

Takes a Polonium::Configuration object and configures it by calling methods on it



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/saucelabs_adapter/selenium_config.rb', line 75

def configure_polonium(polonium_configuration_object)
  {
    'selenium_server_host'      => :selenium_server_address,
    'selenium_server_port'      => :selenium_server_port,
    'browser'                   => :selenium_browser_key,
    'external_app_server_host'  => :application_address,
    'external_app_server_port'  => :application_port
  }.each do |polonium_configuration_method, our_accessor|
    polonium_configuration_object.send("#{polonium_configuration_method}=", self.send(our_accessor).to_s)
  end
end

#configure_webrat(webrat_configuration_object) ⇒ Object

Takes a Webrat::Configuration object and configures it by calling methods on it



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/saucelabs_adapter/selenium_config.rb', line 62

def configure_webrat(webrat_configuration_object)
  {
    'selenium_server_address' => :selenium_server_address,
    'selenium_server_port'    => :selenium_server_port,
    'selenium_browser_key'    => :selenium_browser_key,
    'application_address'     => :application_address,
    'application_port'        => :application_port
  }.each do |webrat_configuration_method, our_accessor|
    webrat_configuration_object.send("#{webrat_configuration_method}=", self.send(our_accessor).to_s)
  end
end

#create_driver(selenium_args = {}) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/saucelabs_adapter/selenium_config.rb', line 87

def create_driver(selenium_args = {})
  args = selenium_client_driver_args.merge(selenium_args)
  say "Connecting to Selenium RC server at #{args[:host]}:#{args[:port]} (testing app at #{args[:url]})"
  say "args = #{display_safely(args)}"
  driver = ::Selenium::Client::Driver.new(args)
  debug "done"
  driver
end

#kill_mongrel_after_suite?Boolean

Returns:

  • (Boolean)


100
101
102
103
# File 'lib/saucelabs_adapter/selenium_config.rb', line 100

def kill_mongrel_after_suite?
  return true if kill_mongrel_after_suite.nil?
  kill_mongrel_after_suite.to_s == 'true'
end

#selenium_browser_keyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/saucelabs_adapter/selenium_config.rb', line 32

def selenium_browser_key
  if selenium_server_address == 'saucelabs.com'
    # Create the JSON string that Saucelabs needs:
    { 'username' => saucelabs_username,
      'access-key' => saucelabs_access_key,
      'os' => saucelabs_browser_os,
      'browser' => saucelabs_browser,
      'browser-version' => saucelabs_browser_version,
      'max-duration' => saucelabs_max_duration_seconds.to_i,
      'job-name' => ENV['SAUCELABS_JOB_NAME'] || Socket.gethostname
    }.to_json
  else
    @configuration['selenium_browser_key']
  end
end

#start_tunnel?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/saucelabs_adapter/selenium_config.rb', line 96

def start_tunnel?
  !tunnel_method.nil? && tunnel_method.to_sym != :othertunnel
end