jasmine_selenium_runner 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f85e4cefa20dc2a1976e3a56c9ab6f69abaceaf8
4
- data.tar.gz: eba4354fd76bc9642d63bb5c33b0adc283dcd21d
3
+ metadata.gz: 94aa68074fa6bd922eae4c54c51337a27881b366
4
+ data.tar.gz: ffff97516d2a1241a7c2fa7f08fdc79d12683d3f
5
5
  SHA512:
6
- metadata.gz: b92bb57994b870683782005d394899af5bf11a896659d3c54578b849ea14f55047750e39b32d517988c9d0bf145359719c88ac0c7b27ae7805778fc88bf896e6
7
- data.tar.gz: 11a5f427662ff9c31063be536da4988a7b7ab271d8d67410c0e664edd97dfcf8b31211a0b1b9e251d413845e2fa526089486964490f7c2d687a1214451cf5057
6
+ metadata.gz: 57a3598792a25d6c482f9630804ef8884a36cac9c7f8a1e576bd75f17df9b216bfadb96756c7f8cbb725d6c120a27ef8623aa918bc99c1bf9e3746d003933ccf
7
+ data.tar.gz: 222a273ad1d72480624e3676af3b256c8586c2e20f7aef078be1f6fccb4a069adb9d4746eb49e637680ece9890bd0f10fd1dd68e58ac5488ae20b2774dd7fd66
data/README.md CHANGED
@@ -94,6 +94,28 @@ Create a jasmine_selenium_runner.yml in spec/javascripts/support/ with the follo
94
94
  selenium_server: <full url to selenium server>
95
95
  browser: <%= ENV['JASMINE_BROWSER'] %>
96
96
 
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
+
97
119
  ## Contributing
98
120
 
99
121
  1. Fork it
@@ -1,7 +1,7 @@
1
1
  module Jasmine
2
2
  module Runners
3
3
  class Selenium
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -3,59 +3,100 @@ require 'jasmine/runners/selenium'
3
3
  require 'selenium-webdriver'
4
4
 
5
5
  module JasmineSeleniumRunner
6
- module ConfigureJasmine
6
+ class ConfigureJasmine
7
7
  def self.install_selenium_runner
8
8
  Jasmine.configure do |config|
9
- filepath = File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_selenium_runner.yml')
10
- runner_config = YAML::load(ERB.new(File.read(filepath)).result(binding)) if File.exist?(filepath)
11
- runner_config ||= {}
12
- config.port = 5555 if runner_config['use_sauce'] #Sauce only proxies certain ports
9
+ runner_config = load_config
10
+ config.ci_port = 5555 if runner_config['use_sauce'] #Sauce only proxies certain ports
13
11
 
14
12
  config.runner = lambda { |formatter, jasmine_server_url|
15
- webdriver = nil
16
- browser = runner_config['browser'] || 'firefox'
17
-
18
- if runner_config['use_sauce']
19
- sauce_config = runner_config['sauce']
20
-
21
- unless sauce_config['tunnel_identifier']
22
- require 'sauce/connect'
23
- Sauce::Connect.connect!
24
- end
25
-
26
- username = sauce_config.fetch('username')
27
- key = sauce_config.fetch('access_key')
28
- driver_url = "http://#{username}:#{key}@localhost:4445/wd/hub"
29
-
30
- capabilities = {
31
- :name => sauce_config['name'],
32
- :platform => sauce_config['os'],
33
- :version => sauce_config['browser_version'],
34
- :build => sauce_config['build'],
35
- :tags => sauce_config['tags'],
36
- :browserName => browser,
37
- 'tunnel-identifier' => sauce_config['tunnel_identifier']
38
- }
39
-
40
- webdriver = Selenium::WebDriver.for :remote, :url => driver_url, :desired_capabilities => capabilities
41
- elsif runner_config['selenium_server']
42
- webdriver = Selenium::WebDriver.for :remote, :url => runner_config['selenium_server'], :desired_capabilities => browser.to_sym
43
- else
44
-
45
- selenium_options = {}
46
- if browser == 'firefox-firebug'
47
- require File.join(File.dirname(__FILE__), 'firebug/firebug')
48
- (profile = Selenium::WebDriver::Firefox::Profile.new)
49
- profile.enable_firebug
50
- selenium_options[:profile] = profile
51
- end
52
- webdriver = Selenium::WebDriver.for(browser.to_sym, selenium_options)
53
- end
54
-
55
- Jasmine::Runners::Selenium.new(formatter, jasmine_server_url, webdriver, runner_config['batch_config_size'] || 50)
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
56
19
  }
57
20
  end
58
21
  end
22
+
23
+ def self.load_config
24
+ filepath = File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_selenium_runner.yml')
25
+ if File.exist?(filepath)
26
+ YAML::load(ERB.new(File.read(filepath)).result(binding))
27
+ else
28
+ {}
29
+ end
30
+ end
31
+
32
+ def initialize(formatter, jasmine_server_url, runner_config)
33
+ @formatter = formatter
34
+ @jasmine_server_url = jasmine_server_url
35
+ @runner_config = runner_config
36
+ @browser = runner_config['browser'] || 'firefox'
37
+ end
38
+
39
+ def make_runner
40
+ webdriver = nil
41
+ if runner_config['use_sauce']
42
+ webdriver = sauce_webdriver(runner_config['sauce'])
43
+ elsif runner_config['selenium_server']
44
+ webdriver = remote_webdriver(runner_config['selenium_server'])
45
+ else
46
+ webdriver = local_webdriver
47
+ end
48
+
49
+ Jasmine::Runners::Selenium.new(formatter, jasmine_server_url, webdriver, batch_size)
50
+ end
51
+
52
+ def batch_size
53
+ runner_config['batch_config_size'] || 50
54
+ end
55
+
56
+ def sauce_webdriver(sauce_config)
57
+ unless sauce_config['tunnel_identifier']
58
+ require 'sauce/connect'
59
+ Sauce::Connect.connect!
60
+ end
61
+
62
+ username = sauce_config.fetch('username')
63
+ key = sauce_config.fetch('access_key')
64
+ driver_url = "http://#{username}:#{key}@localhost:4445/wd/hub"
65
+
66
+ capabilities = {
67
+ :name => sauce_config['name'],
68
+ :platform => sauce_config['os'],
69
+ :version => sauce_config['browser_version'],
70
+ :build => sauce_config['build'],
71
+ :tags => sauce_config['tags'],
72
+ :browserName => browser,
73
+ 'tunnel-identifier' => sauce_config['tunnel_identifier']
74
+ }
75
+
76
+ Selenium::WebDriver.for :remote, :url => driver_url, :desired_capabilities => capabilities
77
+ end
78
+
79
+ def remote_webdriver(server_url)
80
+ Selenium::WebDriver.for :remote, :url => server_url, :desired_capabilities => browser.to_sym
81
+ end
82
+
83
+ def local_webdriver
84
+ Selenium::WebDriver.for(browser.to_sym, selenium_options)
85
+ end
86
+
87
+ def selenium_options
88
+ if browser == 'firefox-firebug'
89
+ require File.join(File.dirname(__FILE__), 'firebug/firebug')
90
+ profile = Selenium::WebDriver::Firefox::Profile.new
91
+ profile.enable_firebug
92
+ { :profile => profile }
93
+ else
94
+ {}
95
+ end
96
+ end
97
+
98
+ protected
99
+ attr_reader :formatter, :jasmine_server_url, :runner_config, :browser
59
100
  end
60
101
  end
61
102
 
@@ -4,48 +4,68 @@ require 'selenium-webdriver'
4
4
  require 'jasmine_selenium_runner/configure_jasmine'
5
5
 
6
6
  describe "Configuring jasmine" do
7
+ let(:configurer) { JasmineSeleniumRunner::ConfigureJasmine.new(nil, nil, config) }
7
8
 
8
- class FakeConfig
9
- attr_accessor :port, :runner
10
- end
9
+ context "when a custom selenium server is specified" do
10
+ let(:config) { { 'selenium_server' => 'http://example.com/selenium/stuff' }}
11
11
 
12
- def configure
13
- Dir.stub(:pwd).and_return(working_dir)
14
- Jasmine.stub(:configure).and_yield(fake_config)
15
- JasmineSeleniumRunner::ConfigureJasmine.install_selenium_runner
12
+ it "make a webdriver pointing to the custom server" do
13
+ Selenium::WebDriver.should_receive(:for).with(:remote, hash_including(url: 'http://example.com/selenium/stuff'))
14
+ configurer.make_runner
15
+ end
16
16
  end
17
17
 
18
- def stub_config_file(config_obj)
19
- config_path = File.join(working_dir, 'spec', 'javascripts', 'support', 'jasmine_selenium_runner.yml')
20
- File.stub(:exist?).with(config_path).and_return(true)
21
- File.stub(:read).with(config_path).and_return(YAML.dump(config_obj))
18
+ context "when the user wants firebug installed" do
19
+ let(:config) { { 'browser' => 'firefox-firebug' } }
20
+
21
+ it "should create a firebug profile and pass that to WebDriver" do
22
+ profile = double(:profile, enable_firebug: nil)
23
+ Selenium::WebDriver::Firefox::Profile.stub(:new).and_return(profile)
24
+ Selenium::WebDriver.should_receive(:for).with('firefox-firebug'.to_sym, {profile: profile})
25
+ configurer.make_runner
26
+ end
22
27
  end
23
28
 
24
- let(:working_dir) { 'hi' }
25
- let(:fake_config) { FakeConfig.new }
29
+ context "specifying a custom configurer" do
30
+ class FakeConfig
31
+ attr_accessor :port, :runner
32
+ end
26
33
 
27
- context "when a custom selenium server is specified" do
28
- before do
29
- stub_config_file 'selenium_server' => 'http://example.com/selenium/stuff'
30
- configure
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
31
38
  end
32
39
 
33
- it "make a webdriver pointing to the custom server" do
34
- Selenium::WebDriver.should_receive(:for).with(:remote, hash_including(url: 'http://example.com/selenium/stuff'))
35
- fake_config.runner.call(nil, nil)
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
36
59
  end
37
- end
38
60
 
39
- context "when the user wants firebug installed" do
40
61
  before do
41
- stub_config_file 'browser' => 'firefox-firebug'
62
+ stub_config_file 'configuration_class' => 'Foo::Bar'
42
63
  configure
43
64
  end
44
65
 
45
- it "should create a firebug profile and pass that to WebDriver" do
46
- profile = double(:profile, enable_firebug: nil)
47
- Selenium::WebDriver::Firefox::Profile.stub(:new).and_return(profile)
48
- Selenium::WebDriver.should_receive(:for).with('firefox-firebug'.to_sym, {profile: profile})
66
+ it "should use the custom class" do
67
+ Selenium::WebDriver.should_not_receive(:for)
68
+ Foo::Bar.any_instance.should_receive(:make_runner)
49
69
  fake_config.runner.call(nil, nil)
50
70
  end
51
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine_selenium_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajan Agaskar
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-27 00:00:00.000000000 Z
12
+ date: 2013-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler