page-object 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/.gitignore +1 -0
  2. data/.rvmrc +1 -1
  3. data/ChangeLog +12 -6
  4. data/README.md +1 -1
  5. data/Rakefile +3 -19
  6. data/features/async.feature +8 -8
  7. data/features/button.feature +7 -7
  8. data/features/check_box.feature +8 -8
  9. data/features/div.feature +7 -6
  10. data/features/element_attributes.feature +14 -14
  11. data/features/form.feature +5 -5
  12. data/features/frames.feature +12 -0
  13. data/features/hidden_field.feature +5 -5
  14. data/features/html/frame_1.html +18 -0
  15. data/features/html/frame_2.html +16 -0
  16. data/features/html/frames.html +11 -0
  17. data/features/html/iframes.html +12 -0
  18. data/features/html/static_elements.html +50 -42
  19. data/features/html/success.html +5 -5
  20. data/features/image.feature +11 -11
  21. data/features/link.feature +1 -1
  22. data/features/list_item.feature +5 -5
  23. data/features/ordered_list.feature +6 -6
  24. data/features/page_level_actions.feature +16 -5
  25. data/features/radio_button.feature +12 -12
  26. data/features/select_list.feature +12 -12
  27. data/features/span.feature +5 -5
  28. data/features/step_definitions/accessor_steps.rb +2 -2
  29. data/features/step_definitions/async_steps.rb +1 -1
  30. data/features/step_definitions/element_steps.rb +1 -1
  31. data/features/step_definitions/frames_steps.rb +21 -0
  32. data/features/step_definitions/page_level_actions_steps.rb +24 -2
  33. data/features/step_definitions/page_traversal_steps.rb +0 -1
  34. data/features/support/env.rb +20 -6
  35. data/features/support/page.rb +14 -11
  36. data/features/support/url_helper.rb +4 -0
  37. data/features/table.feature +9 -9
  38. data/features/table_cell.feature +6 -6
  39. data/features/text_area.feature +6 -6
  40. data/features/text_field.feature +7 -7
  41. data/features/unordered_list.feature +6 -6
  42. data/lib/page-object.rb +40 -16
  43. data/lib/page-object/accessors.rb +15 -15
  44. data/lib/page-object/elements.rb +0 -1
  45. data/lib/page-object/elements/button.rb +24 -24
  46. data/lib/page-object/elements/div.rb +8 -3
  47. data/lib/page-object/elements/element.rb +27 -28
  48. data/lib/page-object/elements/form.rb +7 -7
  49. data/lib/page-object/elements/hidden_field.rb +5 -5
  50. data/lib/page-object/elements/image.rb +8 -8
  51. data/lib/page-object/elements/link.rb +9 -9
  52. data/lib/page-object/elements/list_item.rb +1 -1
  53. data/lib/page-object/elements/option.rb +1 -1
  54. data/lib/page-object/elements/ordered_list.rb +13 -13
  55. data/lib/page-object/elements/select_list.rb +6 -6
  56. data/lib/page-object/elements/span.rb +2 -2
  57. data/lib/page-object/elements/table.rb +11 -11
  58. data/lib/page-object/elements/table_row.rb +9 -9
  59. data/lib/page-object/elements/text_area.rb +4 -4
  60. data/lib/page-object/elements/text_field.rb +4 -4
  61. data/lib/page-object/elements/unordered_list.rb +13 -13
  62. data/lib/page-object/loads_platform.rb +24 -0
  63. data/lib/page-object/page_factory.rb +3 -3
  64. data/lib/page-object/platforms.rb +18 -0
  65. data/lib/page-object/platforms/selenium.rb +16 -0
  66. data/lib/page-object/platforms/selenium/button.rb +15 -0
  67. data/lib/page-object/platforms/selenium/element.rb +168 -0
  68. data/lib/page-object/platforms/selenium/form.rb +16 -0
  69. data/lib/page-object/platforms/selenium/image.rb +28 -0
  70. data/lib/page-object/platforms/selenium/link.rb +16 -0
  71. data/lib/page-object/platforms/selenium/ordered_list.rb +33 -0
  72. data/lib/page-object/platforms/selenium/page_object.rb +524 -0
  73. data/lib/page-object/platforms/selenium/select_list.rb +32 -0
  74. data/lib/page-object/platforms/selenium/table.rb +40 -0
  75. data/lib/page-object/platforms/selenium/table_row.rb +32 -0
  76. data/lib/page-object/platforms/selenium/unordered_list.rb +33 -0
  77. data/lib/page-object/platforms/watir.rb +16 -0
  78. data/lib/page-object/platforms/watir/element.rb +154 -0
  79. data/lib/page-object/platforms/watir/form.rb +16 -0
  80. data/lib/page-object/platforms/watir/image.rb +22 -0
  81. data/lib/page-object/platforms/watir/ordered_list.rb +32 -0
  82. data/lib/page-object/{watir_page_object.rb → platforms/watir/page_object.rb} +62 -35
  83. data/lib/page-object/platforms/watir/select_list.rb +33 -0
  84. data/lib/page-object/platforms/watir/table.rb +27 -0
  85. data/lib/page-object/platforms/watir/table_row.rb +24 -0
  86. data/lib/page-object/platforms/watir/unordered_list.rb +33 -0
  87. data/lib/page-object/version.rb +1 -1
  88. data/page-object.gemspec +13 -13
  89. data/spec/page-object/accessors_spec.rb +142 -108
  90. data/spec/page-object/elements/button_spec.rb +33 -33
  91. data/spec/page-object/elements/check_box_spec.rb +1 -1
  92. data/spec/page-object/elements/div_spec.rb +3 -3
  93. data/spec/page-object/elements/element_spec.rb +51 -41
  94. data/spec/page-object/elements/form_spec.rb +3 -3
  95. data/spec/page-object/elements/hidden_field_spec.rb +3 -3
  96. data/spec/page-object/elements/image_spec.rb +7 -7
  97. data/spec/page-object/elements/link_spec.rb +8 -8
  98. data/spec/page-object/elements/list_item_spec.rb +1 -1
  99. data/spec/page-object/elements/ordered_list_spec.rb +9 -9
  100. data/spec/page-object/elements/radio_button_spec.rb +1 -1
  101. data/spec/page-object/elements/select_list_spec.rb +2 -2
  102. data/spec/page-object/elements/span_spec.rb +1 -1
  103. data/spec/page-object/elements/table_row_spec.rb +6 -6
  104. data/spec/page-object/elements/table_spec.rb +9 -9
  105. data/spec/page-object/elements/text_area_spec.rb +3 -3
  106. data/spec/page-object/elements/text_field_spec.rb +3 -3
  107. data/spec/page-object/elements/unordered_list_spec.rb +10 -10
  108. data/spec/page-object/loads_platform_spec.rb +38 -0
  109. data/spec/page-object/page-object_spec.rb +70 -10
  110. data/spec/page-object/page_factory_spec.rb +3 -3
  111. data/spec/page-object/{selenium_page_object_spec.rb → platforms/selenium/selenium_page_object_spec.rb} +10 -3
  112. data/spec/page-object/platforms/selenium_spec.rb +26 -0
  113. data/spec/page-object/platforms/watir_spec.rb +27 -0
  114. data/spec/spec_helper.rb +18 -5
  115. metadata +48 -26
  116. data/lib/page-object/platforms/selenium_button.rb +0 -13
  117. data/lib/page-object/platforms/selenium_element.rb +0 -142
  118. data/lib/page-object/platforms/selenium_form.rb +0 -14
  119. data/lib/page-object/platforms/selenium_image.rb +0 -26
  120. data/lib/page-object/platforms/selenium_link.rb +0 -13
  121. data/lib/page-object/platforms/selenium_ordered_list.rb +0 -31
  122. data/lib/page-object/platforms/selenium_select_list.rb +0 -29
  123. data/lib/page-object/platforms/selenium_table.rb +0 -38
  124. data/lib/page-object/platforms/selenium_table_row.rb +0 -29
  125. data/lib/page-object/platforms/selenium_unordered_list.rb +0 -31
  126. data/lib/page-object/platforms/watir_element.rb +0 -136
  127. data/lib/page-object/platforms/watir_form.rb +0 -14
  128. data/lib/page-object/platforms/watir_image.rb +0 -20
  129. data/lib/page-object/platforms/watir_ordered_list.rb +0 -30
  130. data/lib/page-object/platforms/watir_select_list.rb +0 -30
  131. data/lib/page-object/platforms/watir_table.rb +0 -24
  132. data/lib/page-object/platforms/watir_table_row.rb +0 -22
  133. data/lib/page-object/platforms/watir_unordered_list.rb +0 -31
  134. data/lib/page-object/selenium_page_object.rb +0 -486
@@ -1,4 +1,3 @@
1
-
2
1
  module PageObject
3
2
  #
4
3
  # Contains the class level methods that are inserted into your page objects
@@ -9,7 +8,7 @@ module PageObject
9
8
  # @see PageObject::SeleniumPageObject for the selenium implementation of the platform delegate
10
9
  #
11
10
  module Accessors
12
-
11
+
13
12
  #
14
13
  # Specify the url for the page. A call to this method will generate a
15
14
  # 'goto' method to take you to the page.
@@ -21,7 +20,7 @@ module PageObject
21
20
  platform.navigate_to url
22
21
  end
23
22
  end
24
-
23
+
25
24
  #
26
25
  # adds three methods to the page object - one to set text in a text field,
27
26
  # another to retrieve text from a text field and another to return the text
@@ -56,7 +55,7 @@ module PageObject
56
55
  block ? block.call(browser) : platform.text_field_for(identifier.clone)
57
56
  end
58
57
  end
59
-
58
+
60
59
  #
61
60
  # adds two methods to the page object - one to get the text from a hidden field
62
61
  # and another to retrieve the hidden field element.
@@ -86,7 +85,7 @@ module PageObject
86
85
  block ? block.call(browser) : platform.hidden_field_for(identifier.clone)
87
86
  end
88
87
  end
89
-
88
+
90
89
  #
91
90
  # adds three methods to the page object - one to set text in a text area,
92
91
  # another to retrieve text from a text area and another to return the text
@@ -184,7 +183,7 @@ module PageObject
184
183
  block ? block.call(browser) : platform.link_for(identifier.clone)
185
184
  end
186
185
  end
187
-
186
+
188
187
  #
189
188
  # adds four methods - one to check, another to uncheck, another
190
189
  # to return the state of a checkbox, and a final method to return
@@ -218,7 +217,7 @@ module PageObject
218
217
  block ? block.call(browser) : platform.checkbox_for(identifier.clone)
219
218
  end
220
219
  end
221
-
220
+
222
221
  #
223
222
  # adds four methods - one to select, another to clear,
224
223
  # another to return if a radio button is selected, and
@@ -246,7 +245,7 @@ module PageObject
246
245
  define_method("clear_#{name}") do
247
246
  platform.clear_radio(identifier.clone)
248
247
  end
249
- define_method("#{name}_selected?") do
248
+ define_method("#{name}_selected?") do
250
249
  platform.radio_selected?(identifier.clone)
251
250
  end
252
251
  define_method("#{name}_radio_button") do
@@ -281,7 +280,7 @@ module PageObject
281
280
  block ? block.call(browser) : platform.button_for(identifier.clone)
282
281
  end
283
282
  end
284
-
283
+
285
284
  #
286
285
  # adds two methods - one to retrieve the text from a div
287
286
  # and another to return the div element
@@ -297,6 +296,7 @@ module PageObject
297
296
  # * :id => Watir and Selenium
298
297
  # * :index => Watir and Selenium
299
298
  # * :name => Watir and Selenium
299
+ # * :text => Watir and Selenium
300
300
  # * :xpath => Watir and Selenium
301
301
  # @param optional block to be invoked when element method is called
302
302
  #
@@ -358,7 +358,7 @@ module PageObject
358
358
  block ? block.call(browser) : platform.table_for(identifier.clone)
359
359
  end
360
360
  end
361
-
361
+
362
362
  #
363
363
  # adds two methods one to retrieve the text from a table cell
364
364
  # and another to return the table cell element
@@ -385,7 +385,7 @@ module PageObject
385
385
  block ? block.call(browser) : platform.cell_for(identifier.clone)
386
386
  end
387
387
  end
388
-
388
+
389
389
  #
390
390
  # adds a method to retrieve the image element
391
391
  #
@@ -408,7 +408,7 @@ module PageObject
408
408
  block ? block.call(browser) : platform.image_for(identifier.clone)
409
409
  end
410
410
  end
411
-
411
+
412
412
  #
413
413
  # adds a method to retrieve the form element
414
414
  #
@@ -430,7 +430,7 @@ module PageObject
430
430
  block ? block.call(browser) : platform.form_for(identifier.clone)
431
431
  end
432
432
  end
433
-
433
+
434
434
  #
435
435
  # adds two methods - one to retrieve the text from a list item
436
436
  # and another to return the list item element
@@ -457,7 +457,7 @@ module PageObject
457
457
  block ? block.call(browser) : platform.list_item_for(identifier.clone)
458
458
  end
459
459
  end
460
-
460
+
461
461
  #
462
462
  # adds a method to retrieve the unordered list element
463
463
  #
@@ -480,7 +480,7 @@ module PageObject
480
480
  block ? block.call(browser) : platform.unordered_list_for(identifier.clone)
481
481
  end
482
482
  end
483
-
483
+
484
484
  #
485
485
  # adds a method to retrieve the ordered list element
486
486
  #
@@ -1,4 +1,3 @@
1
-
2
1
  require 'page-object/elements/element'
3
2
  require 'page-object/elements/link'
4
3
  require 'page-object/elements/text_field'
@@ -1,25 +1,25 @@
1
- module PageObject
2
- module Elements
3
- class Button < Element
4
-
5
- def initialize(element, platform)
6
- @element = element
7
- include_platform_for platform
8
- end
9
-
10
- protected
11
-
12
- def self.watir_finders
13
- super + [:text]
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
23
- end
24
- end
1
+ module PageObject
2
+ module Elements
3
+ class Button < Element
4
+
5
+ def initialize(element, platform)
6
+ @element = element
7
+ include_platform_for platform
8
+ end
9
+
10
+ protected
11
+
12
+ def self.watir_finders
13
+ super + [:text]
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::Selenium::Button
21
+ end
22
+ end
23
+ end
24
+ end
25
25
  end
@@ -1,12 +1,17 @@
1
1
  module PageObject
2
2
  module Elements
3
3
  class Div < Element
4
-
4
+
5
5
  protected
6
-
6
+
7
7
  def self.watir_finders
8
- [:class, :id, :index, :xpath]
8
+ [:class, :id, :text, :index, :xpath]
9
+ end
10
+
11
+ def self.selenium_finders
12
+ [:class, :id, :name, :text, :xpath, :index]
9
13
  end
14
+
10
15
  end
11
16
  end
12
17
  end
@@ -1,4 +1,3 @@
1
-
2
1
  module PageObject
3
2
  module Elements
4
3
  #
@@ -9,12 +8,12 @@ module PageObject
9
8
  #
10
9
  class Element
11
10
  attr_reader :element
12
-
11
+
13
12
  def initialize(element, platform)
14
13
  @element = element
15
14
  include_platform_for platform
16
15
  end
17
-
16
+
18
17
  # @private
19
18
  def self.watir_identifier_for identifier
20
19
  if should_build_watir_xpath(identifier)
@@ -30,7 +29,7 @@ module PageObject
30
29
  end
31
30
  all_identities
32
31
  end
33
-
32
+
34
33
  # @private
35
34
  def self.selenium_identifier_for identifier
36
35
  if identifier.length == 1
@@ -44,7 +43,7 @@ module PageObject
44
43
  end
45
44
 
46
45
  protected
47
-
46
+
48
47
  def self.should_build_watir_xpath identifier
49
48
  ['table', 'span', 'div', 'td', 'li', 'ul', 'ol'].include? identifier[:tag_name] and identifier[:name]
50
49
  end
@@ -58,7 +57,7 @@ module PageObject
58
57
  xpath << "[#{idx+1}]" if idx
59
58
  xpath
60
59
  end
61
-
60
+
62
61
  def self.attribute_expression(identifier)
63
62
  identifier.map do |key, value|
64
63
  if value.kind_of?(Array)
@@ -68,7 +67,7 @@ module PageObject
68
67
  end
69
68
  end.join(" and ")
70
69
  end
71
-
70
+
72
71
  def self.equal_pair(key, value)
73
72
  if key == :label
74
73
  "@id=//label[normalize-space()=#{xpath_string(value)}]/@for"
@@ -76,15 +75,15 @@ module PageObject
76
75
  "#{lhs_for(key)}=#{xpath_string(value)}"
77
76
  end
78
77
  end
79
-
78
+
80
79
  def self.lhs_for(key)
81
80
  case key
82
- when :text, 'text'
83
- 'normalize-space()'
84
- when :href
85
- 'normalize-space(@href)'
86
- else
87
- "@#{key.to_s.gsub("_", "-")}"
81
+ when :text, 'text'
82
+ 'normalize-space()'
83
+ when :href
84
+ 'normalize-space(@href)'
85
+ else
86
+ "@#{key.to_s.gsub("_", "-")}"
88
87
  end
89
88
  end
90
89
 
@@ -104,32 +103,32 @@ module PageObject
104
103
  return find_by_mapping[how] => what if find_by_mapping[how]
105
104
  return nil => what
106
105
  end
107
-
106
+
108
107
  def self.watir_finders
109
108
  [:class, :id, :index, :name, :xpath]
110
109
  end
111
-
112
- def self.watir_mapping
113
- {}
110
+
111
+ def self.watir_mapping
112
+ {}
114
113
  end
115
-
114
+
116
115
  def self.selenium_finders
117
116
  [:class, :id, :name, :xpath, :index]
118
117
  end
119
-
120
- def self.selenium_mapping
121
- {}
118
+
119
+ def self.selenium_mapping
120
+ {}
122
121
  end
123
-
122
+
124
123
  def include_platform_for platform
125
124
  if platform[:platform] == :watir
126
- require 'page-object/platforms/watir_element'
127
- self.class.send :include, PageObject::Platforms::WatirElement
125
+ require 'page-object/platforms/watir/element'
126
+ self.class.send :include, PageObject::Platforms::Watir::Element
128
127
  elsif platform[:platform] == :selenium
129
- require 'page-object/platforms/selenium_element'
130
- self.class.send :include, PageObject::Platforms::SeleniumElement
128
+ require 'page-object/platforms/selenium/element'
129
+ self.class.send :include, PageObject::Platforms::Selenium::Element
131
130
  else
132
- raise ArgumentError, "expect platform to be :watir or :selenium"
131
+ raise ArgumentError, "expect platform to be :watir or :selenium"
133
132
  end
134
133
  end
135
134
  end
@@ -5,19 +5,19 @@ module PageObject
5
5
  @element = element
6
6
  include_platform_for platform
7
7
  end
8
-
8
+
9
9
  protected
10
-
10
+
11
11
  def include_platform_for platform
12
12
  super
13
13
  if platform[:platform] == :watir
14
- require 'page-object/platforms/watir_form'
15
- self.class.send :include, PageObject::Platforms::WatirForm
14
+ require 'page-object/platforms/watir/form'
15
+ self.class.send :include, PageObject::Platforms::Watir::Form
16
16
  elsif platform[:platform] == :selenium
17
- require 'page-object/platforms/selenium_form'
18
- self.class.send :include, PageObject::Platforms::SeleniumForm
17
+ require 'page-object/platforms/selenium/form'
18
+ self.class.send :include, PageObject::Platforms::Selenium::Form
19
19
  else
20
- raise ArgumentError, "expect platform to be :watir or :selenium"
20
+ raise ArgumentError, "expect platform to be :watir or :selenium"
21
21
  end
22
22
  end
23
23
  end
@@ -1,25 +1,25 @@
1
1
  module PageObject
2
2
  module Elements
3
3
  class HiddenField < Element
4
-
4
+
5
5
  def click
6
6
  raise "click is not available on hidden field element with Selenium or Watir"
7
7
  end
8
8
 
9
9
  protected
10
-
10
+
11
11
  def self.watir_finders
12
12
  super + [:tag_name, :text]
13
13
  end
14
-
14
+
15
15
  def self.watir_mapping
16
16
  super.merge({:css => :tag_name})
17
17
  end
18
-
18
+
19
19
  def self.selenium_finders
20
20
  super + [:css]
21
21
  end
22
-
22
+
23
23
  def self.selenium_mapping
24
24
  super.merge({:tag_name => :css})
25
25
  end
@@ -5,22 +5,22 @@ module PageObject
5
5
  @element = element
6
6
  include_platform_for platform
7
7
  end
8
-
8
+
9
9
  protected
10
-
10
+
11
11
  def include_platform_for platform
12
12
  super
13
13
  if platform[:platform] == :watir
14
- require 'page-object/platforms/watir_image'
15
- self.class.send :include, PageObject::Platforms::WatirImage
14
+ require 'page-object/platforms/watir/image'
15
+ self.class.send :include, PageObject::Platforms::Watir::Image
16
16
  elsif platform[:platform] == :selenium
17
- require 'page-object/platforms/selenium_image'
18
- self.class.send :include, PageObject::Platforms::SeleniumImage
17
+ require 'page-object/platforms/selenium/image'
18
+ self.class.send :include, PageObject::Platforms::Selenium::Image
19
19
  else
20
- raise ArgumentError, "expect platform to be :watir or :selenium"
20
+ raise ArgumentError, "expect platform to be :watir or :selenium"
21
21
  end
22
22
  end
23
-
23
+
24
24
  end
25
25
  end
26
26
  end
@@ -1,26 +1,26 @@
1
1
  module PageObject
2
2
  module Elements
3
3
  class Link < Element
4
-
4
+
5
5
  def initialize(element, platform)
6
6
  @element = element
7
7
  include_platform_for platform
8
8
  end
9
-
9
+
10
10
  protected
11
-
11
+
12
12
  def self.watir_finders
13
13
  super + [:href, :text]
14
14
  end
15
-
15
+
16
16
  def self.watir_mapping
17
- super.merge({ :link => :text, :link_text => :text })
17
+ super.merge({:link => :text, :link_text => :text})
18
18
  end
19
-
19
+
20
20
  def self.selenium_finders
21
21
  super + [:link, :link_text]
22
22
  end
23
-
23
+
24
24
  def self.selenium_mapping
25
25
  super.merge(:text => :link_text)
26
26
  end
@@ -28,8 +28,8 @@ module PageObject
28
28
  def include_platform_for platform
29
29
  super
30
30
  if platform[:platform] == :selenium
31
- require 'page-object/platforms/selenium_link'
32
- self.class.send :include, PageObject::Platforms::SeleniumLink
31
+ require 'page-object/platforms/selenium/link'
32
+ self.class.send :include, PageObject::Platforms::Selenium::Link
33
33
  end
34
34
  end
35
35
  end