pagetience 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 004f4ab33f47df3056f939497b29b16c12105985
4
- data.tar.gz: c2ccc08d0088664a2c5ede5dc686adcaee6563ff
3
+ metadata.gz: 108a062d3af7caac8148b20d6862d7b6b8a5663d
4
+ data.tar.gz: a08091eaf61fec1f8fc7f153f1cb98c408aada5a
5
5
  SHA512:
6
- metadata.gz: e70f0e4b6837fcba9b3ea2e3e7582c3b1e792750c41f8fe50157c216044737ada154bdd5c7be6c4b98ac4187c561f0d88de05e2e17427b314ecab81757795eb4
7
- data.tar.gz: 183ac9d6f088af1335d12fc3c7cea3452a95578d3de27ab36e6e66ceaedb23be4bb294752614d0cf8489853f5cca315287762c482441f56ffad05b44ad16e373
6
+ metadata.gz: e5937d66687049bc3696cf9c03de038bc0484f2fb1a60fed4b70d1708f5a8094891e3535255485c7cba9db519e9609837a5e97dfe16d37b11e369e44667d2a21
7
+ data.tar.gz: afe6e463749d5206377e1e3e329273b9657598978206951e89e9287f7a2f75e5325b423314775cc097c754a0d08bf53da580ec2bb5ab5fa1b32bf16866635165
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  *.iml
11
11
  /.idea/
12
+ *.gem
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Pagetience
2
- A simple gem to verify pages and important elements are loaded.
2
+ [![Build Status](https://travis-ci.org/dmcneil/pagetience.svg?branch=master)](https://travis-ci.org/dmcneil/pagetience)
3
+
4
+ Pronounced like "patience".
5
+
6
+ Using a simple DSL, you can declare which of your page object elements must be present and visible on the page before your code can consider it **loaded**.
3
7
 
4
8
  ## Installation
5
9
  Add this line to your application's Gemfile:
@@ -47,9 +51,15 @@ class GooglePage
47
51
  end
48
52
  ```
49
53
 
54
+ ## Supported Platforms
55
+ Currently, this gem only works with the [page-object](https://github.com/cheezy/page-object) gem. It's a high priority to make working with other page object/webdriver libraries easier.
56
+
50
57
  ## Notes/Todo/Issues
51
- ### IMPORTANT
52
- Currently, this gem only works with the [page-object](https://github.com/cheezy/page-object)gem. It's a high priority to make working with other page object/webdriver libraries easier.
58
+ 1. Add platform support for Selenium WebDriver
59
+ 2. Add platform support for Watir WebDriver
60
+ 3. SitePrism?
61
+ 4. Documentation
62
+ 5. Organize unit tests
53
63
 
54
64
  ## Contributing
55
65
  Bug reports and pull requests are welcome on GitHub at https://github.com/dmcneil/pagetience.
@@ -2,5 +2,8 @@ module Pagetience
2
2
  module Exceptions
3
3
  class Timeout < StandardError
4
4
  end
5
+
6
+ class Platform < StandardError
7
+ end
5
8
  end
6
9
  end
@@ -1,5 +1,5 @@
1
1
  module Pagetience
2
- class Timer
2
+ class Meditate
3
3
  attr_accessor :timeout, :polling, :block
4
4
 
5
5
  def initialize(timeout=30, polling=1, &block)
@@ -8,7 +8,7 @@ module Pagetience
8
8
  @block = block
9
9
  end
10
10
 
11
- def run_until(expected=nil)
11
+ def until_enlightened(expected=nil, msg='Timed out waiting for the expected result.')
12
12
  raise ArgumentError, 'Timeout cannot be lower than the polling value.' unless @timeout > @polling
13
13
 
14
14
  while @timeout > 0 && @timeout > @polling
@@ -18,8 +18,9 @@ module Pagetience
18
18
  @timeout = @timeout - @polling
19
19
  end
20
20
 
21
+ raise Pagetience::Exceptions::Timeout, msg unless @latest_result
22
+
21
23
  @latest_result
22
24
  end
23
- alias_method :run, :run_until
24
25
  end
25
26
  end
@@ -0,0 +1,26 @@
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; end
20
+
21
+ def underlying_element_for(sym)
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Pagetience
2
+ module ElementPlatforms
3
+ ANCESTORS = [Pagetience::ElementPlatforms::PageObjectGem]
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ module Pagetience
2
+ module ElementPlatforms
3
+ class PageObjectGem < Base
4
+ attr_reader :page_object_instance
5
+
6
+ class << self
7
+ def present?(klazz)
8
+ klazz.class.ancestors.include? PageObject
9
+ end
10
+ end
11
+
12
+ def initialize(klazz)
13
+ super
14
+
15
+ @page_object_instance = klazz
16
+ @browser = @page_object_instance.browser
17
+ end
18
+
19
+ def platform_initialize
20
+ @page_object_instance.instance_eval do
21
+ PageObject.instance_method(:initialize).bind(self).call(@browser)
22
+ end
23
+ end
24
+
25
+ def underlying_element_for(sym)
26
+ @page_object_instance.send("#{sym}_element").element
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Pagetience
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/pagetience.rb CHANGED
@@ -1,16 +1,37 @@
1
1
  require 'pagetience/exceptions'
2
- require 'pagetience/timer'
2
+ require 'pagetience/meditate'
3
3
  require 'pagetience/version'
4
4
 
5
+ require 'pagetience/platforms/base'
6
+ require 'pagetience/platforms/page-object-gem'
7
+
8
+ require 'pagetience/platforms/element_platforms'
9
+
5
10
  module Pagetience
6
- SUPPORTED_ELEMENT_LIBS = [PageObject]
11
+ module ClassMethods
12
+ def required(*elements)
13
+ elements.keep_if { |e| e.is_a? Symbol }
14
+ define_method('_required_elements') do
15
+ elements
16
+ end
17
+ end
18
+
19
+ def waiting(timeout, polling=1)
20
+ define_method('_waiting_timeout') do
21
+ timeout
22
+ end
23
+ define_method('_waiting_polling') do
24
+ polling
25
+ end
26
+ end
27
+ end
7
28
 
8
29
  attr_accessor :_waiting_timeout, :_waiting_polling
9
30
 
10
31
  attr_reader :browser
11
32
  attr_reader :loaded
12
33
 
13
- attr_reader :element_lib
34
+ attr_reader :element_platform
14
35
  attr_reader :_poller, :_required_elements, :_underlying_elements
15
36
 
16
37
  def self.included(base)
@@ -18,12 +39,11 @@ module Pagetience
18
39
  end
19
40
 
20
41
  def initialize(browser)
21
- @element_lib = self.class.ancestors.find { |m| SUPPORTED_ELEMENT_LIBS.include? m }
22
- raise StandardError, 'Could not determine what page object platform is being used.' unless @element_lib
42
+ @browser = browser
23
43
 
24
- PageObject.instance_method(:initialize).bind(self).call(browser) if @element_lib == PageObject
44
+ determine_platform
45
+ @element_platform.platform_initialize
25
46
 
26
- @browser = browser
27
47
  @loaded = false
28
48
  @_waiting_timeout = _waiting_timeout || 30
29
49
  @_waiting_polling = _waiting_polling || 1
@@ -39,17 +59,13 @@ module Pagetience
39
59
  end
40
60
 
41
61
  def gather_underlying_elements
42
- if @element_lib == PageObject
43
- @_required_elements.each do |e|
44
- if respond_to? "#{e}_element"
45
- @_underlying_elements << self.send("#{e}_element").element
46
- end
47
- end
62
+ @_required_elements.each do |e|
63
+ @_underlying_elements << @element_platform.underlying_element_for(e)
48
64
  end
49
65
  end
50
66
 
51
67
  def wait_for_required_elements
52
- @_poller = Pagetience::Timer.new(@_waiting_timeout, @_waiting_polling) do
68
+ @_poller = Pagetience::Meditate.new(@_waiting_timeout, @_waiting_polling) do
53
69
  begin
54
70
  unless @_underlying_elements.any? { |e| !e.visible? }
55
71
  @loaded = true
@@ -58,28 +74,18 @@ module Pagetience
58
74
  # TODO implement better strategy for certain platforms
59
75
  end
60
76
  end
61
- @_poller.run_until true
77
+ @_poller.until_enlightened true
62
78
 
63
79
  unless loaded?
64
80
  raise Pagetience::Exceptions::Timeout, "Timed out after polling every #{@_poller.polling}s for #{@_poller.timeout}s waiting for the page to be loaded."
65
81
  end
66
82
  end
67
83
 
68
- module ClassMethods
69
- def required(*elements)
70
- elements.keep_if { |e| e.is_a? Symbol }
71
- define_method('_required_elements') do
72
- elements
73
- end
74
- end
84
+ private
75
85
 
76
- def waiting(timeout, polling=1)
77
- define_method('_waiting_timeout') do
78
- timeout
79
- end
80
- define_method('_waiting_polling') do
81
- polling
82
- end
83
- end
86
+ def determine_platform
87
+ @element_platform = Pagetience::ElementPlatforms::Base.find(self)
88
+
89
+ raise Pagetience::Exceptions::Platform, 'Could not determine what element platform is being used.' unless @element_platform
84
90
  end
85
91
  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.1.0
4
+ version: 0.2.0
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-21 00:00:00.000000000 Z
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -153,7 +153,10 @@ files:
153
153
  - Rakefile
154
154
  - lib/pagetience.rb
155
155
  - lib/pagetience/exceptions.rb
156
- - lib/pagetience/timer.rb
156
+ - lib/pagetience/meditate.rb
157
+ - lib/pagetience/platforms/base.rb
158
+ - lib/pagetience/platforms/element_platforms.rb
159
+ - lib/pagetience/platforms/page-object-gem.rb
157
160
  - lib/pagetience/version.rb
158
161
  - pagetience.gemspec
159
162
  homepage: http://www.github.com/dmcneil/pagetience
@@ -176,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
179
  version: '0'
177
180
  requirements: []
178
181
  rubyforge_project:
179
- rubygems_version: 2.6.4
182
+ rubygems_version: 2.5.1
180
183
  signing_key:
181
184
  specification_version: 4
182
185
  summary: A simple gem for making page object waiting easy.