Skip to content

Commit 381c9eb

Browse files
author
Gregg Van Hove
committed
Allow users to customize how the WebDriver is built
- Allows the user to customize the profile to do things like modify script timeouts [finish #37287185]
1 parent 926c300 commit 381c9eb

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ Create a jasmine_selenium_runner.yml in spec/javascripts/support/ with the follo
9494
selenium_server: <full url to selenium server>
9595
browser: <%= ENV['JASMINE_BROWSER'] %>
9696

97+
### Customizing the browser profile
98+
99+
Make a class that extends `JasmineSeleniumRunner::ConfigureJasmine` and override the `selenium_options` method
100+
101+
class MyConfigurer < JasmineSeleniumRunner::ConfigureJasmine
102+
def selenium_options
103+
options = super
104+
if browser =~ /^firefox/
105+
options = super
106+
options[:profile] ||= Selenium::WebDriver::Firefox::Profile.new
107+
options[:profile]['dom.max_chrome_script_run_time'] = 20
108+
options[:profile]['dom.max_script_run_time'] = 20
109+
end
110+
options
111+
end
112+
end
113+
114+
Create a jasmine_selenium_runner.yml in spec/javascripts/support/ with the following content:
115+
116+
---
117+
configuration_class: MyConfigurer
118+
97119
## Contributing
98120

99121
1. Fork it

lib/jasmine_selenium_runner/configure_jasmine.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ def self.install_selenium_runner
1010
config.port = 5555 if runner_config['use_sauce'] #Sauce only proxies certain ports
1111

1212
config.runner = lambda { |formatter, jasmine_server_url|
13-
new(formatter, jasmine_server_url, runner_config).make_runner
13+
configuration_class = if runner_config['configuration_class']
14+
const_get(runner_config['configuration_class'])
15+
else
16+
self
17+
end
18+
configuration_class.new(formatter, jasmine_server_url, runner_config).make_runner
1419
}
1520
end
1621
end
@@ -76,14 +81,18 @@ def remote_webdriver(server_url)
7681
end
7782

7883
def local_webdriver
79-
selenium_options = {}
84+
Selenium::WebDriver.for(browser.to_sym, selenium_options)
85+
end
86+
87+
def selenium_options
8088
if browser == 'firefox-firebug'
8189
require File.join(File.dirname(__FILE__), 'firebug/firebug')
82-
(profile = Selenium::WebDriver::Firefox::Profile.new)
90+
profile = Selenium::WebDriver::Firefox::Profile.new
8391
profile.enable_firebug
84-
selenium_options[:profile] = profile
92+
{ :profile => profile }
93+
else
94+
{}
8595
end
86-
Selenium::WebDriver.for(browser.to_sym, selenium_options)
8796
end
8897

8998
protected

spec/jasmine_selenium_runner/configure_jasmine_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,48 @@
2525
configurer.make_runner
2626
end
2727
end
28+
29+
context "specifying a custom configurer" do
30+
class FakeConfig
31+
attr_accessor :port, :runner
32+
end
33+
34+
def configure
35+
Dir.stub(:pwd).and_return(working_dir)
36+
Jasmine.stub(:configure).and_yield(fake_config)
37+
JasmineSeleniumRunner::ConfigureJasmine.install_selenium_runner
38+
end
39+
40+
def stub_config_file(config_obj)
41+
config_path = File.join(working_dir, 'spec', 'javascripts', 'support', 'jasmine_selenium_runner.yml')
42+
File.stub(:exist?).and_call_original
43+
File.stub(:exist?).with(config_path).and_return(true)
44+
File.stub(:read).and_call_original
45+
File.stub(:read).with(config_path).and_return(YAML.dump(config_obj))
46+
end
47+
48+
let(:working_dir) { 'hi' }
49+
let(:fake_config) { FakeConfig.new }
50+
51+
module Foo
52+
class Bar
53+
def initialize(formatter, jasmine_server_url, config)
54+
end
55+
56+
def make_runner
57+
end
58+
end
59+
end
60+
61+
before do
62+
stub_config_file 'configuration_class' => 'Foo::Bar'
63+
configure
64+
end
65+
66+
it "should use the custom class" do
67+
Selenium::WebDriver.should_not_receive(:for)
68+
Foo::Bar.any_instance.should_receive(:make_runner)
69+
fake_config.runner.call(nil, nil)
70+
end
71+
end
2872
end

0 commit comments

Comments
 (0)