mediawiki_selenium 1.6.5 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CREDITS +1 -0
- data/README.md +34 -0
- data/RELEASES.md +4 -0
- data/lib/mediawiki_selenium.rb +1 -0
- data/lib/mediawiki_selenium/cucumber/hooks.rb +2 -0
- data/lib/mediawiki_selenium/environment.rb +70 -9
- data/lib/mediawiki_selenium/rake_task.rb +31 -0
- data/lib/mediawiki_selenium/version.rb +1 -1
- data/spec/environment_spec.rb +83 -9
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3406e3a83ca87d98254baab7ad0e8aaba8a63804
|
4
|
+
data.tar.gz: 3cfa9c9d4be2e9646457f481a3b78948eb6fb4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f0ac98aeab7706c6a24f04ebc28a7253bc1fb068481106660826bf34016509765ef2337ada75b227cc666c3f5f69d88d994e4a381fb49565fd9827df8a80c3d
|
7
|
+
data.tar.gz: f4631f18d8ea831cac316304f9840fc7ac560c2fac92d0b1ea357deac026b9e263a1d2c26dccf82abee8c3af6df37c188cd0be867f3fe08603b154d93c8537e6
|
data/CREDITS
CHANGED
data/README.md
CHANGED
@@ -204,6 +204,40 @@ the destination path for screenshots. Example:
|
|
204
204
|
|
205
205
|
SCREENSHOT_FAILURES=true SCREENSHOT_FAILURES_PATH="/tmp/screenshots" bundle exec cucumber
|
206
206
|
|
207
|
+
### CI Rake task
|
208
|
+
|
209
|
+
To utilize the CI rake task, add the following to your `Rakefile`:
|
210
|
+
|
211
|
+
require 'mediawiki_selenium/rake_task'
|
212
|
+
MediawikiSelenium::RakeTask.new
|
213
|
+
|
214
|
+
It defaults to look for `environments.yml` and `features` under `tests/browser`.
|
215
|
+
You can specify the directory:
|
216
|
+
|
217
|
+
require 'mediawiki_selenium/rake_task'
|
218
|
+
MediawikiSelenium::RakeTask.new(test_dir: modules/ve-mw/tests/browser)
|
219
|
+
|
220
|
+
By default, it will run something like this:
|
221
|
+
|
222
|
+
bundle exec cucumber (...) --tags ~@skip --tags @en.wikipedia.beta.wmflabs.org --tags @firefox
|
223
|
+
|
224
|
+
To exclude Cucumber site tag (example: `--tags @en.wikipedia.beta.wmflabs.org`):
|
225
|
+
|
226
|
+
require 'mediawiki_selenium/rake_task'
|
227
|
+
MediawikiSelenium::RakeTask.new(site_tag: false)
|
228
|
+
|
229
|
+
The above will run:
|
230
|
+
|
231
|
+
bundle exec cucumber (...) --tags ~@skip -tags @firefox
|
232
|
+
|
233
|
+
CI specific options are passed to cucumber when the rake task detects the
|
234
|
+
environment variable WORKSPACE is set. It will emit JUnit results under
|
235
|
+
`$WORKSPACE/log/junit`. To reproduce that behavior one can:
|
236
|
+
|
237
|
+
export WORKSPACE=/tmp/myplace
|
238
|
+
mkdir -p $WORKSPACE/log/junit
|
239
|
+
bundle exec rake spec
|
240
|
+
|
207
241
|
## Updating Your Gemfile
|
208
242
|
|
209
243
|
In your repository, the `Gemfile` specifies dependencies and `Gemfile.lock` defines
|
data/RELEASES.md
CHANGED
data/lib/mediawiki_selenium.rb
CHANGED
@@ -10,6 +10,7 @@ module MediawikiSelenium
|
|
10
10
|
autoload :LoginHelper, 'mediawiki_selenium/helpers/login_helper'
|
11
11
|
autoload :PageFactory, 'mediawiki_selenium/page_factory'
|
12
12
|
autoload :Raita, 'mediawiki_selenium/raita'
|
13
|
+
autoload :RakeTask, 'mediawiki_selenium/rake_task'
|
13
14
|
autoload :RemoteBrowserFactory, 'mediawiki_selenium/remote_browser_factory'
|
14
15
|
autoload :ScreenshotHelper, 'mediawiki_selenium/helpers/screenshot_helper'
|
15
16
|
autoload :StrictPending, 'mediawiki_selenium/cucumber/strict_pending'
|
@@ -3,6 +3,8 @@ Before('@custom-browser') do |scenario|
|
|
3
3
|
end
|
4
4
|
|
5
5
|
AfterConfiguration do |config|
|
6
|
+
MediawikiSelenium::Environment.default_test_directory = config.paths.first || '.'
|
7
|
+
|
6
8
|
# Install a formatter that can be used to show feature-related warnings
|
7
9
|
pretty_format, io = config.formats.find { |(format, _io)| format == 'pretty' }
|
8
10
|
config.formats << ['MediawikiSelenium::WarningsFormatter', io] if pretty_format
|
@@ -63,7 +63,7 @@ module MediawikiSelenium
|
|
63
63
|
include Comparable
|
64
64
|
|
65
65
|
class << self
|
66
|
-
attr_accessor :default_configuration
|
66
|
+
attr_accessor :default_configuration, :default_test_directory
|
67
67
|
|
68
68
|
# Instantiates a new environment using the given set of default
|
69
69
|
# configuration from `environments.yml` in the current working
|
@@ -71,20 +71,23 @@ module MediawikiSelenium
|
|
71
71
|
#
|
72
72
|
# @param name [String] Name of the environment.
|
73
73
|
# @param extra [Hash] Additional configuration to use.
|
74
|
+
# @param test_dir [String] Path from which to search upward for
|
75
|
+
# `environments.yml`
|
74
76
|
#
|
75
|
-
def load(name, extra = {})
|
77
|
+
def load(name, extra = {}, test_dir = nil)
|
76
78
|
name = name.to_s
|
77
79
|
configs = []
|
78
80
|
|
79
81
|
unless name.empty?
|
80
|
-
envs = YAML.load_file(
|
82
|
+
envs = YAML.load_file(search_for_configuration(test_dir || default_test_directory))
|
81
83
|
raise ConfigurationError, "unknown environment `#{name}`" unless envs.include?(name)
|
82
84
|
configs << envs[name]
|
83
85
|
end
|
84
86
|
|
85
87
|
configs << extra
|
86
88
|
|
87
|
-
new(*configs)
|
89
|
+
env = new(*configs)
|
90
|
+
env
|
88
91
|
end
|
89
92
|
|
90
93
|
# Instantiates a new environment from the values of `ENV` and the
|
@@ -93,12 +96,29 @@ module MediawikiSelenium
|
|
93
96
|
#
|
94
97
|
# @see load
|
95
98
|
#
|
96
|
-
def load_default
|
97
|
-
load(ENV['MEDIAWIKI_ENVIRONMENT'] || 'default', ENV)
|
99
|
+
def load_default(test_dir = nil)
|
100
|
+
load(ENV['MEDIAWIKI_ENVIRONMENT'] || 'default', ENV, test_dir)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Searches for `environments.yml` in the given path. If it isn't found,
|
104
|
+
# the search continues upward in the directory hierarchy.
|
105
|
+
#
|
106
|
+
# @param path [String] Path to search for configuration
|
107
|
+
#
|
108
|
+
# @return [String] Qualified path to the configuration file
|
109
|
+
#
|
110
|
+
def search_for_configuration(path)
|
111
|
+
return default_configuration if path.nil? || path.empty?
|
112
|
+
|
113
|
+
file_path = File.join(path, default_configuration)
|
114
|
+
return file_path if File.exist?(file_path)
|
115
|
+
|
116
|
+
search_for_configuration(File.dirname(path))
|
98
117
|
end
|
99
118
|
end
|
100
119
|
|
101
120
|
self.default_configuration = 'environments.yml'
|
121
|
+
self.default_test_directory = 'tests/browser'
|
102
122
|
|
103
123
|
def initialize(*configs)
|
104
124
|
@_config = configs.map { |config| normalize_config(config) }.reduce(:merge)
|
@@ -174,12 +194,41 @@ module MediawikiSelenium
|
|
174
194
|
end
|
175
195
|
end
|
176
196
|
|
177
|
-
# Name of the browser we're using.
|
197
|
+
# Name of the browser we're using. If the `:browser` configuration
|
198
|
+
# contains a version at the end, only the name is returned.
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# env = Environment.new(browser: 'internet_explorer 8.0')
|
202
|
+
# env.browser_name # => :internet_explorer
|
178
203
|
#
|
179
204
|
# @return [Symbol]
|
180
205
|
#
|
181
206
|
def browser_name
|
182
|
-
|
207
|
+
browser_spec[0].to_sym
|
208
|
+
end
|
209
|
+
|
210
|
+
# Tag names that can be used to filter test scenarios for a specific
|
211
|
+
# browser and/or version.
|
212
|
+
#
|
213
|
+
# @return [Array<String>]
|
214
|
+
#
|
215
|
+
def browser_tags
|
216
|
+
tags = [browser_name.to_s]
|
217
|
+
|
218
|
+
version = browser_version
|
219
|
+
tags << "#{browser_name}_#{version}" if version
|
220
|
+
|
221
|
+
tags
|
222
|
+
end
|
223
|
+
|
224
|
+
# Version of the browser we're using. If a `:version` configuration
|
225
|
+
# is provided, that value is returned. Otherwise a version is searched for
|
226
|
+
# in the `:browser` configuration.
|
227
|
+
#
|
228
|
+
# @return [String]
|
229
|
+
#
|
230
|
+
def browser_version
|
231
|
+
lookup(:version, default: browser_spec[1])
|
183
232
|
end
|
184
233
|
|
185
234
|
# Returns the current alternate ID for the given configuration key.
|
@@ -514,7 +563,19 @@ module MediawikiSelenium
|
|
514
563
|
private
|
515
564
|
|
516
565
|
def browser_config
|
517
|
-
lookup_all(browser_factory.all_binding_keys, default: nil).reject { |_k, v| v.nil? }
|
566
|
+
config = lookup_all(browser_factory.all_binding_keys, default: nil).reject { |_k, v| v.nil? }
|
567
|
+
|
568
|
+
# The browser version may be provided as part of the `:browser`
|
569
|
+
# configuration or separately as `:version`. In either case,
|
570
|
+
# `browser_version` will return the right value.
|
571
|
+
version = browser_version
|
572
|
+
config[:version] = version unless version.nil?
|
573
|
+
|
574
|
+
config
|
575
|
+
end
|
576
|
+
|
577
|
+
def browser_spec
|
578
|
+
lookup(:browser, default: 'firefox').to_s.downcase.split(' ')
|
518
579
|
end
|
519
580
|
|
520
581
|
def normalize_config(hash)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'cucumber/rake/task'
|
2
|
+
require 'mediawiki_selenium'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module MediawikiSelenium
|
6
|
+
class RakeTask < Cucumber::Rake::Task
|
7
|
+
def initialize(name: :selenium, test_dir: Environment.default_test_directory, site_tag: true)
|
8
|
+
target = File.expand_path(test_dir, Rake.original_dir)
|
9
|
+
env = Environment.load_default(target)
|
10
|
+
|
11
|
+
workspace = env.lookup(:workspace, default: nil)
|
12
|
+
site = URI.parse(env.lookup(:mediawiki_url)).host
|
13
|
+
browser_tags = env.browser_tags.map { |tag| "@#{tag}" }.join(',')
|
14
|
+
|
15
|
+
options = Shellwords.escape(test_dir)
|
16
|
+
|
17
|
+
if workspace
|
18
|
+
options +=
|
19
|
+
' --backtrace --verbose --color --format pretty'\
|
20
|
+
" --format Cucumber::Formatter::Sauce --out '#{workspace}/log/junit'"\
|
21
|
+
' --tags ~@skip'
|
22
|
+
options +=
|
23
|
+
" --tags @#{site}" if site_tag
|
24
|
+
end
|
25
|
+
|
26
|
+
super(name) do |t|
|
27
|
+
t.cucumber_opts = "#{options} --tags #{browser_tags}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/environment_spec.rb
CHANGED
@@ -23,18 +23,16 @@ module MediawikiSelenium
|
|
23
23
|
let(:mediawiki_user) { 'mw user' }
|
24
24
|
let(:mediawiki_password) { 'mw password' }
|
25
25
|
|
26
|
-
def mock_environment_name(name)
|
27
|
-
expect(ENV).to receive(:[]).with('MEDIAWIKI_ENVIRONMENT').and_return(name)
|
28
|
-
end
|
29
|
-
|
30
26
|
describe '.load' do
|
31
27
|
subject { Environment.load(name, extra) }
|
32
28
|
|
33
29
|
let(:name) { 'foo' }
|
34
30
|
let(:extra) { {} }
|
31
|
+
let(:env_file) { 'environments.yml' }
|
35
32
|
|
36
33
|
before do
|
37
|
-
|
34
|
+
allow(Environment).to receive(:search_for_configuration).and_return(env_file)
|
35
|
+
allow(YAML).to receive(:load_file).with(env_file).
|
38
36
|
and_return('foo' => { 'x' => 'a', 'y' => 'b' })
|
39
37
|
end
|
40
38
|
|
@@ -63,21 +61,43 @@ module MediawikiSelenium
|
|
63
61
|
expect(subject[:y]).to eq('b')
|
64
62
|
end
|
65
63
|
end
|
64
|
+
|
65
|
+
context 'when a test_dir is given' do
|
66
|
+
subject { Environment.load('foo', {}, test_dir) }
|
67
|
+
|
68
|
+
let(:test_dir) { '/srv/workspace/job' }
|
69
|
+
let(:env_file) { File.join(test_dir, 'environments.yml') }
|
70
|
+
|
71
|
+
it 'loads configuration in the given test_dir' do
|
72
|
+
expect(Environment).to receive(:search_for_configuration).with(test_dir).
|
73
|
+
and_return(env_file)
|
74
|
+
expect(YAML).to receive(:load_file).with(env_file).
|
75
|
+
and_return('foo' => { 'x' => 'a', 'y' => 'b' })
|
76
|
+
subject
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
66
80
|
end
|
67
81
|
|
68
82
|
describe '.load_default' do
|
69
83
|
subject { Environment.load_default }
|
70
84
|
|
85
|
+
let(:mediawiki_environment) { 'foo' }
|
86
|
+
|
87
|
+
before do
|
88
|
+
expect(ENV).to receive(:[]).with('MEDIAWIKI_ENVIRONMENT').and_return(mediawiki_environment)
|
89
|
+
end
|
90
|
+
|
71
91
|
it 'loads the environment configuration specified by MEDIAWIKI_ENVIRONMENT' do
|
72
|
-
|
73
|
-
expect(Environment).to receive(:load).with('foo', ENV)
|
92
|
+
expect(Environment).to receive(:load).with(mediawiki_environment, ENV, nil)
|
74
93
|
subject
|
75
94
|
end
|
76
95
|
|
77
96
|
context 'where MEDIAWIKI_ENVIRONMENT is not defined' do
|
97
|
+
let(:mediawiki_environment) { nil }
|
98
|
+
|
78
99
|
it 'looks for a "default" environment' do
|
79
|
-
|
80
|
-
expect(Environment).to receive(:load).with('default', ENV)
|
100
|
+
expect(Environment).to receive(:load).with('default', ENV, nil)
|
81
101
|
subject
|
82
102
|
end
|
83
103
|
end
|
@@ -250,6 +270,60 @@ module MediawikiSelenium
|
|
250
270
|
expect(subject).to be(:firefox)
|
251
271
|
end
|
252
272
|
end
|
273
|
+
|
274
|
+
context 'when browser and version are combined' do
|
275
|
+
let(:browser) { 'internet_explorer 8.0' }
|
276
|
+
|
277
|
+
it 'returns only the name' do
|
278
|
+
expect(subject).to be(:internet_explorer)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe '#browser_tags' do
|
284
|
+
subject { env.browser_tags }
|
285
|
+
|
286
|
+
context 'when a version is specified' do
|
287
|
+
let(:browser) { 'internet_explorer 8.0' }
|
288
|
+
|
289
|
+
it 'returns tags for use in filter test scenarios' do
|
290
|
+
expect(subject).to eq(['internet_explorer', 'internet_explorer_8.0'])
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when no version is specified' do
|
295
|
+
let(:browser) { 'internet_explorer' }
|
296
|
+
|
297
|
+
it 'includes only a tag for the browser name' do
|
298
|
+
expect(subject).to eq(['internet_explorer'])
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe '#browser_version' do
|
304
|
+
subject { env.browser_version }
|
305
|
+
|
306
|
+
let(:browser) { 'internet_explorer 8.0' }
|
307
|
+
|
308
|
+
context 'when no explicit version configuration is provided' do
|
309
|
+
it 'is the version specified at the end of browser' do
|
310
|
+
expect(subject).to eq('8.0')
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context 'when an explicit version configuration is provided' do
|
315
|
+
let(:config) { minimum_config.merge(version: '9.0') }
|
316
|
+
|
317
|
+
it 'ignores the version given at the end of browser and returns the explicit one' do
|
318
|
+
expect(subject).to eq('9.0')
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
context 'when no version is specified' do
|
323
|
+
let(:browser) { 'internet_explorer' }
|
324
|
+
|
325
|
+
it { is_expected.to be(nil) }
|
326
|
+
end
|
253
327
|
end
|
254
328
|
|
255
329
|
describe '#current_alternative' do
|
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.
|
4
|
+
version: 1.7.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: 2016-
|
16
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: cucumber
|
@@ -395,6 +395,7 @@ files:
|
|
395
395
|
- lib/mediawiki_selenium/raita/formatter.rb
|
396
396
|
- lib/mediawiki_selenium/raita/logger.rb
|
397
397
|
- lib/mediawiki_selenium/raita/null_io.rb
|
398
|
+
- lib/mediawiki_selenium/rake_task.rb
|
398
399
|
- lib/mediawiki_selenium/remote_browser_factory.rb
|
399
400
|
- lib/mediawiki_selenium/rspec.rb
|
400
401
|
- lib/mediawiki_selenium/rspec/environment.rb
|
@@ -445,7 +446,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
445
446
|
version: '0'
|
446
447
|
requirements: []
|
447
448
|
rubyforge_project:
|
448
|
-
rubygems_version: 2.4.
|
449
|
+
rubygems_version: 2.4.5.1
|
449
450
|
signing_key:
|
450
451
|
specification_version: 4
|
451
452
|
summary: An easy way to run MediaWiki Selenium tests.
|