page-object 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/.gitignore +0 -2
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/ChangeLog +23 -0
  5. data/README.md +2 -0
  6. data/features/button.feature +37 -0
  7. data/features/div.feature +45 -0
  8. data/features/html/static_elements.html +21 -3
  9. data/features/html/success.html +8 -0
  10. data/features/link.feature +1 -4
  11. data/features/step_definitions/accessor_steps.rb +37 -0
  12. data/features/step_definitions/element_steps.rb +18 -0
  13. data/features/step_definitions/table_steps.rb +14 -0
  14. data/features/support/page.rb +26 -1
  15. data/features/table.feature +52 -0
  16. data/features/table_cell.feature +45 -0
  17. data/lib/page-object/accessors.rb +88 -0
  18. data/lib/page-object/elements/button.rb +4 -7
  19. data/lib/page-object/elements/check_box.rb +0 -8
  20. data/lib/page-object/elements/div.rb +12 -0
  21. data/lib/page-object/elements/element.rb +22 -12
  22. data/lib/page-object/elements/link.rb +0 -8
  23. data/lib/page-object/elements/radio_button.rb +0 -8
  24. data/lib/page-object/elements/select_list.rb +0 -9
  25. data/lib/page-object/elements/table.rb +26 -0
  26. data/lib/page-object/elements/table_cell.rb +7 -0
  27. data/lib/page-object/elements/table_row.rb +26 -0
  28. data/lib/page-object/elements/text_field.rb +0 -9
  29. data/lib/page-object/elements.rb +4 -0
  30. data/lib/page-object/platforms/selenium_element.rb +29 -0
  31. data/lib/page-object/platforms/selenium_table.rb +24 -0
  32. data/lib/page-object/platforms/selenium_table_row.rb +16 -0
  33. data/lib/page-object/platforms/watir_element.rb +29 -0
  34. data/lib/page-object/platforms/watir_table.rb +15 -0
  35. data/lib/page-object/platforms/watir_table_row.rb +15 -0
  36. data/lib/page-object/selenium_page_object.rb +68 -1
  37. data/lib/page-object/version.rb +1 -1
  38. data/lib/page-object/watir_page_object.rb +67 -0
  39. data/spec/page-object/accessors_spec.rb +135 -8
  40. data/spec/page-object/elements/div_spec.rb +22 -0
  41. data/spec/page-object/elements/element_spec.rb +10 -1
  42. data/spec/page-object/elements/table_row_spec.rb +25 -0
  43. data/spec/page-object/elements/table_spec.rb +45 -0
  44. metadata +33 -4
  45. data/lib/page-object/selenium_element.rb +0 -12
  46. data/lib/page-object/watir_element.rb +0 -12
@@ -2,13 +2,10 @@ module PageObject
2
2
  module Elements
3
3
  class Button < Element
4
4
 
5
- def self.watir_identifier_for identifier
6
- identifier_for identifier, watir_finders, watir_mapping
7
- end
8
-
9
- def self.selenium_identifier_for identifier
10
- identifier_for identifier, selenium_finders, selenium_mapping
11
- return identifier.keys.first, identifier.values.first
5
+ protected
6
+
7
+ def self.watir_finders
8
+ super + [:text]
12
9
  end
13
10
  end
14
11
  end
@@ -2,14 +2,6 @@ module PageObject
2
2
  module Elements
3
3
  class CheckBox < Element
4
4
 
5
- def self.watir_identifier_for identifier
6
- identifier_for identifier, watir_finders, watir_mapping
7
- end
8
-
9
- def self.selenium_identifier_for identifier
10
- identifier = identifier_for identifier, selenium_finders, selenium_mapping
11
- return identifier.keys.first, identifier.values.first
12
- end
13
5
  end
14
6
  end
15
7
  end
@@ -0,0 +1,12 @@
1
+ module PageObject
2
+ module Elements
3
+ class Div < Element
4
+
5
+ protected
6
+
7
+ def self.watir_finders
8
+ [:class, :id, :index, :xpath]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,4 @@
1
+
1
2
  module PageObject
2
3
  module Elements
3
4
 
@@ -11,6 +12,17 @@ module PageObject
11
12
  include_platform_for platform
12
13
  end
13
14
 
15
+ def self.watir_identifier_for identifier
16
+ identifier_for identifier, watir_finders, watir_mapping
17
+ end
18
+
19
+ def self.selenium_identifier_for identifier
20
+ identifier = identifier_for identifier, selenium_finders, selenium_mapping
21
+ return identifier.keys.first, identifier.values.first
22
+ end
23
+
24
+ protected
25
+
14
26
  def self.identifier_for identifier, find_by, find_by_mapping
15
27
  how, what = identifier.keys.first, identifier.values.first
16
28
  return how => what if find_by.include? how
@@ -18,33 +30,31 @@ module PageObject
18
30
  return nil => what
19
31
  end
20
32
 
21
- protected
22
-
23
33
  def self.watir_finders
24
34
  [:class, :id, :index, :name, :xpath]
25
35
  end
26
36
 
27
- def self.watir_mapping
28
- {}
37
+ def self.watir_mapping
38
+ {}
29
39
  end
30
40
 
31
41
  def self.selenium_finders
32
42
  [:class, :id, :name, :xpath]
33
43
  end
34
44
 
35
- def self.selenium_mapping
36
- {}
45
+ def self.selenium_mapping
46
+ {}
37
47
  end
38
48
 
39
- private
40
-
41
49
  def include_platform_for platform
42
50
  if platform[:platform] == :watir
43
- require 'page-object/watir_element'
44
- self.class.send :include, PageObject::WatirElement
51
+ require 'page-object/platforms/watir_element'
52
+ self.class.send :include, PageObject::Platforms::WatirElement
53
+ elsif platform[:platform] == :selenium
54
+ require 'page-object/platforms/selenium_element'
55
+ self.class.send :include, PageObject::Platforms::SeleniumElement
45
56
  else
46
- require 'page-object/selenium_element'
47
- self.class.send :include, PageObject::SeleniumElement
57
+ raise ArgumentError, "expect platform to be :watir or :selenium"
48
58
  end
49
59
  end
50
60
  end
@@ -2,14 +2,6 @@ module PageObject
2
2
  module Elements
3
3
  class Link < Element
4
4
 
5
- def self.watir_identifier_for identifier
6
- identifier_for identifier, watir_finders, watir_mapping
7
- end
8
-
9
- def self.selenium_identifier_for identifier
10
- identifier = identifier_for identifier, selenium_finders, selenium_mapping
11
- return identifier.keys.first, identifier.values.first
12
- end
13
5
 
14
6
  protected
15
7
 
@@ -2,14 +2,6 @@ module PageObject
2
2
  module Elements
3
3
  class RadioButton < Element
4
4
 
5
- def self.watir_identifier_for identifier
6
- identifier_for identifier, watir_finders, watir_mapping
7
- end
8
-
9
- def self.selenium_identifier_for identifier
10
- identifier = identifier_for identifier, selenium_finders, selenium_mapping
11
- return identifier.keys.first, identifier.values.first
12
- end
13
5
  end
14
6
  end
15
7
  end
@@ -2,15 +2,6 @@ module PageObject
2
2
  module Elements
3
3
  class SelectList < Element
4
4
 
5
- def self.watir_identifier_for identifier
6
- identifier_for identifier, watir_finders, watir_mapping
7
- end
8
-
9
- def self.selenium_identifier_for identifier
10
- identifier = identifier_for identifier, selenium_finders, selenium_mapping
11
- return identifier.keys.first, identifier.values.first
12
- end
13
-
14
5
  protected
15
6
 
16
7
  def self.watir_finders
@@ -0,0 +1,26 @@
1
+ module PageObject
2
+ module Elements
3
+ class Table < Element
4
+
5
+ def initialize(element, platform)
6
+ @element = element
7
+ include_platform_for platform
8
+ end
9
+
10
+ protected
11
+
12
+ def include_platform_for platform
13
+ super
14
+ if platform[:platform] == :watir
15
+ require 'page-object/platforms/watir_table'
16
+ self.class.send :include, PageObject::Platforms::WatirTable
17
+ elsif platform[:platform] == :selenium
18
+ require 'page-object/platforms/selenium_table'
19
+ self.class.send :include, PageObject::Platforms::SeleniumTable
20
+ else
21
+ raise ArgumentError, "expect platform to be :watir or :selenium"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module PageObject
2
+ module Elements
3
+ class TableCell < Element
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module PageObject
2
+ module Elements
3
+ class TableRow < Element
4
+
5
+ def initialize(element, platform)
6
+ @element = element
7
+ include_platform_for platform
8
+ end
9
+
10
+ protected
11
+
12
+ def include_platform_for platform
13
+ super
14
+ if platform[:platform] == :watir
15
+ require 'page-object/platforms/watir_table_row'
16
+ self.class.send :include, PageObject::Platforms::WatirTableRow
17
+ elsif platform[:platform] == :selenium
18
+ require 'page-object/platforms/selenium_table_row'
19
+ self.class.send :include, PageObject::Platforms::SeleniumTableRow
20
+ else
21
+ raise ArgumentError, "expect platform to be :watir or :selenium"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,15 +2,6 @@ module PageObject
2
2
  module Elements
3
3
  class TextField < Element
4
4
 
5
- def self.watir_identifier_for identifier
6
- identifier_for identifier, watir_finders, watir_mapping
7
- end
8
-
9
- def self.selenium_identifier_for identifier
10
- identifier = identifier_for identifier, selenium_finders, selenium_mapping
11
- return identifier.keys.first, identifier.values.first
12
- end
13
-
14
5
  protected
15
6
 
16
7
  def self.watir_finders
@@ -6,3 +6,7 @@ require 'page-object/elements/select_list'
6
6
  require 'page-object/elements/check_box'
7
7
  require 'page-object/elements/button'
8
8
  require 'page-object/elements/radio_button'
9
+ require 'page-object/elements/div'
10
+ require 'page-object/elements/table'
11
+ require 'page-object/elements/table_cell'
12
+ require 'page-object/elements/table_row'
@@ -0,0 +1,29 @@
1
+
2
+ module PageObject
3
+ module Platforms
4
+ module SeleniumElement
5
+
6
+ #
7
+ # return true if an element is visible
8
+ #
9
+ def visible?
10
+ @element.displayed?
11
+ end
12
+
13
+ #
14
+ # return true if an element exists
15
+ #
16
+ def exists?
17
+ nil != @element
18
+ end
19
+
20
+ #
21
+ # return the text for the element
22
+ #
23
+ def text
24
+ @element.text
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ module PageObject
2
+ module Platforms
3
+ module SeleniumTable
4
+
5
+ #
6
+ # Return the PageObject::Elements::TableRow for the index provided. Index
7
+ # is zero based.
8
+ #
9
+ def [](idx)
10
+ element = @element.find_element(:xpath, ".//tr[#{idx+1}]")
11
+ PageObject::Elements::TableRow.new(element, :platform => :selenium)
12
+ end
13
+
14
+ #
15
+ # override PageObject::Platforms::SeleniumElement because exists? is not
16
+ # available on a table element in Selenium.
17
+ #
18
+ def exists?
19
+ nil
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module PageObject
2
+ module Platforms
3
+ module SeleniumTableRow
4
+
5
+ #
6
+ # Return the PageObject::Elements::TableCell for the index provided. Index
7
+ # is zero based.
8
+ #
9
+ def [](idx)
10
+ element = @element.find_element(:xpath, "./th|td[#{idx+1}]")
11
+ PageObject::Elements::TableCell.new(element, :platform => :selenium)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module PageObject
3
+ module Platforms
4
+ module WatirElement
5
+
6
+ #
7
+ # return true if an element is visible
8
+ #
9
+ def visible?
10
+ @element.present?
11
+ end
12
+
13
+ #
14
+ # return true if an element exists
15
+ #
16
+ def exists?
17
+ @element.exists?
18
+ end
19
+
20
+ #
21
+ # return the text for the element
22
+ #
23
+ def text
24
+ @element.text
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module PageObject
2
+ module Platforms
3
+ module WatirTable
4
+
5
+ #
6
+ # Return the PageObject::Elements::TableRow for the index provided. Index
7
+ # is zero based.
8
+ #
9
+ def [](idx)
10
+ PageObject::Elements::TableRow.new(@element[idx], :platform => :watir)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module PageObject
2
+ module Platforms
3
+ module WatirTableRow
4
+
5
+ #
6
+ # Return the PageObject::Elements::TableCell for the index provided. Index
7
+ # is zero based.
8
+ #
9
+ def [](idx)
10
+ PageObject::Elements::TableCell.new(@element[idx], :platform => :watir)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -44,7 +44,7 @@ module PageObject
44
44
  #
45
45
  def text_field_value_for(identifier)
46
46
  how, what = Elements::TextField.selenium_identifier_for identifier
47
- @browser.find_element(how, what).value
47
+ @browser.find_element(how, what).attribute('value')
48
48
  end
49
49
 
50
50
  #
@@ -186,5 +186,72 @@ module PageObject
186
186
  element = @browser.find_element(how, what)
187
187
  PageObject::Elements::RadioButton.new(element, :platform => :selenium)
188
188
  end
189
+
190
+ #
191
+ # platform method to return the text for a div
192
+ # See PageObject::Accessors#div
193
+ #
194
+ def div_text_for(identifier)
195
+ how, what = Elements::Div.selenium_identifier_for identifier
196
+ @browser.find_element(how, what).text
197
+ end
198
+
199
+ #
200
+ # platform method to return a PageObject::Elements::Div element
201
+ # See PageObject::Accessors#div
202
+ #
203
+ def div_for(identifier)
204
+ how, what = Elements::Div.selenium_identifier_for identifier
205
+ element = @browser.find_element(how, what)
206
+ PageObject::Elements::Div.new(element, :platform => :selenium)
207
+ end
208
+
209
+ #
210
+ # platform method to click a button
211
+ # See PageObject::Accessors#button
212
+ #
213
+ def click_button_for(identifier)
214
+ how, what = Elements::Button.selenium_identifier_for identifier
215
+ @browser.find_element(how, what).click
216
+ end
217
+
218
+ #
219
+ # platform method to retrieve a button element
220
+ # See PageObject::Accessors#button
221
+ #
222
+ def button_for(identifier)
223
+ how, what = Elements::Button.selenium_identifier_for identifier
224
+ element = @browser.find_element(how, what)
225
+ PageObject::Elements::Button.new(element, :platform => :selenium)
226
+ end
227
+
228
+ #
229
+ # platform method to retrieve a table element
230
+ # See PageObject::Accessors#table
231
+ #
232
+ def table_for(identifier)
233
+ how, what = Elements::Table.selenium_identifier_for identifier
234
+ element = @browser.find_element(how, what)
235
+ PageObject::Elements::Table.new(element, :platform => :selenium)
236
+ end
237
+
238
+ #
239
+ # platform method to retrieve the text from a table cell
240
+ # See PageObject::Accessors#cell
241
+ #
242
+ def cell_text_for(identifier)
243
+ how, what = Elements::TableCell.selenium_identifier_for identifier
244
+ @browser.find_element(how, what).text
245
+ end
246
+
247
+ #
248
+ # platform method to retrieve a table cell element
249
+ # See PageObject::Accessors#cell
250
+ #
251
+ def cell_for(identifier)
252
+ how, what = Elements::TableCell.selenium_identifier_for identifier
253
+ element = @browser.find_element(how, what)
254
+ PageObject::Elements::TableCell.new(element, :platform => :selenium)
255
+ end
189
256
  end
190
257
  end