Class: SaucelabsAdapter::SeleniumConfig
- Inherits:
-
Object
- Object
- SaucelabsAdapter::SeleniumConfig
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, #kill_mongrel_if_needed, #raise_with_message, #say, #setup_tunnel, #start_mongrel, #teardown_tunnel
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
#configuration ⇒ Object
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
110
111
112
113
114
115
116
|
# File 'lib/saucelabs_adapter/selenium_config.rb', line 110
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_address ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/saucelabs_adapter/selenium_config.rb', line 48
def application_address
if start_tunnel? &&
[:sauceconnecttunnel, :saucetunnel].include?(@configuration['tunnel_method'].to_sym)
hostname = Socket.gethostname.split(".").first
"#{hostname}-#{Process.pid}.com"
else
@configuration['application_address']
end
end
|
Takes a Polonium::Configuration object and configures it by calling methods on it
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/saucelabs_adapter/selenium_config.rb', line 80
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
|
Takes a Webrat::Configuration object and configures it by calling methods on it
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/saucelabs_adapter/selenium_config.rb', line 63
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_for_selenium' => start_tunnel? ? :tunnel_to_localhost_port : :application_port,
'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
92
93
94
95
96
97
98
99
|
# File 'lib/saucelabs_adapter/selenium_config.rb', line 92
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]})" if ENV['SAUCELABS_ADAPTER_DEBUG']
say "args = #{display_safely(args)}" if ENV['SAUCELABS_ADAPTER_DEBUG']
driver = ::Selenium::Client::Driver.new(args)
debug "done"
driver
end
|
#kill_mongrel_after_suite? ⇒ Boolean
105
106
107
108
|
# File 'lib/saucelabs_adapter/selenium_config.rb', line 105
def kill_mongrel_after_suite?
return true if kill_mongrel_after_suite.nil?
kill_mongrel_after_suite.to_s == 'true'
end
|
#selenium_browser_key ⇒ Object
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'
{ '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
101
102
103
|
# File 'lib/saucelabs_adapter/selenium_config.rb', line 101
def start_tunnel?
!tunnel_method.nil? && tunnel_method.to_sym != :othertunnel
end
|