mediawiki_selenium 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67af225480dde4d5ac5bacbe01d631d2334859ec
4
- data.tar.gz: 28454c89b3d8f8550953e18fe9b7762a0333d669
3
+ metadata.gz: 7aa88726278140c10f75311afdd0a7539db96fda
4
+ data.tar.gz: 78c6c6c468dadd5a49ae3d6dff971b4ffa46dc1e
5
5
  SHA512:
6
- metadata.gz: bbcef005071dba80b554fc05c2a61a9fb20a1fb00cafd576fb9cacfb6debe2aae41caf3d571983a1b367c7f693d640998507d3d786051e34e0854f2e032498db
7
- data.tar.gz: a98d7297808c1d75ec7ee16c46d7763e14609e9ce6d43f1298ba641452dd536e5612322b925a2dc7fc6388313334a71302fc86a89da7197534175f957d8fb27d
6
+ metadata.gz: 2790c6bafb50c5924b545ee72d1149732a046d45a7833bcc38f6381721b1a683dd099ec95fd9dd9e4f47fabe1b29cd83fcd0560871e0b6387e333a1d0bc56e63
7
+ data.tar.gz: 62f2281382c96ddc1489bb31cc0d4977b06b3a3bcecde883847fccb90ec713a43394f355a30710376118c4bdd91f6cc78f460eecc1a935df6914ddd237dda4ef
data/.rubocop.yml CHANGED
@@ -19,5 +19,8 @@ Style/FileName:
19
19
  Style/SignalException:
20
20
  Enabled: false
21
21
 
22
+ Style/StringLiterals:
23
+ EnforcedStyle: single_quotes
24
+
22
25
  Style/TrivialAccessors:
23
26
  ExactNameMatch: true
data/README.md CHANGED
@@ -199,6 +199,10 @@ See https://www.mediawiki.org/wiki/Gerrit
199
199
 
200
200
  ## Release notes
201
201
 
202
+ ### 1.1.0 2015-04-06
203
+ * Support for `browser_http_proxy` in Firefox, Chrome, and Phantomjs
204
+ * Renamed browser factory `bind` method to `configure`
205
+
202
206
  ### 1.0.2 2015-03-26
203
207
  * Fixed double yield bug in `PageFactory#on`
204
208
  * Implemented loading of a `default` configuration from `environments.yml`
@@ -15,7 +15,7 @@ module MediawikiSelenium
15
15
  # @example Always configure Firefox's language according to `:browser_language`
16
16
  # module MediawikiSelenium::BrowserFactory
17
17
  # class Firefox < Base
18
- # bind(:browser_language) do |lang, options|
18
+ # configure(:browser_language) do |lang, options|
19
19
  # options[:desired_capabilities][:firefox_profile]["intl.accept_languages"] = lang
20
20
  # end
21
21
  # end
@@ -26,7 +26,7 @@ module MediawikiSelenium
26
26
  # @yield [values, browser_options] A block that binds the configuration to
27
27
  # the browser options.
28
28
  #
29
- def bind(*names, &blk)
29
+ def configure(*names, &blk)
30
30
  raise ArgumentError, 'no block given' unless block_given?
31
31
 
32
32
  key = names.length == 1 ? names.first : names
@@ -34,6 +34,9 @@ module MediawikiSelenium
34
34
  default_bindings[key] << blk
35
35
  end
36
36
 
37
+ # @deprecated Use {.configure} instead.
38
+ alias bind configure
39
+
37
40
  # All bindings for this factory class combined with those of super
38
41
  # classes.
39
42
  #
@@ -58,7 +61,7 @@ module MediawikiSelenium
58
61
 
59
62
  attr_reader :browser_name
60
63
 
61
- bind(:browser_timeout) { |value, options| options[:http_client].timeout = value.to_i }
64
+ configure(:browser_timeout) { |value, options| options[:http_client].timeout = value.to_i }
62
65
 
63
66
  # Initializes new factory instances.
64
67
  #
@@ -83,17 +86,17 @@ module MediawikiSelenium
83
86
  #
84
87
  # @example Override the user agent according :browser_user_agent
85
88
  # factory = BrowserFactory.new(:firefox)
86
- # factory.bind(:browser_user_agent) do |agent, options|
89
+ # factory.configure(:browser_user_agent) do |agent, options|
87
90
  # options[:desired_capabilities][:firefox_profile]["general.useragent.override"] = agent
88
91
  # end
89
92
  #
90
93
  # @example Annotate the session with our build information
91
- # factory.bind(:job_name, :build_number) do |job, build, options|
94
+ # factory.configure(:job_name, :build_number) do |job, build, options|
92
95
  # options[:desired_capabilities][:name] = "#{job} (#{build})"
93
96
  # end
94
97
  #
95
98
  # @example Bindings aren't invoked unless all given options are configured
96
- # factory.bind(:foo, :bar) do |foo, bar, options|
99
+ # factory.configure(:foo, :bar) do |foo, bar, options|
97
100
  # # this never happens!
98
101
  # options[:desired_capabilities][:name] = "#{foo} #{bar}"
99
102
  # end
@@ -104,12 +107,15 @@ module MediawikiSelenium
104
107
  # @yield [values, browser_options] A block that binds the configuration to
105
108
  # the browser options.
106
109
  #
107
- def bind(*names, &blk)
110
+ def configure(*names, &blk)
108
111
  key = names.length == 1 ? names.first : names
109
112
  @bindings[key] ||= []
110
113
  @bindings[key] << (blk || proc {})
111
114
  end
112
115
 
116
+ # @deprecated Use {#configure} instead.
117
+ alias bind configure
118
+
113
119
  # Effective bindings for this factory, those defined at the class level
114
120
  # and those defined for this instance.
115
121
  #
@@ -3,17 +3,22 @@ module MediawikiSelenium
3
3
  # Constructs new Chrome browser instances. The following configuration is
4
4
  # supported.
5
5
  #
6
+ # - browser_http_proxy
6
7
  # - browser_language
7
8
  # - browser_user_agent
8
9
  #
9
10
  # @see Base
10
11
  #
11
12
  class Chrome < Base
12
- bind(:browser_language) do |language, options|
13
+ configure(:browser_http_proxy) do |http_proxy, options|
14
+ options[:args] << "--proxy-server=#{http_proxy}"
15
+ end
16
+
17
+ configure(:browser_language) do |language, options|
13
18
  options[:prefs]['intl.accept_languages'] = language
14
19
  end
15
20
 
16
- bind(:browser_user_agent) do |user_agent, options|
21
+ configure(:browser_user_agent) do |user_agent, options|
17
22
  options[:args] << "--user-agent=#{user_agent}"
18
23
  end
19
24
 
@@ -3,6 +3,7 @@ module MediawikiSelenium
3
3
  # Constructs new Firefox browser instances. The following configuration is
4
4
  # supported.
5
5
  #
6
+ # - browser_http_proxy
6
7
  # - browser_language
7
8
  # - browser_timeout
8
9
  # - browser_user_agent
@@ -10,17 +11,21 @@ module MediawikiSelenium
10
11
  # @see Base
11
12
  #
12
13
  class Firefox < Base
13
- bind(:browser_timeout) do |timeout, options|
14
+ configure(:browser_http_proxy) do |http_proxy, options|
15
+ options[:profile].proxy = Selenium::WebDriver::Proxy.new(http: http_proxy, ssl: http_proxy)
16
+ end
17
+
18
+ configure(:browser_timeout) do |timeout, options|
14
19
  timeout = timeout.to_i
15
20
  options[:profile]['dom.max_script_run_time'] = timeout
16
21
  options[:profile]['dom.max_chrome_script_run_time'] = timeout
17
22
  end
18
23
 
19
- bind(:browser_language) do |language, options|
24
+ configure(:browser_language) do |language, options|
20
25
  options[:profile]['intl.accept_languages'] = language
21
26
  end
22
27
 
23
- bind(:browser_user_agent) do |user_agent, options|
28
+ configure(:browser_user_agent) do |user_agent, options|
24
29
  options[:profile]['general.useragent.override'] = user_agent
25
30
  end
26
31
 
@@ -3,19 +3,32 @@ module MediawikiSelenium
3
3
  # Constructs new Phantomjs browser instances. The following configuration is
4
4
  # supported.
5
5
  #
6
+ # - browser_http_proxy
6
7
  # - browser_language
7
8
  # - browser_user_agent
8
9
  #
9
10
  # @see Base
10
11
  #
11
12
  class Phantomjs < Base
12
- bind(:browser_language) do |language, options|
13
+ configure(:browser_http_proxy) do |http_proxy, options|
14
+ options[:desired_capabilities]['phantomjs.cli.args'] << "--proxy=#{http_proxy}"
15
+ end
16
+
17
+ configure(:browser_language) do |language, options|
13
18
  options[:desired_capabilities]['phantomjs.page.customHeaders.Accept-Language'] = language
14
19
  end
15
20
 
16
- bind(:browser_user_agent) do |user_agent, options|
21
+ configure(:browser_user_agent) do |user_agent, options|
17
22
  options[:desired_capabilities]['phantomjs.page.settings.userAgent'] = user_agent
18
23
  end
24
+
25
+ protected
26
+
27
+ def default_browser_options
28
+ super.tap do |options|
29
+ options[:desired_capabilities]['phantomjs.cli.args'] = []
30
+ end
31
+ end
19
32
  end
20
33
  end
21
34
  end
@@ -167,7 +167,7 @@ module MediawikiSelenium
167
167
  browser = browser.to_s.downcase.to_sym
168
168
 
169
169
  @_factory_cache[[remote?, browser]] ||= BrowserFactory.new(browser).tap do |factory|
170
- factory.bind(:_browser_session)
170
+ factory.configure(:_browser_session)
171
171
  factory.extend(RemoteBrowserFactory) if remote?
172
172
  end
173
173
  end
@@ -17,23 +17,23 @@ module MediawikiSelenium
17
17
  URL = 'http://ondemand.saucelabs.com/wd/hub'
18
18
 
19
19
  class << self
20
- def extend_object(factory)
21
- return if factory.is_a?(self)
20
+ def extend_object(base)
21
+ return if base.is_a?(self)
22
22
 
23
23
  super
24
24
 
25
- factory.bind(:sauce_ondemand_username, :sauce_ondemand_access_key) do |user, key, options|
25
+ base.configure(:sauce_ondemand_username, :sauce_ondemand_access_key) do |user, key, options|
26
26
  options[:url] = URI.parse(URL)
27
27
 
28
28
  options[:url].user = user
29
29
  options[:url].password = key
30
30
  end
31
31
 
32
- factory.bind(:platform) do |platform, options|
32
+ base.configure(:platform) do |platform, options|
33
33
  options[:desired_capabilities].platform = platform
34
34
  end
35
35
 
36
- factory.bind(:version) do |version, options|
36
+ base.configure(:version) do |version, options|
37
37
  options[:desired_capabilities].version = version
38
38
  end
39
39
  end
@@ -55,15 +55,15 @@ Before do |scenario|
55
55
  @random_string = Random.new.rand.to_s
56
56
 
57
57
  # Annotate sessions with the scenario name and Jenkins build info
58
- browser_factory.bind do |options|
58
+ browser_factory.configure do |options|
59
59
  options[:desired_capabilities][:name] = test_name(scenario)
60
60
  end
61
61
 
62
- browser_factory.bind(:job_name) do |job, options|
62
+ browser_factory.configure(:job_name) do |job, options|
63
63
  options[:desired_capabilities][:name] += " #{job}"
64
64
  end
65
65
 
66
- browser_factory.bind(:build_number) do |build, options|
66
+ browser_factory.configure(:build_number) do |build, options|
67
67
  options[:desired_capabilities][:name] += "##{build}"
68
68
  end
69
69
  end
@@ -1,3 +1,3 @@
1
1
  module MediawikiSelenium
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'bundler', '~> 1.6', '>= 1.6.3'
41
41
  spec.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7.4'
42
42
  spec.add_development_dependency 'redcarpet', '~> 3.2', '>= 3.2.0'
43
- spec.add_development_dependency 'rubocop', '~> 0.26', '>= 0.26.1'
43
+ spec.add_development_dependency 'rubocop', '~> 0.29.1'
44
44
  spec.add_development_dependency 'rspec-core', '~> 2.14', '>= 2.14.4'
45
45
  spec.add_development_dependency 'rspec-mocks', '~> 2.14', '>= 2.14.4'
46
46
  end
@@ -6,8 +6,24 @@ module MediawikiSelenium::BrowserFactory
6
6
  let(:factory) { factory_class.new(browser_name) }
7
7
  let(:browser_name) { :lynx }
8
8
 
9
- describe '.bind' do
10
- subject { factory_class.bind(option_name, &block) }
9
+ describe '.bindings' do
10
+ subject { factory_class.bindings }
11
+
12
+ before do
13
+ factory_class.configure(:foo) {}
14
+ end
15
+
16
+ it "includes the base class's default bindings" do
17
+ expect(subject).to include(Base.default_bindings)
18
+ end
19
+
20
+ it 'includes its own bindings' do
21
+ expect(subject).to include(factory_class.default_bindings)
22
+ end
23
+ end
24
+
25
+ describe '.configure' do
26
+ subject { factory_class.configure(option_name, &block) }
11
27
 
12
28
  let(:option_name) { :foo }
13
29
  let(:block) { proc { } }
@@ -19,7 +35,7 @@ module MediawikiSelenium::BrowserFactory
19
35
  end
20
36
 
21
37
  context 'given no block' do
22
- subject { factory_class.bind(option_name) }
38
+ subject { factory_class.configure(option_name) }
23
39
 
24
40
  it 'raises an ArgumentError' do
25
41
  expect { subject }.to raise_error(ArgumentError)
@@ -27,22 +43,6 @@ module MediawikiSelenium::BrowserFactory
27
43
  end
28
44
  end
29
45
 
30
- describe '.bindings' do
31
- subject { factory_class.bindings }
32
-
33
- before do
34
- factory_class.bind(:foo) {}
35
- end
36
-
37
- it "includes the base class's default bindings" do
38
- expect(subject).to include(Base.default_bindings)
39
- end
40
-
41
- it 'includes its own bindings' do
42
- expect(subject).to include(factory_class.default_bindings)
43
- end
44
- end
45
-
46
46
  describe '.default_bindings' do
47
47
  subject { factory_class.default_bindings }
48
48
 
@@ -54,9 +54,9 @@ module MediawikiSelenium::BrowserFactory
54
54
 
55
55
  context 'when bindings are defined' do
56
56
  before do
57
- factory_class.bind(:foo) {}
58
- factory_class.bind(:bar) {}
59
- factory_class.bind(:bar) {}
57
+ factory_class.configure(:foo) {}
58
+ factory_class.configure(:bar) {}
59
+ factory_class.configure(:bar) {}
60
60
  end
61
61
 
62
62
  it 'includes all defined bindings' do
@@ -69,33 +69,12 @@ module MediawikiSelenium::BrowserFactory
69
69
  end
70
70
  end
71
71
 
72
- describe '#bind' do
73
- subject { factory.bind(option_name, &block) }
74
- before { subject }
75
-
76
- let(:option_name) { :foo }
77
- let(:block) { proc { } }
78
-
79
- it 'adds a new binding for the given option' do
80
- expect(factory.bindings).to include(option_name)
81
- expect(factory.bindings[option_name]).to include(block)
82
- end
83
-
84
- context 'given no block' do
85
- subject { factory.bind(option_name) }
86
-
87
- it 'will default to an empty block' do
88
- expect(factory.bindings[option_name]).not_to include(nil)
89
- end
90
- end
91
- end
92
-
93
72
  describe '#bindings' do
94
73
  subject { factory.bindings }
95
74
 
96
75
  before do
97
- factory_class.bind(:foo) {}
98
- factory.bind(:bar)
76
+ factory_class.configure(:foo) {}
77
+ factory.configure(:bar)
99
78
  end
100
79
 
101
80
  it 'includes the class-level bindings' do
@@ -176,7 +155,7 @@ module MediawikiSelenium::BrowserFactory
176
155
  let(:config) { { foo: 'x' } }
177
156
 
178
157
  it 'invokes the binding with the configured value' do
179
- expect { |block| factory.bind(:foo, &block) && subject }.
158
+ expect { |block| factory.configure(:foo, &block) && subject }.
180
159
  to yield_with_args('x', options)
181
160
  end
182
161
  end
@@ -185,7 +164,7 @@ module MediawikiSelenium::BrowserFactory
185
164
  let(:config) { {} }
186
165
 
187
166
  it 'never invokes the binding' do
188
- expect { |block| factory.bind(:foo, &block) && subject }.
167
+ expect { |block| factory.configure(:foo, &block) && subject }.
189
168
  to_not yield_control
190
169
  end
191
170
  end
@@ -196,7 +175,7 @@ module MediawikiSelenium::BrowserFactory
196
175
  let(:config) { { foo: 'x', bar: 'y' } }
197
176
 
198
177
  it 'invokes the binding with the configured values' do
199
- expect { |block| factory.bind(:foo, :bar, &block) && subject }.
178
+ expect { |block| factory.configure(:foo, :bar, &block) && subject }.
200
179
  to yield_with_args('x', 'y', options)
201
180
  end
202
181
  end
@@ -205,11 +184,32 @@ module MediawikiSelenium::BrowserFactory
205
184
  let(:config) { { foo: 'x' } }
206
185
 
207
186
  it 'never invokes the binding' do
208
- expect { |block| factory.bind(:foo, :bar, &block) && subject }.
187
+ expect { |block| factory.configure(:foo, :bar, &block) && subject }.
209
188
  to_not yield_control
210
189
  end
211
190
  end
212
191
  end
213
192
  end
193
+
194
+ describe '#configure' do
195
+ subject { factory.configure(option_name, &block) }
196
+ before { subject }
197
+
198
+ let(:option_name) { :foo }
199
+ let(:block) { proc { } }
200
+
201
+ it 'adds a new binding for the given option' do
202
+ expect(factory.bindings).to include(option_name)
203
+ expect(factory.bindings[option_name]).to include(block)
204
+ end
205
+
206
+ context 'given no block' do
207
+ subject { factory.configure(option_name) }
208
+
209
+ it 'will default to an empty block' do
210
+ expect(factory.bindings[option_name]).not_to include(nil)
211
+ end
212
+ end
213
+ end
214
214
  end
215
215
  end
@@ -16,6 +16,14 @@ module MediawikiSelenium::BrowserFactory
16
16
  describe '#browser_options' do
17
17
  subject { factory.browser_options(config) }
18
18
 
19
+ context 'given a browser proxy' do
20
+ let(:config) { { browser_http_proxy: 'proxy.example:8080' } }
21
+
22
+ it 'includes it as --proxy-server in the chrome arguments' do
23
+ expect(subject[:args]).to include('--proxy-server=proxy.example:8080')
24
+ end
25
+ end
26
+
19
27
  context 'given a custom browser_language' do
20
28
  let(:config) { { browser_language: 'eo' } }
21
29
 
@@ -22,6 +22,21 @@ module MediawikiSelenium::BrowserFactory
22
22
  expect(Selenium::WebDriver::Firefox::Profile).to receive(:new).and_return(profile)
23
23
  end
24
24
 
25
+ context 'given a browser proxy' do
26
+ let(:config) { { browser_http_proxy: 'proxy.example:8080' } }
27
+
28
+ it 'sets up the profile to use a proxy for both http and https' do
29
+ selenium_proxy = double('Selenium::WebDriver::Proxy')
30
+
31
+ expect(Selenium::WebDriver::Proxy).to receive(:new).
32
+ with(http: 'proxy.example:8080', ssl: 'proxy.example:8080').
33
+ and_return(selenium_proxy)
34
+ expect(profile).to receive(:proxy=).with(selenium_proxy)
35
+
36
+ subject
37
+ end
38
+ end
39
+
25
40
  context 'given a custom browser_timeout' do
26
41
  let(:config) { { browser_timeout: '30' } }
27
42
 
@@ -16,6 +16,15 @@ module MediawikiSelenium::BrowserFactory
16
16
  describe '#browser_options' do
17
17
  subject { factory.browser_options(config) }
18
18
 
19
+ context 'given a browser proxy' do
20
+ let(:config) { { browser_http_proxy: 'proxy.example:8080' } }
21
+
22
+ it 'includes it as --proxy in the cli arguments' do
23
+ capabilities = subject[:desired_capabilities]
24
+ expect(capabilities['phantomjs.cli.args']).to include('--proxy=proxy.example:8080')
25
+ end
26
+ end
27
+
19
28
  context 'given a custom browser_language' do
20
29
  let(:config) { { browser_language: 'eo' } }
21
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki_selenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris McMahon
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2015-03-26 00:00:00.000000000 Z
16
+ date: 2015-04-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: cucumber
@@ -255,20 +255,14 @@ dependencies:
255
255
  requirements:
256
256
  - - "~>"
257
257
  - !ruby/object:Gem::Version
258
- version: '0.26'
259
- - - ">="
260
- - !ruby/object:Gem::Version
261
- version: 0.26.1
258
+ version: 0.29.1
262
259
  type: :development
263
260
  prerelease: false
264
261
  version_requirements: !ruby/object:Gem::Requirement
265
262
  requirements:
266
263
  - - "~>"
267
264
  - !ruby/object:Gem::Version
268
- version: '0.26'
269
- - - ">="
270
- - !ruby/object:Gem::Version
271
- version: 0.26.1
265
+ version: 0.29.1
272
266
  - !ruby/object:Gem::Dependency
273
267
  name: rspec-core
274
268
  requirement: !ruby/object:Gem::Requirement