page-object 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +20 -2
- data/features/div.feature +1 -1
- data/features/element.feature +160 -0
- data/features/html/images/circle.png +0 -0
- data/features/html/static_elements.html +8 -0
- data/features/image.feature +32 -0
- data/features/span.feature +37 -0
- data/features/step_definitions/accessor_steps.rb +29 -3
- data/features/step_definitions/element_steps.rb +33 -0
- data/features/support/page.rb +13 -0
- data/lib/page-object/accessors.rb +32 -2
- data/lib/page-object/elements.rb +2 -0
- data/lib/page-object/elements/button.rb +13 -0
- data/lib/page-object/elements/element.rb +1 -0
- data/lib/page-object/elements/image.rb +26 -0
- data/lib/page-object/elements/link.rb +11 -0
- data/lib/page-object/elements/span.rb +12 -0
- data/lib/page-object/platforms/selenium_button.rb +13 -0
- data/lib/page-object/platforms/selenium_element.rb +63 -1
- data/lib/page-object/platforms/selenium_image.rb +22 -0
- data/lib/page-object/platforms/selenium_link.rb +13 -0
- data/lib/page-object/platforms/selenium_table.rb +1 -1
- data/lib/page-object/platforms/watir_element.rb +63 -1
- data/lib/page-object/platforms/watir_image.rb +20 -0
- data/lib/page-object/selenium_page_object.rb +29 -0
- data/lib/page-object/version.rb +1 -1
- data/lib/page-object/watir_page_object.rb +29 -0
- data/page-object.gemspec +2 -2
- data/spec/page-object/accessors_spec.rb +64 -0
- data/spec/page-object/elements/button_spec.rb +11 -0
- data/spec/page-object/elements/element_spec.rb +50 -0
- data/spec/page-object/elements/image_spec.rb +62 -0
- data/spec/page-object/elements/link_spec.rb +11 -0
- data/spec/page-object/elements/span_spec.rb +22 -0
- metadata +22 -4
data/lib/page-object/elements.rb
CHANGED
@@ -2,11 +2,24 @@ module PageObject
|
|
2
2
|
module Elements
|
3
3
|
class Button < Element
|
4
4
|
|
5
|
+
def initialize(element, platform)
|
6
|
+
@element = element
|
7
|
+
include_platform_for platform
|
8
|
+
end
|
9
|
+
|
5
10
|
protected
|
6
11
|
|
7
12
|
def self.watir_finders
|
8
13
|
super + [:text]
|
9
14
|
end
|
15
|
+
|
16
|
+
def include_platform_for platform
|
17
|
+
super
|
18
|
+
if platform[:platform] == :selenium
|
19
|
+
require 'page-object/platforms/selenium_button'
|
20
|
+
self.class.send :include, PageObject::Platforms::SeleniumButton
|
21
|
+
end
|
22
|
+
end
|
10
23
|
end
|
11
24
|
end
|
12
25
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Elements
|
3
|
+
class Image < Element
|
4
|
+
def initialize(element, platform)
|
5
|
+
@element = element
|
6
|
+
include_platform_for platform
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def include_platform_for platform
|
12
|
+
super
|
13
|
+
if platform[:platform] == :watir
|
14
|
+
require 'page-object/platforms/watir_image'
|
15
|
+
self.class.send :include, PageObject::Platforms::WatirImage
|
16
|
+
elsif platform[:platform] == :selenium
|
17
|
+
require 'page-object/platforms/selenium_image'
|
18
|
+
self.class.send :include, PageObject::Platforms::SeleniumImage
|
19
|
+
else
|
20
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -2,6 +2,10 @@ module PageObject
|
|
2
2
|
module Elements
|
3
3
|
class Link < Element
|
4
4
|
|
5
|
+
def initialize(element, platform)
|
6
|
+
@element = element
|
7
|
+
include_platform_for platform
|
8
|
+
end
|
5
9
|
|
6
10
|
protected
|
7
11
|
|
@@ -21,6 +25,13 @@ module PageObject
|
|
21
25
|
super.merge(:text => :link_text)
|
22
26
|
end
|
23
27
|
|
28
|
+
def include_platform_for platform
|
29
|
+
super
|
30
|
+
if platform[:platform] == :selenium
|
31
|
+
require 'page-object/platforms/selenium_link'
|
32
|
+
self.class.send :include, PageObject::Platforms::SeleniumLink
|
33
|
+
end
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
26
37
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module SeleniumButton
|
4
|
+
#
|
5
|
+
# Override PageObject::PLatforms::SeleniumElement#text because
|
6
|
+
# #text does not reliabably return a value in Selenium
|
7
|
+
#
|
8
|
+
def text
|
9
|
+
raise "value not available on link element with Selenium"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -18,12 +18,74 @@ module PageObject
|
|
18
18
|
end
|
19
19
|
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# Get the text for the element
|
22
|
+
#
|
23
|
+
# @return [String]
|
22
24
|
#
|
23
25
|
def text
|
24
26
|
@element.text
|
25
27
|
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Get the value of this element
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
#
|
34
|
+
def value
|
35
|
+
@element.attribute('value')
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# compare this element to another to determine if they are equal
|
40
|
+
#
|
41
|
+
def ==(other)
|
42
|
+
@element == other.element
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Get the tag name of this element
|
47
|
+
#
|
48
|
+
# @return [String]
|
49
|
+
#
|
50
|
+
def tag_name
|
51
|
+
@element.tag_name
|
52
|
+
end
|
26
53
|
|
54
|
+
#
|
55
|
+
# Get the value of a the given attribute of the element. Will return the current value, even if
|
56
|
+
# this has been modified after the page has been loaded. More exactly, this method will return
|
57
|
+
# the value of the given attribute, unless that attribute is not present, in which case the
|
58
|
+
# value of the property with the same name is returned. If neither value is set, nil is
|
59
|
+
# returned. The "style" attribute is converted as best can be to a text representation with a
|
60
|
+
# trailing semi-colon. The following are deemed to be "boolean" attributes, and will
|
61
|
+
# return either "true" or "false":
|
62
|
+
#
|
63
|
+
# async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
|
64
|
+
# defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
|
65
|
+
# iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate,
|
66
|
+
# nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
|
67
|
+
# selected, spellcheck, truespeed, willvalidate
|
68
|
+
#
|
69
|
+
# Finally, the following commonly mis-capitalized attribute/property names are evaluated as
|
70
|
+
# expected:
|
71
|
+
#
|
72
|
+
# class, readonly
|
73
|
+
#
|
74
|
+
# @param [String]
|
75
|
+
# attribute name
|
76
|
+
# @return [String,nil]
|
77
|
+
# attribute value
|
78
|
+
#
|
79
|
+
def attribute(attribute_name)
|
80
|
+
@element.attribute attribute_name
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Click this element
|
85
|
+
#
|
86
|
+
def click
|
87
|
+
@element.click
|
88
|
+
end
|
27
89
|
end
|
28
90
|
end
|
29
91
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module SeleniumImage
|
4
|
+
|
5
|
+
#
|
6
|
+
# Return the width of the image.
|
7
|
+
#
|
8
|
+
def width
|
9
|
+
dimension = @element.size
|
10
|
+
dimension.width
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# Return the height of the image
|
15
|
+
#
|
16
|
+
def height
|
17
|
+
dimension = @element.size
|
18
|
+
dimension.height
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module SeleniumLink
|
4
|
+
#
|
5
|
+
# Override PageObject::PLatforms::SeleniumElement#value because
|
6
|
+
# #value is not available on links in Selenium.
|
7
|
+
#
|
8
|
+
def value
|
9
|
+
raise "value not available on link element with Selenium"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -18,12 +18,74 @@ module PageObject
|
|
18
18
|
end
|
19
19
|
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# Get the text for the element
|
22
|
+
#
|
23
|
+
# @return [String]
|
22
24
|
#
|
23
25
|
def text
|
24
26
|
@element.text
|
25
27
|
end
|
26
28
|
|
29
|
+
#
|
30
|
+
# Get the value of this element
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
#
|
34
|
+
def value
|
35
|
+
@element.value
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# compare this element to another to determine if they are equal
|
40
|
+
#
|
41
|
+
def ==(other)
|
42
|
+
@element == other.element
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Get the tag name of this element
|
47
|
+
#
|
48
|
+
# @return [String]
|
49
|
+
#
|
50
|
+
def tag_name
|
51
|
+
@element.tag_name
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Get the value of a the given attribute of the element. Will return the current value, even if
|
56
|
+
# this has been modified after the page has been loaded. More exactly, this method will return
|
57
|
+
# the value of the given attribute, unless that attribute is not present, in which case the
|
58
|
+
# value of the property with the same name is returned. If neither value is set, nil is
|
59
|
+
# returned. The "style" attribute is converted as best can be to a text representation with a
|
60
|
+
# trailing semi-colon. The following are deemed to be "boolean" attributes, and will
|
61
|
+
# return either "true" or "false":
|
62
|
+
#
|
63
|
+
# async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
|
64
|
+
# defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
|
65
|
+
# iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate,
|
66
|
+
# nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
|
67
|
+
# selected, spellcheck, truespeed, willvalidate
|
68
|
+
#
|
69
|
+
# Finally, the following commonly mis-capitalized attribute/property names are evaluated as
|
70
|
+
# expected:
|
71
|
+
#
|
72
|
+
# class, readonly
|
73
|
+
#
|
74
|
+
# @param [String]
|
75
|
+
# attribute name
|
76
|
+
# @return [String,nil]
|
77
|
+
# attribute value
|
78
|
+
#
|
79
|
+
def attribute(attribute_name)
|
80
|
+
@element.attribute_value attribute_name
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Click this element
|
85
|
+
#
|
86
|
+
def click
|
87
|
+
@element.click
|
88
|
+
end
|
27
89
|
end
|
28
90
|
end
|
29
91
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module WatirImage
|
4
|
+
|
5
|
+
#
|
6
|
+
# Return the width of the image.
|
7
|
+
#
|
8
|
+
def width
|
9
|
+
@element.width
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Return the height of the image
|
14
|
+
#
|
15
|
+
def height
|
16
|
+
@element.height
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -206,6 +206,25 @@ module PageObject
|
|
206
206
|
PageObject::Elements::Div.new(element, :platform => :selenium)
|
207
207
|
end
|
208
208
|
|
209
|
+
#
|
210
|
+
# platform method to return the text for a span
|
211
|
+
# See PageObject::Accessors#span
|
212
|
+
#
|
213
|
+
def span_text_for(identifier)
|
214
|
+
how, what = Elements::Span.selenium_identifier_for identifier
|
215
|
+
@browser.find_element(how, what).text
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# platform method to return a PageObject::Elements::Span element
|
220
|
+
# See PageObject::Accessors#span
|
221
|
+
#
|
222
|
+
def span_for(identifier)
|
223
|
+
how, what = Elements::Span.selenium_identifier_for identifier
|
224
|
+
element = @browser.find_element(how, what)
|
225
|
+
PageObject::Elements::Span.new(element, :platform => :selenium)
|
226
|
+
end
|
227
|
+
|
209
228
|
#
|
210
229
|
# platform method to click a button
|
211
230
|
# See PageObject::Accessors#button
|
@@ -253,5 +272,15 @@ module PageObject
|
|
253
272
|
element = @browser.find_element(how, what)
|
254
273
|
PageObject::Elements::TableCell.new(element, :platform => :selenium)
|
255
274
|
end
|
275
|
+
|
276
|
+
#
|
277
|
+
# platform method to retrieve an image element
|
278
|
+
# See PageObject::Accessors#image
|
279
|
+
#
|
280
|
+
def image_for(identifier)
|
281
|
+
how, what = Elements::Image.selenium_identifier_for identifier
|
282
|
+
element = @browser.find_element(how, what)
|
283
|
+
PageObject::Elements::Image.new(element, :platform => :selenium)
|
284
|
+
end
|
256
285
|
end
|
257
286
|
end
|
data/lib/page-object/version.rb
CHANGED
@@ -206,6 +206,25 @@ module PageObject
|
|
206
206
|
PageObject::Elements::Div.new(element, :platform => :watir)
|
207
207
|
end
|
208
208
|
|
209
|
+
#
|
210
|
+
# platform method to return the text for a span
|
211
|
+
# See PageObject::Accessors#span
|
212
|
+
#
|
213
|
+
def span_text_for(identifier)
|
214
|
+
identifier = Elements::Span.watir_identifier_for identifier
|
215
|
+
@browser.span(identifier).text
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# platform method to return a PageObject::Elements::Span element
|
220
|
+
# See PageObject::Accessors#span
|
221
|
+
#
|
222
|
+
def span_for(identifier)
|
223
|
+
identifier = Elements::Span.watir_identifier_for identifier
|
224
|
+
element = @browser.span(identifier)
|
225
|
+
PageObject::Elements::Span.new(element, :platform => :watir)
|
226
|
+
end
|
227
|
+
|
209
228
|
#
|
210
229
|
# platform method to click a button
|
211
230
|
# See PageObject::Accessors#button
|
@@ -253,5 +272,15 @@ module PageObject
|
|
253
272
|
element = @browser.td(identifier)
|
254
273
|
PageObject::Elements::TableCell.new(element, :platform => :watir)
|
255
274
|
end
|
275
|
+
|
276
|
+
#
|
277
|
+
# platform method to retrieve an image element
|
278
|
+
# See PageObject::Accessors#image
|
279
|
+
#
|
280
|
+
def image_for(identifier)
|
281
|
+
identifier = Elements::Image.watir_identifier_for identifier
|
282
|
+
element = @browser.image(identifier)
|
283
|
+
PageObject::Elements::Image.new(element, :platform => :watir)
|
284
|
+
end
|
256
285
|
end
|
257
286
|
end
|
data/page-object.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency 'watir-webdriver', '>= 0.2.
|
23
|
-
s.add_dependency 'selenium-webdriver', '>= 0.2.
|
22
|
+
s.add_dependency 'watir-webdriver', '>= 0.2.4'
|
23
|
+
s.add_dependency 'selenium-webdriver', '>= 0.2.1'
|
24
24
|
|
25
25
|
s.add_development_dependency 'rspec', '>= 2.5.0'
|
26
26
|
s.add_development_dependency 'cucumber', '>= 0.10.2'
|