mediawiki_selenium 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -3
- data/UPGRADE.md +1 -1
- data/features/api.feature +15 -0
- data/features/basic_usage.feature +27 -0
- data/features/saucelabs.feature +14 -0
- data/features/step_definitions/api_helper_steps.rb +11 -0
- data/features/step_definitions/browser_steps.rb +37 -0
- data/features/step_definitions/environment_steps.rb +22 -0
- data/features/step_definitions/user_factory_steps.rb +22 -0
- data/features/support/env.rb +7 -0
- data/features/user_factory.feature +20 -0
- data/lib/mediawiki_selenium.rb +2 -0
- data/lib/mediawiki_selenium/environment.rb +19 -6
- data/lib/mediawiki_selenium/page_factory.rb +1 -1
- data/lib/mediawiki_selenium/support/env.rb +1 -0
- data/lib/mediawiki_selenium/support/modules/api_helper.rb +10 -2
- data/lib/mediawiki_selenium/support/modules/user_factory_helper.rb +35 -0
- data/lib/mediawiki_selenium/user_factory.rb +50 -0
- data/lib/mediawiki_selenium/version.rb +1 -1
- data/mediawiki_selenium.gemspec +2 -2
- data/spec/environment_spec.rb +42 -2
- data/spec/page_factory_spec.rb +12 -0
- data/spec/user_factory_helper_spec.rb +59 -0
- data/spec/user_factory_spec.rb +77 -0
- data/templates/tests/browser/environments.yml +6 -4
- metadata +21 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 329d08a407bf34d62782833f29ddc148c36e75c0
|
4
|
+
data.tar.gz: 34f4f2700b159884ddb8b5e6ddf77c935c8fd9ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b87efa97ee1d7ad227c7d30264daf1b1144a0cedaf3ccb46495a5a68081781fe8ae4cab1db855d7b5dfce880c7ede665e3de58736a4582a521c847c1f16b43e3
|
7
|
+
data.tar.gz: 84993de521a0a42243a8420d91fdb6a41eef45abbc9281a356197968715652b9b5fad2f809799ec5d716b18e4e081da249c8dd248d3865baff9d26be6aea78b8
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ Create a `Gemfile` in the root of your MediaWiki-related project that
|
|
37
37
|
specifies the version of `mediawiki_selenium` you wish to use (typically the
|
38
38
|
latest version).
|
39
39
|
|
40
|
-
gem 'mediawiki_selenium', '~> 1.
|
40
|
+
gem 'mediawiki_selenium', '~> 1.4.0'
|
41
41
|
|
42
42
|
Install the gem and its dependencies by running `bundle install`. (If
|
43
43
|
[Bundler](http://bundler.io/) is not yet installed, install it with
|
@@ -169,6 +169,30 @@ behavior.
|
|
169
169
|
# Keep xvfb running after execution (the default is to kill it)
|
170
170
|
HEADLESS_DESTROY_AT_EXIT=false bundle exec cucumber ...
|
171
171
|
|
172
|
+
### User Factory
|
173
|
+
|
174
|
+
Setting `user_factory` to `true` for an environment in your `environments.yml`
|
175
|
+
will enable the {MediawikiSelenium::UserFactoryHelper} module. The module
|
176
|
+
automatically creates accounts referenced in tests (calls to the `user`,
|
177
|
+
`password`, or `as_user` methods) using the MW API, and randomizes the actual
|
178
|
+
user names.
|
179
|
+
|
180
|
+
These randomized fixtures can greatly improve the atomicity/isolation of your
|
181
|
+
scenarios, ensuring control over the initial user state (e.g. an edit count
|
182
|
+
of 0) or allowing scenarios to run in parallel on the same MW installation.
|
183
|
+
|
184
|
+
Note that using this feature will result in a large number of accounts being
|
185
|
+
created for each run. You'll typically want to enable this feature only for
|
186
|
+
environments like CI (`integration`) or perhaps your local MW-Vagrant.
|
187
|
+
|
188
|
+
integration:
|
189
|
+
user_factory: true
|
190
|
+
# ...
|
191
|
+
|
192
|
+
mw-vagrant-host:
|
193
|
+
user_factory: true
|
194
|
+
# ...
|
195
|
+
|
172
196
|
### Screenshots
|
173
197
|
|
174
198
|
You can get screenshots on failures by setting the environment
|
@@ -199,9 +223,17 @@ See https://www.mediawiki.org/wiki/Gerrit
|
|
199
223
|
|
200
224
|
## Release notes
|
201
225
|
|
226
|
+
### 1.4.0 2015-06-26
|
227
|
+
* New user factory module provides account fixtures for a greater level of
|
228
|
+
isolation/atomicity between scenarios
|
229
|
+
* Updated MediaWiki API client and Cucumber dependencies for various fixes
|
230
|
+
* Fixed `PageFactory#on` for cases where it's used before browser
|
231
|
+
initialization
|
232
|
+
* Implemented integration tests that run against a MediaWiki instance in CI
|
233
|
+
|
202
234
|
### 1.3.0 2015-06-10
|
203
|
-
* Added
|
204
|
-
|
235
|
+
* Added `Environment#override` for overriding environment configuration at
|
236
|
+
runtime
|
205
237
|
* Removed deprecated `APIPage` page object and updated upgrade docs
|
206
238
|
|
207
239
|
### 1.2.1 2015-06-02
|
data/UPGRADE.md
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
@integration
|
2
|
+
Feature: MW API helper
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given I have configured my environment from `ENV` and with:
|
6
|
+
"""
|
7
|
+
user_factory: true
|
8
|
+
"""
|
9
|
+
And I have set "MEDIAWIKI_URL" in my shell
|
10
|
+
And I am using the user factory
|
11
|
+
And I am using the API helper
|
12
|
+
|
13
|
+
Scenario: API helper automatically authenticates
|
14
|
+
When I access the API helper
|
15
|
+
Then the API client should have authenticated
|
@@ -0,0 +1,27 @@
|
|
1
|
+
@integration
|
2
|
+
Feature: Basic usage
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given I have configured my environment from `ENV` and with:
|
6
|
+
"""
|
7
|
+
browser: phantomjs
|
8
|
+
"""
|
9
|
+
And I have set "MEDIAWIKI_URL" in my shell
|
10
|
+
And I am using a local browser
|
11
|
+
|
12
|
+
Scenario: The configured browser is used
|
13
|
+
When I start interacting with the browser
|
14
|
+
Then the browser name is `:phantomjs`
|
15
|
+
|
16
|
+
Scenario: Browsers are started on-demand
|
17
|
+
When I start interacting with the browser
|
18
|
+
Then the browser is open
|
19
|
+
|
20
|
+
Scenario: Browsers are closed automatically
|
21
|
+
Given I have started a browser
|
22
|
+
When teardown is called
|
23
|
+
Then the browser should have closed
|
24
|
+
|
25
|
+
Scenario: Navigating to the wiki
|
26
|
+
When I navigate to the `wiki_url`
|
27
|
+
Then the wiki page should have loaded
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: Remote browser sessions through SauceLabs
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I have configured my environment from `ENV` and with:
|
5
|
+
"""
|
6
|
+
browser: firefox
|
7
|
+
platform: linux
|
8
|
+
"""
|
9
|
+
|
10
|
+
Scenario: SauceLabs sessions start just like a normal browser
|
11
|
+
Given I have set "SAUCE_ONDEMAND_USERNAME" in my shell
|
12
|
+
And I have set "SAUCE_ONDEMAND_ACCESS_KEY" in my shell
|
13
|
+
When I start interacting with the browser
|
14
|
+
Then the browser is open
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
Given(/^I have started a browser$/) do
|
4
|
+
@env.browser
|
5
|
+
end
|
6
|
+
|
7
|
+
Given(/^I am using a local browser$/) do
|
8
|
+
allow(@env).to receive(:remote?).and_return(false)
|
9
|
+
end
|
10
|
+
|
11
|
+
When(/^I start interacting with the browser$/) do
|
12
|
+
@env.browser
|
13
|
+
end
|
14
|
+
|
15
|
+
When(/^I navigate to the `wiki_url`$/) do
|
16
|
+
@env.browser.goto @env.wiki_url
|
17
|
+
end
|
18
|
+
|
19
|
+
When(/^teardown is called$/) do
|
20
|
+
@env.teardown
|
21
|
+
end
|
22
|
+
|
23
|
+
Then(/^the browser is open$/) do
|
24
|
+
expect(@env.browser).to exist
|
25
|
+
end
|
26
|
+
|
27
|
+
Then(/^the wiki page should have loaded$/) do
|
28
|
+
expect(@env.browser.element(tag_name: 'body', class: 'mediawiki')).to be_present
|
29
|
+
end
|
30
|
+
|
31
|
+
Then(/^the browser should have closed$/) do
|
32
|
+
expect(@env.browser).to_not exist
|
33
|
+
end
|
34
|
+
|
35
|
+
Then(/^the browser name is `:(.*?)`$/) do |type|
|
36
|
+
expect(@env.browser.name).to eq(type.to_sym)
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Given(/^I have configured my environment with:$/) do |yaml|
|
2
|
+
@env = MediawikiSelenium::Environment.new(YAML.load(yaml))
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^I have configured my environment from `ENV`(?: and with:)?$/) do |*args|
|
6
|
+
configs = [ENV]
|
7
|
+
configs << YAML.load(args.first) if args.length > 0
|
8
|
+
|
9
|
+
@env = MediawikiSelenium::Environment.new(*configs)
|
10
|
+
end
|
11
|
+
|
12
|
+
Given(/^I have set "(.*?)" in my shell$/) do |var|
|
13
|
+
begin
|
14
|
+
@env.lookup(var)
|
15
|
+
rescue MediawikiSelenium::ConfigurationError
|
16
|
+
pending "you must configure #{var.upcase} to run this test"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
After do
|
21
|
+
@env.teardown unless @env.nil?
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Given(/^I am using the user factory$/) do
|
2
|
+
@env.extend(MediawikiSelenium::ApiHelper, MediawikiSelenium::UserFactoryHelper)
|
3
|
+
end
|
4
|
+
|
5
|
+
When(/^I reference the primary user$/) do
|
6
|
+
@user = @env.user
|
7
|
+
end
|
8
|
+
|
9
|
+
When(/^I reference user "(.*?)"$/) do |id|
|
10
|
+
@user = @env.user(id)
|
11
|
+
end
|
12
|
+
|
13
|
+
Then(/^an account for the user should exist$/) do
|
14
|
+
@users = @env.api.query(list: 'users', ususers: @user).data['users']
|
15
|
+
|
16
|
+
expect(@users).to be_a(Array)
|
17
|
+
expect(@users.first).to include('name')
|
18
|
+
end
|
19
|
+
|
20
|
+
Then(/^the user name should start with "(.*?)"$/) do |prefix|
|
21
|
+
expect(@users.first['name']).to start_with(prefix)
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
@integration
|
2
|
+
Feature: User factory
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given I have configured my environment from `ENV` and with:
|
6
|
+
"""
|
7
|
+
user_factory: true
|
8
|
+
"""
|
9
|
+
And I have set "MEDIAWIKI_URL" in my shell
|
10
|
+
And I am using the user factory
|
11
|
+
|
12
|
+
Scenario: User factory creates the primary account
|
13
|
+
When I reference the primary user
|
14
|
+
Then an account for the user should exist
|
15
|
+
And the user name should start with "User-"
|
16
|
+
|
17
|
+
Scenario: User factory creates an alternative account
|
18
|
+
When I reference user "some_user"
|
19
|
+
Then an account for the user should exist
|
20
|
+
And the user name should start with "User-some-user-"
|
data/lib/mediawiki_selenium.rb
CHANGED
@@ -8,4 +8,6 @@ module MediawikiSelenium
|
|
8
8
|
autoload :PageFactory, 'mediawiki_selenium/page_factory'
|
9
9
|
autoload :Raita, 'mediawiki_selenium/raita'
|
10
10
|
autoload :RemoteBrowserFactory, 'mediawiki_selenium/remote_browser_factory'
|
11
|
+
autoload :UserFactory, 'mediawiki_selenium/user_factory'
|
12
|
+
autoload :UserFactoryHelper, 'mediawiki_selenium/support/modules/user_factory_helper'
|
11
13
|
end
|
@@ -103,6 +103,7 @@ module MediawikiSelenium
|
|
103
103
|
def initialize(*configs)
|
104
104
|
@_config = configs.map { |config| normalize_config(config) }.reduce(:merge)
|
105
105
|
@_factory_cache = {}
|
106
|
+
@_current_alternatives = {}
|
106
107
|
end
|
107
108
|
|
108
109
|
# Whether the given environment is equal to this one. Two environments are
|
@@ -143,10 +144,7 @@ module MediawikiSelenium
|
|
143
144
|
# @yieldparam password [String] Alternative MediaWiki password.
|
144
145
|
#
|
145
146
|
def as_user(id, &blk)
|
146
|
-
user
|
147
|
-
password = lookup(:mediawiki_password, id: id, default: -> { lookup(:mediawiki_password) })
|
148
|
-
|
149
|
-
with(mediawiki_user: user, mediawiki_password: password, &blk)
|
147
|
+
with(mediawiki_user: user(id), mediawiki_password: password(id), &blk)
|
150
148
|
end
|
151
149
|
|
152
150
|
# Browser with which to drive tests.
|
@@ -180,6 +178,14 @@ module MediawikiSelenium
|
|
180
178
|
lookup(:browser, default: 'firefox').downcase.to_sym
|
181
179
|
end
|
182
180
|
|
181
|
+
# Returns the current alternate ID for the given configuration key.
|
182
|
+
#
|
183
|
+
# @param key [Symbol] Configuration key.
|
184
|
+
#
|
185
|
+
def current_alternative(key)
|
186
|
+
@_current_alternatives[key]
|
187
|
+
end
|
188
|
+
|
183
189
|
# A reference to this environment. Can be used in conjunction with {#[]}
|
184
190
|
# for syntactic sugar in looking up environment configuration where `self`
|
185
191
|
# would otherwise seem ambiguous.
|
@@ -317,7 +323,7 @@ module MediawikiSelenium
|
|
317
323
|
# @return [String]
|
318
324
|
#
|
319
325
|
def password(id = nil)
|
320
|
-
lookup(:mediawiki_password, id: id)
|
326
|
+
lookup(:mediawiki_password, id: id, default: -> { lookup(:mediawiki_password) })
|
321
327
|
end
|
322
328
|
|
323
329
|
# Whether this environment has been configured to use remote browser
|
@@ -461,7 +467,14 @@ module MediawikiSelenium
|
|
461
467
|
# @yield [*args] Values of the overridden configuration.
|
462
468
|
#
|
463
469
|
def with_alternative(names, id, &blk)
|
464
|
-
|
470
|
+
names = Array(names)
|
471
|
+
|
472
|
+
original_alts = @_current_alternatives.dup
|
473
|
+
@_current_alternatives.merge!(names.each.with_object({}) { |n, alts| alts[n] = id })
|
474
|
+
|
475
|
+
with(lookup_all(names, id: id), &blk)
|
476
|
+
ensure
|
477
|
+
@_current_alternatives = original_alts
|
465
478
|
end
|
466
479
|
|
467
480
|
protected
|
@@ -14,7 +14,7 @@ module MediawikiSelenium
|
|
14
14
|
# @see http://www.rubydoc.info/github/cheezy/page-object
|
15
15
|
#
|
16
16
|
def on_page(page_class, params = { using_params: {} }, visit = false)
|
17
|
-
@browser = browser if visit
|
17
|
+
@browser = browser if visit || !defined?(@browser)
|
18
18
|
|
19
19
|
super(page_class, params, false) do |page|
|
20
20
|
if page.respond_to?(:goto)
|
@@ -12,15 +12,23 @@ module MediawikiSelenium
|
|
12
12
|
def api
|
13
13
|
@_api_cache ||= {}
|
14
14
|
|
15
|
-
url =
|
15
|
+
url = api_url
|
16
16
|
|
17
17
|
@_api_cache[[url, user]] ||= MediawikiApi::Client.new(url).tap do |client|
|
18
18
|
client.log_in(user, password)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
# URL to the API endpoint for the current wiki.
|
23
|
+
#
|
24
|
+
# @return [String]
|
25
|
+
#
|
26
|
+
def api_url
|
27
|
+
lookup(:mediawiki_api_url, default: -> { api_url_from(lookup(:mediawiki_url)) })
|
28
|
+
end
|
29
|
+
|
22
30
|
# Ensures the given alternative account exists by attempting to create it
|
23
|
-
# via the API.
|
31
|
+
# via the API. Any errors related to the account already existing are
|
24
32
|
# swallowed.
|
25
33
|
#
|
26
34
|
# @param id [Symbol] ID of alternative user.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'mediawiki_api'
|
2
|
+
|
3
|
+
module MediawikiSelenium
|
4
|
+
# Provisions user accounts automatically using the MW API upon their first
|
5
|
+
# reference.
|
6
|
+
#
|
7
|
+
# Note you must explicitly enable this functionality by setting
|
8
|
+
# `user_factory` to `true` in your `environments.yml` configuration file.
|
9
|
+
#
|
10
|
+
# @see Environment
|
11
|
+
# @see UserFactory
|
12
|
+
#
|
13
|
+
module UserFactoryHelper
|
14
|
+
# @!method user
|
15
|
+
# @!method password
|
16
|
+
#
|
17
|
+
# Create account upon the first reference to its username or password.
|
18
|
+
#
|
19
|
+
# @see Environment#user
|
20
|
+
# @see Environment#password
|
21
|
+
#
|
22
|
+
[:user, :password].each do |name|
|
23
|
+
define_method(name) do |id = nil|
|
24
|
+
return super(id) unless lookup(:user_factory, default: false)
|
25
|
+
factory.create(id || current_alternative(:"mediawiki_#{name}"))[name]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def factory
|
32
|
+
@_user_factory ||= UserFactory.new(MediawikiApi::Client.new(api_url))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'mediawiki_api'
|
2
|
+
|
3
|
+
module MediawikiSelenium
|
4
|
+
# Factory class used to provision test user fixtures via the MW API.
|
5
|
+
#
|
6
|
+
class UserFactory
|
7
|
+
# Create a user factory. This should typically be done anew for each test
|
8
|
+
# case.
|
9
|
+
#
|
10
|
+
# @param api [MediawikiApi::Client] API client used to create users.
|
11
|
+
#
|
12
|
+
def initialize(api)
|
13
|
+
@api = api
|
14
|
+
@users = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Return a unique name for the given user ID. Each account will be created
|
18
|
+
# via the MW API if it has not already been created.
|
19
|
+
#
|
20
|
+
# @param id [Symbol, nil] Alternative ID or `nil` for the primary user.
|
21
|
+
#
|
22
|
+
# @return [Hash]
|
23
|
+
#
|
24
|
+
def create(id = nil)
|
25
|
+
return @users[id] if @users.include?(id)
|
26
|
+
|
27
|
+
user = unique(id, 'User')
|
28
|
+
pass = unique(id, 'Pass')
|
29
|
+
|
30
|
+
create_account(user, pass)
|
31
|
+
|
32
|
+
@users[id] = { user: user, password: pass }
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def create_account(user, password)
|
38
|
+
@api.create_account(user, password)
|
39
|
+
rescue MediawikiApi::ApiError => e
|
40
|
+
raise e unless e.code == 'userexists'
|
41
|
+
end
|
42
|
+
|
43
|
+
def unique(id, label)
|
44
|
+
prefix = label
|
45
|
+
prefix += "-#{id.to_s.gsub('_', '-')}" if id
|
46
|
+
|
47
|
+
"#{prefix}-#{Random.rand(36**10).to_s(36)}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/mediawiki_selenium.gemspec
CHANGED
@@ -27,10 +27,10 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_runtime_dependency 'cucumber', '~> 1.3', '>= 1.3.
|
30
|
+
spec.add_runtime_dependency 'cucumber', '~> 1.3', '>= 1.3.20'
|
31
31
|
spec.add_runtime_dependency 'headless', '~> 1.0', '>= 1.0.1'
|
32
32
|
spec.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.1'
|
33
|
-
spec.add_runtime_dependency 'mediawiki_api', '~> 0.
|
33
|
+
spec.add_runtime_dependency 'mediawiki_api', '~> 0.4', '>= 0.4.1'
|
34
34
|
spec.add_runtime_dependency 'page-object', '~> 1.0'
|
35
35
|
spec.add_runtime_dependency 'rest-client', '~> 1.6', '>= 1.6.7'
|
36
36
|
spec.add_runtime_dependency 'rspec-expectations', '~> 2.14', '>= 2.14.4'
|
data/spec/environment_spec.rb
CHANGED
@@ -23,6 +23,10 @@ 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
|
+
|
26
30
|
describe '.load' do
|
27
31
|
subject { Environment.load(name, extra) }
|
28
32
|
|
@@ -65,14 +69,14 @@ module MediawikiSelenium
|
|
65
69
|
subject { Environment.load_default }
|
66
70
|
|
67
71
|
it 'loads the environment configuration specified by MEDIAWIKI_ENVIRONMENT' do
|
68
|
-
|
72
|
+
mock_environment_name('foo')
|
69
73
|
expect(Environment).to receive(:load).with('foo', ENV)
|
70
74
|
subject
|
71
75
|
end
|
72
76
|
|
73
77
|
context 'where MEDIAWIKI_ENVIRONMENT is not defined' do
|
74
78
|
it 'looks for a "default" environment' do
|
75
|
-
|
79
|
+
mock_environment_name(nil)
|
76
80
|
expect(Environment).to receive(:load).with('default', ENV)
|
77
81
|
subject
|
78
82
|
end
|
@@ -232,6 +236,42 @@ module MediawikiSelenium
|
|
232
236
|
end
|
233
237
|
end
|
234
238
|
|
239
|
+
describe '#current_alternative' do
|
240
|
+
subject { env.current_alternative(key) }
|
241
|
+
|
242
|
+
let(:key) { :foo }
|
243
|
+
let(:config) { { foo: 'a', foo_b: 'b', foo_c: 'c' } }
|
244
|
+
|
245
|
+
context 'when there is no active alternative' do
|
246
|
+
it { is_expected.to be(nil) }
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'when there is an active alternative' do
|
250
|
+
it 'should return the alternative ID' do
|
251
|
+
env.with_alternative([key], :b) do
|
252
|
+
expect(subject).to eq(:b)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'when there are nested active alternatives' do
|
258
|
+
it 'should return the latest alternative ID' do
|
259
|
+
env.with_alternative([key], :b) do
|
260
|
+
env.with_alternative([key], :c) do
|
261
|
+
expect(subject).to eq(:c)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'properly restores the active alternatives for each level of nesting' do
|
267
|
+
env.with_alternative([key], :b) do
|
268
|
+
env.with_alternative([key], :c)
|
269
|
+
expect(subject).to eq(:b)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
235
275
|
describe '#env' do
|
236
276
|
subject { env.env }
|
237
277
|
|
data/spec/page_factory_spec.rb
CHANGED
@@ -17,6 +17,10 @@ module MediawikiSelenium
|
|
17
17
|
|
18
18
|
let(:browser) { double('Watir::Browser') }
|
19
19
|
|
20
|
+
before do
|
21
|
+
allow(env).to receive(:browser).and_return(browser)
|
22
|
+
end
|
23
|
+
|
20
24
|
it 'returns a new page object' do
|
21
25
|
page = double('PageObject')
|
22
26
|
expect(page_class).to receive(:new).and_return(page)
|
@@ -33,6 +37,14 @@ module MediawikiSelenium
|
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
40
|
+
context 'when the browser has not yet been initialized' do
|
41
|
+
it 'initializes a browser' do
|
42
|
+
allow(page_class).to receive(:new)
|
43
|
+
expect(env).to receive(:browser).and_return(browser)
|
44
|
+
subject
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
36
48
|
context 'when told to visit a page' do
|
37
49
|
let(:visit) { true }
|
38
50
|
let(:config) { { mediawiki_url: 'http://an.example/wiki/' } }
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MediawikiSelenium
|
4
|
+
describe UserFactoryHelper do
|
5
|
+
let(:env) { Environment.new(config).extend(ApiHelper, UserFactoryHelper) }
|
6
|
+
|
7
|
+
let(:api_url) { 'http://an.example/api' }
|
8
|
+
let(:api) { double('MediawikiApi::Client') }
|
9
|
+
|
10
|
+
[:user, :password].each do |method|
|
11
|
+
describe "##{method}" do
|
12
|
+
subject { env.send(method, id) }
|
13
|
+
|
14
|
+
context 'when the `user_factory` option is enabled' do
|
15
|
+
let(:config) { { mediawiki_api_url: api_url, user_factory: true } }
|
16
|
+
|
17
|
+
before do
|
18
|
+
expect(MediawikiApi::Client).to receive(:new).with(api_url).and_return(api)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'given no alternative ID' do
|
22
|
+
let(:id) { nil }
|
23
|
+
|
24
|
+
it 'creates the primary account and returns the name' do
|
25
|
+
expect(api).to receive(:create_account)
|
26
|
+
|
27
|
+
expect(subject).to be_a(String)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'given an existing alternative ID' do
|
32
|
+
let(:id) { :b }
|
33
|
+
|
34
|
+
it 'creates the alternative account and returns the name' do
|
35
|
+
expect(api).to receive(:create_account)
|
36
|
+
|
37
|
+
expect(subject).to be_a(String)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should be different from the primary account' do
|
41
|
+
expect(api).to receive(:create_account).twice
|
42
|
+
|
43
|
+
expect(subject).not_to eq(env.user)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when the `user_factory` option is not enabled' do
|
49
|
+
let(:config) { { mediawiki_api_url: api_url, user_factory: false } }
|
50
|
+
let(:id) { nil }
|
51
|
+
|
52
|
+
it "delegates to `Environment##{method}`" do
|
53
|
+
expect { subject }.to raise_error(ConfigurationError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MediawikiSelenium
|
4
|
+
describe UserFactory do
|
5
|
+
subject { factory }
|
6
|
+
|
7
|
+
let(:factory) { UserFactory.new(api) }
|
8
|
+
let(:api) { double('MediawikiApi::Client') }
|
9
|
+
|
10
|
+
it { is_expected.to be_a(UserFactory) }
|
11
|
+
|
12
|
+
describe '#create' do
|
13
|
+
let(:rando) { 'x' * 10 }
|
14
|
+
|
15
|
+
before do
|
16
|
+
n = double('Fixnum')
|
17
|
+
allow(Random).to receive(:rand).and_return(n)
|
18
|
+
allow(n).to receive(:to_s).with(36).and_return(rando)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'given no ID' do
|
22
|
+
it 'creates a new user like "User--<random 10 chars>"' do
|
23
|
+
expect(api).to receive(:create_account).
|
24
|
+
with("User-#{rando}", "Pass-#{rando}")
|
25
|
+
|
26
|
+
factory.create
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the user name and password' do
|
30
|
+
allow(api).to receive(:create_account)
|
31
|
+
|
32
|
+
expect(factory.create).to eq(user: "User-#{rando}", password: "Pass-#{rando}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'given an ID' do
|
37
|
+
it 'creates a new user like "User-<id>-<random 10 chars>"' do
|
38
|
+
expect(api).to receive(:create_account).
|
39
|
+
with("User-foo-#{rando}", "Pass-foo-#{rando}")
|
40
|
+
|
41
|
+
factory.create(:foo)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'replaces underscores in IDs with dashes' do
|
45
|
+
expect(api).to receive(:create_account).
|
46
|
+
with("User-foo-bar-#{rando}", "Pass-foo-bar-#{rando}")
|
47
|
+
|
48
|
+
factory.create(:foo_bar)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns the alternative user name and password' do
|
52
|
+
allow(api).to receive(:create_account)
|
53
|
+
|
54
|
+
expect(factory.create(:foo)).
|
55
|
+
to eq(user: "User-foo-#{rando}", password: "Pass-foo-#{rando}")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'called more than once' do
|
60
|
+
it 'will not create the same account twice' do
|
61
|
+
expect(api).to receive(:create_account).once.
|
62
|
+
with("User-foo-#{rando}", "Pass-foo-#{rando}")
|
63
|
+
|
64
|
+
factory.create(:foo)
|
65
|
+
factory.create(:foo)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns the same user and password' do
|
69
|
+
expect(api).to receive(:create_account).
|
70
|
+
with("User-foo-#{rando}", "Pass-foo-#{rando}")
|
71
|
+
|
72
|
+
expect(factory.create(:foo)).to be(factory.create(:foo))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -15,14 +15,12 @@
|
|
15
15
|
# bundle exec cucumber
|
16
16
|
#
|
17
17
|
mw-vagrant-host: &default
|
18
|
+
user_factory: true
|
18
19
|
mediawiki_url: http://127.0.0.1:8080/wiki/
|
19
|
-
mediawiki_user: Selenium_user
|
20
|
-
mediawiki_password: vagrant
|
21
20
|
|
22
21
|
mw-vagrant-guest:
|
22
|
+
user_factory: true
|
23
23
|
mediawiki_url: http://127.0.0.1/wiki/
|
24
|
-
mediawiki_user: Selenium_user
|
25
|
-
mediawiki_password: vagrant
|
26
24
|
|
27
25
|
beta:
|
28
26
|
mediawiki_url: http://en.wikipedia.beta.wmflabs.org/wiki/
|
@@ -34,4 +32,8 @@ test2:
|
|
34
32
|
mediawiki_user: Selenium_user
|
35
33
|
# mediawiki_password: SET THIS IN THE ENVIRONMENT!
|
36
34
|
|
35
|
+
integration:
|
36
|
+
user_factory: true
|
37
|
+
# mediawiki_url: THIS WILL BE SET BY JENKINS
|
38
|
+
|
37
39
|
default: *default
|
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.4.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-06-
|
16
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: cucumber
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version: '1.3'
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.3.
|
27
|
+
version: 1.3.20
|
28
28
|
type: :runtime
|
29
29
|
prerelease: false
|
30
30
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: '1.3'
|
35
35
|
- - ">="
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.3.
|
37
|
+
version: 1.3.20
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: headless
|
40
40
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,20 +81,20 @@ dependencies:
|
|
81
81
|
requirements:
|
82
82
|
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '0.
|
84
|
+
version: '0.4'
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0.
|
87
|
+
version: 0.4.1
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: '0.
|
94
|
+
version: '0.4'
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.
|
97
|
+
version: 0.4.1
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: page-object
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -330,6 +330,15 @@ files:
|
|
330
330
|
- README.md
|
331
331
|
- UPGRADE.md
|
332
332
|
- bin/mediawiki-selenium-init
|
333
|
+
- features/api.feature
|
334
|
+
- features/basic_usage.feature
|
335
|
+
- features/saucelabs.feature
|
336
|
+
- features/step_definitions/api_helper_steps.rb
|
337
|
+
- features/step_definitions/browser_steps.rb
|
338
|
+
- features/step_definitions/environment_steps.rb
|
339
|
+
- features/step_definitions/user_factory_steps.rb
|
340
|
+
- features/support/env.rb
|
341
|
+
- features/user_factory.feature
|
333
342
|
- lib/mediawiki_selenium.rb
|
334
343
|
- lib/mediawiki_selenium/browser_factory.rb
|
335
344
|
- lib/mediawiki_selenium/browser_factory/base.rb
|
@@ -356,11 +365,13 @@ files:
|
|
356
365
|
- lib/mediawiki_selenium/support/hooks.rb
|
357
366
|
- lib/mediawiki_selenium/support/modules/api_helper.rb
|
358
367
|
- lib/mediawiki_selenium/support/modules/strict_pending.rb
|
368
|
+
- lib/mediawiki_selenium/support/modules/user_factory_helper.rb
|
359
369
|
- lib/mediawiki_selenium/support/pages.rb
|
360
370
|
- lib/mediawiki_selenium/support/pages/login_page.rb
|
361
371
|
- lib/mediawiki_selenium/support/pages/random_page.rb
|
362
372
|
- lib/mediawiki_selenium/support/pages/reset_preferences_page.rb
|
363
373
|
- lib/mediawiki_selenium/support/sauce.rb
|
374
|
+
- lib/mediawiki_selenium/user_factory.rb
|
364
375
|
- lib/mediawiki_selenium/version.rb
|
365
376
|
- lib/mediawiki_selenium/warnings_formatter.rb
|
366
377
|
- mediawiki_selenium.gemspec
|
@@ -373,6 +384,8 @@ files:
|
|
373
384
|
- spec/page_factory_spec.rb
|
374
385
|
- spec/remote_browser_factory_spec.rb
|
375
386
|
- spec/spec_helper.rb
|
387
|
+
- spec/user_factory_helper_spec.rb
|
388
|
+
- spec/user_factory_spec.rb
|
376
389
|
- templates/tests/browser/environments.yml
|
377
390
|
- templates/tests/browser/features/support/env.rb
|
378
391
|
homepage: https://gerrit.wikimedia.org/r/#/admin/projects/mediawiki/selenium
|