capybara-experience 0.2 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/capybara-experience.gemspec +2 -0
- data/lib/capybara/experience/pool.rb +54 -0
- data/lib/capybara/experience/rspec.rb +3 -0
- data/lib/capybara/experience/version.rb +1 -1
- data/lib/capybara/experience.rb +22 -15
- metadata +16 -2
- data/lib/capybara/experience/session.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa20ed37708148de49cef701b1a01f8bb178e265aa7e90fd5f0669a60850147
|
4
|
+
data.tar.gz: a7becb3e8c47766a43bc2aa0a5f5ea327042d1b3860342cc4e21ce42966001be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 299a7d14d66b32ee67f19275bce4ede292e2d29c14faddb0561205fde708a2a8dd65133900dd0dc40eadc0f91f931302fcb72d3d8c198e595f1841f6ae2f1d50
|
7
|
+
data.tar.gz: 3c6fae1f8bebef030e7ff554b73a30d022c3553de3b75cc0822645f92332507698800ed5c8076ac37441098b9dfeb6e0f8419eefbc04d135809b552b33e0b5dc
|
data/.gitignore
CHANGED
data/capybara-experience.gemspec
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "singleton"
|
3
|
+
|
4
|
+
module Capybara
|
5
|
+
class Experience
|
6
|
+
class Pool < Hash
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
super(key) || begin
|
11
|
+
driver, _session_name, app_object_id = key.split(":")
|
12
|
+
take(driver: driver, app_object_id: app_object_id, key: key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def take(driver: Capybara.current_driver, app_object_id: Capybara.app.object_id, key: nil)
|
17
|
+
session = idle.find { |s| s.mode == driver && s.app.object_id == app_object_id }
|
18
|
+
if session
|
19
|
+
idle.delete(session)
|
20
|
+
self[key] = delete(session_key(session)) if key
|
21
|
+
else
|
22
|
+
session = ::Capybara::Session.new(driver.to_sym, Capybara.app)
|
23
|
+
key ||= session_key(session)
|
24
|
+
self[key] = session
|
25
|
+
end
|
26
|
+
|
27
|
+
session
|
28
|
+
end
|
29
|
+
|
30
|
+
def idle
|
31
|
+
@idle ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
def taken
|
35
|
+
values - idle
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset_idle!
|
39
|
+
dup.each do |key, session|
|
40
|
+
self[session_key(session)] = delete(key)
|
41
|
+
end
|
42
|
+
@idle = values
|
43
|
+
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def session_key(session)
|
50
|
+
"#{session.mode}:#{session.object_id}:#{session.app.object_id}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/capybara/experience.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "capybara/dsl"
|
3
|
-
require "capybara/experience/
|
3
|
+
require "capybara/experience/pool"
|
4
4
|
|
5
5
|
module Capybara
|
6
6
|
class Experience
|
@@ -23,28 +23,35 @@ module Capybara
|
|
23
23
|
delegate :driver, to: :page
|
24
24
|
|
25
25
|
def page
|
26
|
-
@page ||= Experience::
|
26
|
+
@page ||= Experience::Pool.instance.take(driver: driver_name)
|
27
|
+
|
28
|
+
Capybara::Screenshot.final_session_name = @page.object_id if defined?(Capybara::Screenshot)
|
29
|
+
|
30
|
+
@page
|
27
31
|
end
|
28
32
|
|
29
33
|
def self.wait_for_pending_requests
|
30
|
-
Experience::
|
34
|
+
Experience::Pool.taken.each do |session|
|
31
35
|
session.server.try(:wait_for_pending_requests)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
35
|
-
|
36
|
-
save_and_open_screenshot(path, options.merge(full: true))
|
37
|
-
end
|
39
|
+
class Error < StandardError; end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
document.evaluate('#{xpath}', document, null, XPathResult.ANY_TYPE, null)
|
43
|
-
.iterateNext()
|
44
|
-
.click()
|
45
|
-
JS
|
46
|
-
end
|
41
|
+
module UnifySessionPool
|
42
|
+
def page
|
43
|
+
Capybara::Screenshot.final_session_name = Capybara.session_name if defined?(Capybara::Screenshot)
|
47
44
|
|
48
|
-
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def session_pool
|
51
|
+
@session_pool ||= Experience::Pool.instance
|
52
|
+
end
|
53
|
+
end
|
49
54
|
end
|
55
|
+
|
56
|
+
singleton_class.prepend Experience::UnifySessionPool
|
50
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-experience
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Ong
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: capybara
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
56
70
|
description: Abstractions for Capybara to manage multiple user sessions, encapsulate
|
57
71
|
shared test behavior, and semantically contextualize test code.
|
58
72
|
email:
|
@@ -73,8 +87,8 @@ files:
|
|
73
87
|
- capybara-experience.gemspec
|
74
88
|
- lib/capybara-experience.rb
|
75
89
|
- lib/capybara/experience.rb
|
90
|
+
- lib/capybara/experience/pool.rb
|
76
91
|
- lib/capybara/experience/rspec.rb
|
77
|
-
- lib/capybara/experience/session.rb
|
78
92
|
- lib/capybara/experience/version.rb
|
79
93
|
homepage: https://github.com/ryanong/capybara-experience
|
80
94
|
licenses: []
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Capybara
|
4
|
-
class Experience
|
5
|
-
module Session
|
6
|
-
class << self
|
7
|
-
def next(driver:)
|
8
|
-
pool.next(driver)
|
9
|
-
end
|
10
|
-
|
11
|
-
def create(driver)
|
12
|
-
::Capybara::Session.new(driver, Capybara.app)
|
13
|
-
end
|
14
|
-
|
15
|
-
def pool
|
16
|
-
@pool ||= Pool.new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Pool
|
21
|
-
attr_accessor :idle, :taken
|
22
|
-
|
23
|
-
def initialize
|
24
|
-
@idle = []
|
25
|
-
@taken = []
|
26
|
-
end
|
27
|
-
|
28
|
-
def next(driver)
|
29
|
-
take_idle(driver) || create(driver)
|
30
|
-
end
|
31
|
-
|
32
|
-
def release
|
33
|
-
taken.each(&:reset!)
|
34
|
-
idle.concat(taken)
|
35
|
-
taken.clear
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def take_idle(driver)
|
41
|
-
idle.find { |s| s.mode == driver }.tap do |session|
|
42
|
-
if session
|
43
|
-
idle.delete(session)
|
44
|
-
taken.push(session)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def create(driver)
|
50
|
-
::Capybara::Experience::Session.create(driver).tap do |session|
|
51
|
-
taken.push(session)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|