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.
Files changed (35) hide show
  1. data/ChangeLog +20 -2
  2. data/features/div.feature +1 -1
  3. data/features/element.feature +160 -0
  4. data/features/html/images/circle.png +0 -0
  5. data/features/html/static_elements.html +8 -0
  6. data/features/image.feature +32 -0
  7. data/features/span.feature +37 -0
  8. data/features/step_definitions/accessor_steps.rb +29 -3
  9. data/features/step_definitions/element_steps.rb +33 -0
  10. data/features/support/page.rb +13 -0
  11. data/lib/page-object/accessors.rb +32 -2
  12. data/lib/page-object/elements.rb +2 -0
  13. data/lib/page-object/elements/button.rb +13 -0
  14. data/lib/page-object/elements/element.rb +1 -0
  15. data/lib/page-object/elements/image.rb +26 -0
  16. data/lib/page-object/elements/link.rb +11 -0
  17. data/lib/page-object/elements/span.rb +12 -0
  18. data/lib/page-object/platforms/selenium_button.rb +13 -0
  19. data/lib/page-object/platforms/selenium_element.rb +63 -1
  20. data/lib/page-object/platforms/selenium_image.rb +22 -0
  21. data/lib/page-object/platforms/selenium_link.rb +13 -0
  22. data/lib/page-object/platforms/selenium_table.rb +1 -1
  23. data/lib/page-object/platforms/watir_element.rb +63 -1
  24. data/lib/page-object/platforms/watir_image.rb +20 -0
  25. data/lib/page-object/selenium_page_object.rb +29 -0
  26. data/lib/page-object/version.rb +1 -1
  27. data/lib/page-object/watir_page_object.rb +29 -0
  28. data/page-object.gemspec +2 -2
  29. data/spec/page-object/accessors_spec.rb +64 -0
  30. data/spec/page-object/elements/button_spec.rb +11 -0
  31. data/spec/page-object/elements/element_spec.rb +50 -0
  32. data/spec/page-object/elements/image_spec.rb +62 -0
  33. data/spec/page-object/elements/link_spec.rb +11 -0
  34. data/spec/page-object/elements/span_spec.rb +22 -0
  35. metadata +22 -4
@@ -10,3 +10,5 @@ require 'page-object/elements/div'
10
10
  require 'page-object/elements/table'
11
11
  require 'page-object/elements/table_cell'
12
12
  require 'page-object/elements/table_row'
13
+ require 'page-object/elements/span'
14
+ require 'page-object/elements/image'
@@ -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
@@ -6,6 +6,7 @@ module PageObject
6
6
  # Contains functionality that is common across all elements.
7
7
  #
8
8
  class Element
9
+ attr_reader :element
9
10
 
10
11
  def initialize(element, platform)
11
12
  @element = element
@@ -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,12 @@
1
+ module PageObject
2
+ module Elements
3
+ class Span < Element
4
+
5
+ protected
6
+
7
+ def self.watir_finders
8
+ [:class, :id, :index, :xpath]
9
+ end
10
+ end
11
+ end
12
+ 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
- # return the text for the element
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
@@ -16,7 +16,7 @@ module PageObject
16
16
  # available on a table element in Selenium.
17
17
  #
18
18
  def exists?
19
- nil
19
+ raise "exists? not available on table element"
20
20
  end
21
21
 
22
22
  end
@@ -18,12 +18,74 @@ module PageObject
18
18
  end
19
19
 
20
20
  #
21
- # return the text for the element
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
@@ -1,3 +1,3 @@
1
1
  module PageObject
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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.3'
23
- s.add_dependency 'selenium-webdriver', '>= 0.2.0'
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'