pagetience 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/lib/pagetience/configuration.rb +30 -0
- data/lib/pagetience/dsl.rb +4 -0
- data/lib/pagetience/meditate.rb +1 -1
- data/lib/pagetience/platforms/page-object-gem.rb +19 -21
- data/lib/pagetience/version.rb +1 -1
- data/lib/pagetience.rb +63 -32
- metadata +3 -5
- data/lib/pagetience/exceptions.rb +0 -9
- data/lib/pagetience/platforms/base.rb +0 -30
- data/lib/pagetience/platforms/element_platforms.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 047639c7bb485cabfaede710c9398d3d9f469fcc
|
4
|
+
data.tar.gz: cf3130de096efde5b85cfb5776213a3b1160161d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77dddb513326bd516ccb69b36fc101182afb900b105fe4eb9288dbc794e4528a3f4d6d13ce2461a3b050dbcea5de2b19b87cc46ce9336e30f707e3c97b85c5f9
|
7
|
+
data.tar.gz: b7fe6cfc8b03af4fa6f83769b6ecd0bd7c99bcf037dbed82f2ef85ca5e25845b4d1abbfa92aa1690f66638cbd27b62758826b7202ce8533b58ac3256ab917fd3
|
data/README.md
CHANGED
@@ -91,13 +91,32 @@ class SomePage
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def wait_longer_for_foo
|
94
|
-
wait_for_element :foo, 60, 5
|
94
|
+
wait_for_element :foo, 60, 5 # wait up to 60 seconds, polling every 5 seconds
|
95
95
|
end
|
96
96
|
end
|
97
|
+
```
|
98
|
+
|
99
|
+
## Configuration
|
100
|
+
Pagetience can be configured, too.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
Pagetience.configure do |config|
|
104
|
+
config.timeout = 60
|
105
|
+
config.polling = 5
|
97
106
|
end
|
98
107
|
```
|
99
108
|
|
100
|
-
|
109
|
+
It can then be retrieve easily!
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
def give_me_a_property
|
113
|
+
Pagetience.config.timeout
|
114
|
+
end
|
115
|
+
|
116
|
+
give_me_a_property # => 60
|
117
|
+
````
|
118
|
+
|
119
|
+
#### Adjusting the Timeout/Polling for a specific Page
|
101
120
|
You can use the `waiting` method to specify how long you want to wait and, optionally, at what interval to poll the page for element visibility.
|
102
121
|
|
103
122
|
The default timeout is **30** seconds, polling every second.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Pagetience
|
2
|
+
class Configuration
|
3
|
+
VALID_PROPERTIES = [
|
4
|
+
:timeout,
|
5
|
+
:polling,
|
6
|
+
:platform
|
7
|
+
]
|
8
|
+
|
9
|
+
attr_accessor *VALID_PROPERTIES
|
10
|
+
|
11
|
+
# Default timeout in seconds
|
12
|
+
DEFAULT_TIMEOUT = 30
|
13
|
+
|
14
|
+
# Default polling in seconds
|
15
|
+
DEFAULT_POLLING = 1
|
16
|
+
|
17
|
+
# Default element platform
|
18
|
+
DEFAULT_PLATFORM = Pagetience::Platform::PageObjectGem
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@timeout = DEFAULT_TIMEOUT
|
22
|
+
@polling = DEFAULT_POLLING
|
23
|
+
@platform = DEFAULT_PLATFORM
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(sym, *args)
|
27
|
+
raise Pagetience::ConfigurationError, "Unknown property #{sym}."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/pagetience/dsl.rb
CHANGED
data/lib/pagetience/meditate.rb
CHANGED
@@ -1,36 +1,34 @@
|
|
1
1
|
module Pagetience
|
2
|
-
module
|
3
|
-
class PageObjectGem
|
4
|
-
attr_reader :page_object_instance
|
5
|
-
|
2
|
+
module Platform
|
3
|
+
class PageObjectGem
|
6
4
|
class << self
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
5
|
+
def init(base, *args)
|
6
|
+
args.flatten! if args
|
11
7
|
|
12
|
-
|
13
|
-
|
8
|
+
base.class.send(:define_method, :visit) do
|
9
|
+
args[1] || false
|
10
|
+
end
|
11
|
+
base.instance_eval do
|
12
|
+
PageObject.instance_method(:initialize).bind(self).call(base.browser, visit)
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
self.new base
|
16
|
+
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@
|
24
|
-
PageObject.instance_method(:initialize).bind(self).call(@browser, visit)
|
25
|
-
end
|
19
|
+
attr_reader :page_object, :browser
|
20
|
+
|
21
|
+
def initialize(page)
|
22
|
+
@page_object = page
|
23
|
+
@browser = @page_object.browser
|
26
24
|
end
|
27
25
|
|
28
26
|
def underlying_element_for(sym)
|
29
|
-
@
|
27
|
+
@page_object.send("#{sym}_element").element
|
30
28
|
end
|
31
29
|
|
32
30
|
def is_element_present?(sym)
|
33
|
-
@
|
31
|
+
@page_object.send("#{sym}_element").visible?
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
data/lib/pagetience/version.rb
CHANGED
data/lib/pagetience.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
|
-
require 'pagetience/
|
1
|
+
require 'pagetience/platforms/page-object-gem'
|
2
|
+
|
3
|
+
require 'pagetience/configuration'
|
2
4
|
require 'pagetience/meditate'
|
3
5
|
require 'pagetience/version'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
module Pagetience
|
8
|
+
class TimeoutError < StandardError; end
|
9
|
+
class PlatformError < StandardError; end
|
10
|
+
class ConfigurationError < StandardError; end
|
7
11
|
|
8
|
-
|
12
|
+
class << self
|
13
|
+
attr_writer :config
|
14
|
+
|
15
|
+
def config
|
16
|
+
@config ||= Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure
|
20
|
+
yield config
|
21
|
+
end
|
22
|
+
end
|
9
23
|
|
10
|
-
module Pagetience
|
11
24
|
module ClassMethods
|
12
25
|
def required(*elements)
|
13
26
|
elements.keep_if { |e| e.is_a? Symbol }
|
@@ -26,30 +39,26 @@ module Pagetience
|
|
26
39
|
end
|
27
40
|
end
|
28
41
|
|
29
|
-
|
30
|
-
|
31
|
-
|
42
|
+
# "Private" methods to avoid naming collision but remain helpful
|
43
|
+
# They can be messed with though, if you ever see fit.
|
44
|
+
attr_accessor :_waiting_timeout, :_waiting_polling, :_required_elements
|
32
45
|
|
46
|
+
attr_reader :browser
|
33
47
|
attr_reader :element_platform
|
34
|
-
attr_reader :_required_elements
|
35
48
|
|
36
49
|
def self.included(base)
|
37
50
|
base.extend ClassMethods
|
38
51
|
end
|
39
52
|
|
40
|
-
def initialize(
|
41
|
-
@browser =
|
42
|
-
|
43
|
-
current_page = self
|
44
|
-
@browser.class.send(:define_method, :current_page) { current_page }
|
53
|
+
def initialize(*args)
|
54
|
+
@browser = args[0]
|
55
|
+
set_current_page
|
45
56
|
|
46
|
-
|
47
|
-
@element_platform.platform_initialize args
|
57
|
+
@element_platform = Pagetience.config.platform.init self, args
|
48
58
|
|
49
59
|
@loaded = false
|
50
|
-
@_waiting_timeout = _waiting_timeout ||
|
51
|
-
@_waiting_polling = _waiting_polling ||
|
52
|
-
|
60
|
+
@_waiting_timeout = _waiting_timeout || Pagetience.config.timeout
|
61
|
+
@_waiting_polling = _waiting_polling || Pagetience.config.polling
|
53
62
|
@_required_elements = _required_elements || []
|
54
63
|
wait_for_required_elements
|
55
64
|
end
|
@@ -58,11 +67,13 @@ module Pagetience
|
|
58
67
|
!!@loaded
|
59
68
|
end
|
60
69
|
|
70
|
+
# Waits for all elements specified by .required to be present
|
71
|
+
# @param [Fixnum] timeout Time to wait in seconds
|
72
|
+
# @param [Fixnum] polling How often to poll
|
61
73
|
def wait_for_required_elements(timeout=nil, polling=nil)
|
62
74
|
opts = {
|
63
|
-
timeout: timeout
|
64
|
-
polling: polling
|
65
|
-
expecting: true,
|
75
|
+
timeout: timeout,
|
76
|
+
polling: polling,
|
66
77
|
msg: "Timed out after polling every #{:polling}s for #{:timeout}s waiting for the page to be loaded."
|
67
78
|
}
|
68
79
|
wait_for(opts) do
|
@@ -70,37 +81,57 @@ module Pagetience
|
|
70
81
|
end
|
71
82
|
end
|
72
83
|
|
84
|
+
# Wait for an element to be present
|
85
|
+
# @param [Symbol] sym Name of the element
|
86
|
+
# @param [Fixnum] timeout Time to wait in seconds
|
87
|
+
# @param [Fixnum] polling How often to poll
|
73
88
|
def wait_for_element(sym, timeout=nil, polling=nil)
|
74
89
|
opts = {
|
75
|
-
timeout: timeout
|
76
|
-
polling: polling
|
77
|
-
expecting: true,
|
90
|
+
timeout: timeout,
|
91
|
+
polling: polling,
|
78
92
|
msg: "Timed out after waiting for the element #{sym} to be present."
|
79
93
|
}
|
80
94
|
wait_for(opts) { @element_platform.is_element_present? sym }
|
81
95
|
end
|
82
96
|
|
97
|
+
# Wait for a transition to another page
|
98
|
+
# @param [Fixnum] timeout Time to wait in seconds
|
99
|
+
# @param [Fixnum] polling How often to poll
|
83
100
|
def wait_for_transition_to(page, timeout=nil, polling=nil)
|
84
101
|
page = page.new browser
|
85
102
|
opts = {
|
86
|
-
timeout: timeout
|
87
|
-
polling: polling
|
88
|
-
expecting: true,
|
103
|
+
timeout: timeout,
|
104
|
+
polling: polling,
|
89
105
|
msg: "Timed out after waiting for the page to transition to #{page}."
|
90
106
|
}
|
91
107
|
wait_for(opts) { page.loaded? }
|
92
108
|
page
|
93
109
|
end
|
94
110
|
|
111
|
+
# Generic waiting method
|
112
|
+
# @param [Hash] opts
|
113
|
+
# Valid options:
|
114
|
+
# :timeout = Time to wait in seconds
|
115
|
+
# :polling = How often to poll
|
116
|
+
# :expecting = The expected result for the block to return
|
117
|
+
# :msg = The exception message if the timeout occurs
|
95
118
|
def wait_for(opts={}, &block)
|
119
|
+
opts = {
|
120
|
+
timeout: @_waiting_timeout,
|
121
|
+
polling: @_waiting_polling,
|
122
|
+
expecting: true,
|
123
|
+
msg: "Timed out after waiting for #{@_waiting_timeout}s, polling every #{@_waiting_polling}s."
|
124
|
+
}.merge(opts) do |key, old, new|
|
125
|
+
new.nil? ? old : new
|
126
|
+
end
|
96
127
|
Pagetience::Meditate.for(opts) { block.call }
|
97
128
|
end
|
98
129
|
|
99
130
|
private
|
100
131
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
132
|
+
# Sets .current on the browser
|
133
|
+
def set_current_page
|
134
|
+
current_page = self
|
135
|
+
@browser.class.send(:define_method, :current_page) { current_page }
|
105
136
|
end
|
106
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagetience
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek McNeil
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -152,12 +152,10 @@ files:
|
|
152
152
|
- README.md
|
153
153
|
- Rakefile
|
154
154
|
- lib/pagetience.rb
|
155
|
+
- lib/pagetience/configuration.rb
|
155
156
|
- lib/pagetience/cucumber.rb
|
156
157
|
- lib/pagetience/dsl.rb
|
157
|
-
- lib/pagetience/exceptions.rb
|
158
158
|
- lib/pagetience/meditate.rb
|
159
|
-
- lib/pagetience/platforms/base.rb
|
160
|
-
- lib/pagetience/platforms/element_platforms.rb
|
161
159
|
- lib/pagetience/platforms/page-object-gem.rb
|
162
160
|
- lib/pagetience/version.rb
|
163
161
|
- pagetience.gemspec
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Pagetience
|
2
|
-
module ElementPlatforms
|
3
|
-
class Base
|
4
|
-
attr_reader :browser
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def find(klazz)
|
8
|
-
valid_ancestor = ANCESTORS.find { |a| a.present? klazz }
|
9
|
-
if valid_ancestor
|
10
|
-
valid_ancestor.new klazz
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(*args)
|
16
|
-
@browser = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def platform_initialize(*args); end
|
20
|
-
|
21
|
-
def underlying_element_for(sym)
|
22
|
-
nil
|
23
|
-
end
|
24
|
-
|
25
|
-
def is_element_present?(sym)
|
26
|
-
false
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|