ae_page_objects 0.0.1.beta.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ module AePageObjects
2
+ class ElementProxy
3
+
4
+ # Remove all instance methods so even things like class()
5
+ # get handled by method_missing(). <lifted from activerecord>
6
+ instance_methods.each do |m|
7
+ unless m.to_s =~ /^(?:nil\?|send|object_id|to_a|tap)$|^__|^respond_to/
8
+ undef_method m
9
+ end
10
+ end
11
+
12
+ def initialize(element_class, *args, &block)
13
+ @element_class = element_class
14
+ @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
+ end
26
+
27
+ # Provided so that visible? can be asked without
28
+ # an explicit check for present? first.
29
+ def visible?
30
+ !!presence.try(:visible?)
31
+ end
32
+
33
+ def present?
34
+ presence.present?
35
+ end
36
+
37
+ def not_present?(timeout = 0)
38
+ Capybara.using_wait_time(timeout) do
39
+ ! present?
40
+ end
41
+ end
42
+
43
+ def presence
44
+ element
45
+ rescue Capybara::ElementNotFound
46
+ nil
47
+ end
48
+
49
+ def is_a?(type)
50
+ type == @element_class || type == ElementProxy
51
+ end
52
+ alias_method :kind_of?, :is_a?
53
+
54
+ def method_missing(name, *args, &block)
55
+ if name == "class"
56
+ return @element_class
57
+ end
58
+
59
+ element.__send__(name, *args, &block)
60
+ end
61
+
62
+ def respond_to?(*args)
63
+ super || @element_class.allocate.respond_to?(*args)
64
+ end
65
+
66
+ private
67
+
68
+ def element
69
+ @element ||= @element_class.new(*@args, &@block)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,19 @@
1
+ module AePageObjects
2
+ class Checkbox < Element
3
+ def check
4
+ node.set true
5
+ end
6
+
7
+ def uncheck
8
+ node.set false
9
+ end
10
+
11
+ def checked?
12
+ node.native.attribute('checked').to_s.eql?("true")
13
+ end
14
+
15
+ def unchecked?
16
+ !checked?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ module AePageObjects
2
+ class Collection < HasOne
3
+ class_attribute :item_class, :instance_writer => false
4
+ self.item_class = Element
5
+
6
+ def at(index, &block)
7
+ if index >= size || index < 0
8
+ nil
9
+ else
10
+ self.item_class.new(self, index, [:xpath, "#{row_xpath}[#{index + 1}]"], &block)
11
+ end
12
+ end
13
+
14
+ alias_method :[], :at
15
+
16
+ def each(&block)
17
+ (0..(size - 1)).each do |index|
18
+ yield at(index)
19
+ end
20
+ end
21
+
22
+ def all
23
+ [].tap do |all|
24
+ self.each { |item| all << item }
25
+ end
26
+ end
27
+
28
+ def size
29
+ node.all(:xpath, row_xpath).size
30
+ end
31
+
32
+ def first(&block)
33
+ self.at(0, &block)
34
+ end
35
+
36
+ def last(&block)
37
+ self.at(size - 1, &block)
38
+ end
39
+
40
+ def add_more(&block)
41
+ append
42
+ last(&block)
43
+ end
44
+
45
+ def row_xpath
46
+ @row_xpath || ".//*[contains(@class, 'item-list')]//*[contains(@class,'row') and not(contains(@style,'display'))]"
47
+ end
48
+
49
+ protected
50
+
51
+ def configure(options)
52
+ super
53
+
54
+ @row_xpath = options.delete(:row_xpath)
55
+ end
56
+
57
+ def append
58
+ node.find('.js-add-item').click
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ module AePageObjects
2
+ class Form < Element
3
+
4
+ private
5
+
6
+ def default_locator
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module AePageObjects
2
+ class HasOne < Element
3
+ def __full_name__
4
+ if parent.respond_to?(:__full_name__)
5
+ "#{parent.__full_name__}_#{__name__}_attributes"
6
+ else
7
+ "#{__name__}_attributes"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module AePageObjects
2
+ class Select < Element
3
+ def set(value)
4
+ node.select(value)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,73 @@
1
+ module AePageObjects
2
+ class Node
3
+ module Methods
4
+ extend ActiveSupport::Concern
5
+
6
+ include Dsl::Element
7
+ include Dsl::NestedElement
8
+ include Dsl::Collection
9
+ include Dsl::FormFor
10
+
11
+ def initialize(capybara_node = Capybara.current_session)
12
+ @node = capybara_node
13
+ end
14
+
15
+ def node
16
+ @node
17
+ end
18
+
19
+ def document
20
+ raise "Must implement!"
21
+ end
22
+
23
+ delegate :current_url, :to => 'self.class'
24
+ delegate :current_url_without_params, :to => 'self.class'
25
+
26
+ delegate :find, :to => :node
27
+ delegate :all, :to => :node
28
+ delegate :value, :to => :node
29
+ delegate :set, :to => :node
30
+ delegate :text, :to => :node
31
+ delegate :visible?, :to => :node
32
+
33
+ private
34
+
35
+ def eval_locator(locator)
36
+ return unless locator
37
+
38
+ if locator.respond_to?(:call)
39
+ locator = instance_eval(&locator)
40
+ end
41
+
42
+ locator.is_a?(Array) ? locator : [locator.to_s]
43
+ end
44
+
45
+ module ClassMethods
46
+
47
+ def current_url
48
+ Capybara.current_session.current_url.sub(/^https?:\/\/[^\/]*/, '')
49
+ end
50
+
51
+ def current_url_without_params
52
+ current_url.sub(/\?.*/, '')
53
+ end
54
+
55
+ def new_subclass(&block)
56
+ klass = Class.new(self)
57
+ klass.class_eval(&block) if block
58
+ klass
59
+ end
60
+
61
+ def new(*args)
62
+ super(*args).tap do |me|
63
+ yield me if block_given?
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ include Methods
70
+ include Concerns::LoadEnsuring
71
+ include Concerns::Staleable
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module AePageObjects
2
+ VERSION = '0.0.1.beta.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ae_page_objects
3
+ version: !ruby/object:Gem::Version
4
+ hash: 4120581079
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - beta
11
+ - 0
12
+ version: 0.0.1.beta.0
13
+ platform: ruby
14
+ authors:
15
+ - Donnie Tognazzini
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2012-11-21 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: activesupport
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 3
33
+ - 0
34
+ - 0
35
+ version: 3.0.0
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: railties
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 7
47
+ segments:
48
+ - 3
49
+ - 0
50
+ - 0
51
+ version: 3.0.0
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: capybara
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ hash: 13
63
+ segments:
64
+ - 1
65
+ - 1
66
+ version: "1.1"
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: appraisal
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 9
78
+ segments:
79
+ - 0
80
+ - 5
81
+ - 1
82
+ version: 0.5.1
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: mocha
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - "="
92
+ - !ruby/object:Gem::Version
93
+ hash: 43
94
+ segments:
95
+ - 0
96
+ - 9
97
+ - 8
98
+ version: 0.9.8
99
+ type: :development
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: selenium-webdriver
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ type: :development
114
+ version_requirements: *id006
115
+ description: Capybara Page Objects pattern
116
+ email: donnie.tognazzini@appfolio.com
117
+ executables: []
118
+
119
+ extensions: []
120
+
121
+ extra_rdoc_files: []
122
+
123
+ files:
124
+ - lib/ae_page_objects.rb
125
+ - lib/ae_page_objects/concerns/load_ensuring.rb
126
+ - lib/ae_page_objects/concerns/staleable.rb
127
+ - lib/ae_page_objects/concerns/visitable.rb
128
+ - lib/ae_page_objects/core/application.rb
129
+ - lib/ae_page_objects/core/application_router.rb
130
+ - lib/ae_page_objects/core/configurable.rb
131
+ - lib/ae_page_objects/core/configuration.rb
132
+ - lib/ae_page_objects/core/constant_resolver.rb
133
+ - lib/ae_page_objects/core/dependencies_hook.rb
134
+ - lib/ae_page_objects/core/dsl/collection.rb
135
+ - lib/ae_page_objects/core/dsl/element.rb
136
+ - lib/ae_page_objects/core/dsl/form_for.rb
137
+ - lib/ae_page_objects/core/dsl/nested_element.rb
138
+ - lib/ae_page_objects/core/internal_helpers.rb
139
+ - lib/ae_page_objects/core/rake_router.rb
140
+ - lib/ae_page_objects/document.rb
141
+ - lib/ae_page_objects/element.rb
142
+ - lib/ae_page_objects/element_proxy.rb
143
+ - lib/ae_page_objects/elements/checkbox.rb
144
+ - lib/ae_page_objects/elements/collection.rb
145
+ - lib/ae_page_objects/elements/form.rb
146
+ - lib/ae_page_objects/elements/has_one.rb
147
+ - lib/ae_page_objects/elements/select.rb
148
+ - lib/ae_page_objects/node.rb
149
+ - lib/ae_page_objects/version.rb
150
+ homepage: http://github.com/appfolio/ae_page_objects
151
+ licenses:
152
+ - MIT
153
+ post_install_message:
154
+ rdoc_options: []
155
+
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project:
179
+ rubygems_version: 1.8.24
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: Capybara Page Objects pattern
183
+ test_files: []
184
+