ae_page_objects 0.5.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,13 +2,19 @@ module AePageObjects
2
2
  class Document < Node
3
3
  include Concerns::Visitable
4
4
 
5
- attr_reader :window
6
-
7
5
  def initialize
8
6
  super(Capybara.current_session)
7
+ end
9
8
 
10
- @window = Window.current
11
- @window.current_document = self
9
+ if defined? Selenium::WebDriver
10
+ attr_reader :window
11
+
12
+ def initialize
13
+ super(Capybara.current_session)
14
+
15
+ @window = Window.current
16
+ @window.current_document = self
17
+ end
12
18
  end
13
19
 
14
20
  def document
@@ -1,15 +1,7 @@
1
1
  module AePageObjects
2
2
  class Element < Node
3
3
  attr_reader :parent
4
-
5
- class << self
6
- def new(*args)
7
- super(*args).tap do |me|
8
- yield me if block_given?
9
- end
10
- end
11
- end
12
-
4
+
13
5
  def initialize(parent, options_or_locator = {})
14
6
  @parent = parent
15
7
  @locator = nil
@@ -1,3 +1,5 @@
1
+ require 'timeout'
2
+
1
3
  module AePageObjects
2
4
  class ElementProxy
3
5
 
@@ -9,36 +11,25 @@ module AePageObjects
9
11
  end
10
12
  end
11
13
 
12
- def initialize(element_class, *args, &block)
14
+ def initialize(element_class, *args)
13
15
  @element_class = element_class
14
16
  @args = args
15
- @block = block
16
-
17
- # Yield to the block immediately by creating
18
- # the element. Block use assumes presence. Since
19
- # the underlying element is passed when yielding
20
- # the block level variable won't have access to
21
- # the proxy methods, but that's ok.
22
- if block_given?
23
- element
24
- end
25
17
  end
26
18
 
27
19
  # Provided so that visible? can be asked without
28
20
  # an explicit check for present? first.
29
21
  def visible?
30
- inst = presence
31
- ! inst.nil? && inst.visible?
22
+ wait_for do
23
+ inst = presence
24
+ !! inst && inst.visible?
25
+ end
32
26
  end
33
27
 
34
28
  def not_visible?
35
- Capybara.current_session.wait_until do
36
- Capybara.using_wait_time(0) do
37
- ! visible?
38
- end
29
+ wait_for do
30
+ inst = presence
31
+ inst.nil? || ! inst.visible?
39
32
  end
40
- rescue Capybara::TimeoutError
41
- false
42
33
  end
43
34
 
44
35
  def present?
@@ -46,13 +37,9 @@ module AePageObjects
46
37
  end
47
38
 
48
39
  def not_present?
49
- Capybara.current_session.wait_until do
50
- Capybara.using_wait_time(0) do
51
- ! present?
52
- end
40
+ wait_for do
41
+ ! present?
53
42
  end
54
- rescue Capybara::TimeoutError
55
- false
56
43
  end
57
44
 
58
45
  def presence
@@ -82,9 +69,18 @@ module AePageObjects
82
69
  end
83
70
 
84
71
  private
85
-
72
+
73
+ def wait_for(&block)
74
+ Timeout.timeout(Capybara.default_wait_time) do
75
+ sleep(0.05) until value = Capybara.using_wait_time(0, &block)
76
+ value
77
+ end
78
+ rescue Timeout::Error
79
+ false
80
+ end
81
+
86
82
  def element
87
- @element ||= @element_class.new(*@args, &@block)
83
+ @element ||= @element_class.new(*@args)
88
84
  end
89
85
  end
90
86
  end
@@ -19,19 +19,20 @@ module AePageObjects
19
19
  self.class.item_class
20
20
  end
21
21
 
22
- def at(index, &block)
22
+
23
+ def at(index)
23
24
  if index >= size || index < 0
24
25
  nil
25
26
  else
26
- item_at(index, &block)
27
+ item_at(index)
27
28
  end
28
29
  end
29
30
 
30
- def [](index, &block)
31
- at(index, &block)
31
+ def [](index)
32
+ at(index)
32
33
  end
33
34
 
34
- def each(&block)
35
+ def each
35
36
  (0..(size - 1)).each do |index|
36
37
  yield at(index)
37
38
  end
@@ -41,8 +42,8 @@ module AePageObjects
41
42
  node.all(:xpath, item_xpath).size
42
43
  end
43
44
 
44
- def last(&block)
45
- self.at(size - 1, &block)
45
+ def last
46
+ self.at(size - 1)
46
47
  end
47
48
 
48
49
  private
@@ -53,8 +54,8 @@ module AePageObjects
53
54
  @item_locator = options.delete(:item_locator) || default_item_locator
54
55
  end
55
56
 
56
- def item_at(index, &block)
57
- ElementProxy.new(item_class_at(index), self, :name => index, :locator => item_locator_at(index), &block)
57
+ def item_at(index)
58
+ ElementProxy.new(item_class_at(index), self, :name => index, :locator => item_locator_at(index))
58
59
  end
59
60
 
60
61
  def item_class_at(index)
@@ -62,7 +63,26 @@ module AePageObjects
62
63
  end
63
64
 
64
65
  def item_xpath
65
- @item_xpath ||= Capybara::Selector.normalize(*eval_locator(@item_locator)).xpaths.first
66
+ @item_xpath ||= begin
67
+ evaled_locator = eval_locator(@item_locator)
68
+
69
+ if Capybara::VERSION =~ /\A1/
70
+ Capybara::Selector.normalize(*evaled_locator).xpaths.first
71
+ else
72
+ query_args = evaled_locator + [{:exact => true}]
73
+ query = Capybara::Query.new(*query_args)
74
+
75
+ result = query.xpath
76
+
77
+ # if it's CSS, we need to run it through XPath as Capybara::Query#xpath only
78
+ # works when the selector is xpath. Lame.
79
+ if query.selector.format == :css
80
+ result = XPath.css(query.xpath).to_xpath
81
+ end
82
+
83
+ result
84
+ end
85
+ end
66
86
  end
67
87
 
68
88
  def item_locator_at(index)
@@ -1,3 +1,3 @@
1
1
  module AePageObjects
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_page_objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-29 00:00:00.000000000 Z
12
+ date: 2014-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.1'
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '2.3'
22
25
  type: :runtime
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  none: false
26
29
  requirements:
27
- - - ~>
30
+ - - ! '>='
28
31
  - !ruby/object:Gem::Version
29
32
  version: '1.1'
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '2.3'
30
36
  description: Capybara Page Objects pattern
31
37
  email:
32
38
  - engineering@appfolio.com
@@ -75,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
81
  version: '0'
76
82
  segments:
77
83
  - 0
78
- hash: 947206196524353569
84
+ hash: 472038393023831036
79
85
  required_rubygems_version: !ruby/object:Gem::Requirement
80
86
  none: false
81
87
  requirements: