page-object 2.0.0 → 2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/ChangeLog +10 -0
  4. data/README.md +12 -0
  5. data/Rakefile +2 -12
  6. data/cucumber.yml +2 -4
  7. data/lib/page-object.rb +12 -20
  8. data/lib/page-object/accessors.rb +50 -363
  9. data/lib/page-object/elements/bold.rb +0 -1
  10. data/lib/page-object/elements/button.rb +0 -4
  11. data/lib/page-object/elements/check_box.rb +19 -7
  12. data/lib/page-object/elements/div.rb +0 -4
  13. data/lib/page-object/elements/element.rb +159 -90
  14. data/lib/page-object/elements/file_field.rb +5 -7
  15. data/lib/page-object/elements/form.rb +0 -8
  16. data/lib/page-object/elements/hidden_field.rb +1 -4
  17. data/lib/page-object/elements/image.rb +13 -7
  18. data/lib/page-object/elements/label.rb +0 -4
  19. data/lib/page-object/elements/link.rb +0 -13
  20. data/lib/page-object/elements/list_item.rb +0 -3
  21. data/lib/page-object/elements/ordered_list.rb +30 -5
  22. data/lib/page-object/elements/radio_button.rb +12 -7
  23. data/lib/page-object/elements/select_list.rb +40 -8
  24. data/lib/page-object/elements/span.rb +0 -3
  25. data/lib/page-object/elements/table.rb +26 -5
  26. data/lib/page-object/elements/table_cell.rb +0 -4
  27. data/lib/page-object/elements/table_row.rb +30 -5
  28. data/lib/page-object/elements/text_area.rb +7 -7
  29. data/lib/page-object/elements/text_field.rb +5 -11
  30. data/lib/page-object/elements/unordered_list.rb +30 -5
  31. data/lib/page-object/indexed_properties.rb +1 -0
  32. data/lib/page-object/platforms.rb +0 -1
  33. data/lib/page-object/platforms/watir.rb +26 -4
  34. data/lib/page-object/platforms/watir/page_object.rb +4 -4
  35. data/lib/page-object/version.rb +1 -1
  36. data/lib/page-object/widgets.rb +0 -1
  37. data/page-object.gemspec +1 -15
  38. metadata +5 -47
  39. data/lib/page-object/platforms/selenium_webdriver.rb +0 -30
  40. data/lib/page-object/platforms/selenium_webdriver/button.rb +0 -15
  41. data/lib/page-object/platforms/selenium_webdriver/check_box.rb +0 -29
  42. data/lib/page-object/platforms/selenium_webdriver/element.rb +0 -335
  43. data/lib/page-object/platforms/selenium_webdriver/file_field.rb +0 -16
  44. data/lib/page-object/platforms/selenium_webdriver/form.rb +0 -16
  45. data/lib/page-object/platforms/selenium_webdriver/image.rb +0 -28
  46. data/lib/page-object/platforms/selenium_webdriver/link.rb +0 -23
  47. data/lib/page-object/platforms/selenium_webdriver/ordered_list.rb +0 -41
  48. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +0 -1297
  49. data/lib/page-object/platforms/selenium_webdriver/radio_button.rb +0 -22
  50. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +0 -93
  51. data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +0 -42
  52. data/lib/page-object/platforms/selenium_webdriver/table.rb +0 -42
  53. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +0 -43
  54. data/lib/page-object/platforms/selenium_webdriver/text_area.rb +0 -17
  55. data/lib/page-object/platforms/selenium_webdriver/text_field.rb +0 -17
  56. data/lib/page-object/platforms/selenium_webdriver/unordered_list.rb +0 -37
  57. data/lib/page-object/platforms/watir/check_box.rb +0 -29
  58. data/lib/page-object/platforms/watir/element.rb +0 -295
  59. data/lib/page-object/platforms/watir/file_field.rb +0 -16
  60. data/lib/page-object/platforms/watir/form.rb +0 -16
  61. data/lib/page-object/platforms/watir/image.rb +0 -22
  62. data/lib/page-object/platforms/watir/link.rb +0 -15
  63. data/lib/page-object/platforms/watir/ordered_list.rb +0 -40
  64. data/lib/page-object/platforms/watir/radio_button.rb +0 -22
  65. data/lib/page-object/platforms/watir/select_list.rb +0 -74
  66. data/lib/page-object/platforms/watir/table.rb +0 -38
  67. data/lib/page-object/platforms/watir/table_row.rb +0 -37
  68. data/lib/page-object/platforms/watir/text_area.rb +0 -23
  69. data/lib/page-object/platforms/watir/text_field.rb +0 -16
  70. data/lib/page-object/platforms/watir/unordered_list.rb +0 -42
@@ -1,9 +1,19 @@
1
1
  module PageObject
2
2
  module Elements
3
3
  class Image < Element
4
- def initialize(element, platform)
5
- @element = element
6
- include_platform_for platform
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
7
17
  end
8
18
 
9
19
  protected
@@ -12,10 +22,6 @@ module PageObject
12
22
  super + [:alt, :src]
13
23
  end
14
24
 
15
- def self.selenium_finders
16
- super + [:alt, :src, :css]
17
- end
18
-
19
25
  end
20
26
 
21
27
  ::PageObject::Elements.tag_to_class[:img] = ::PageObject::Elements::Image
@@ -8,10 +8,6 @@ module PageObject
8
8
  super + [:text]
9
9
  end
10
10
 
11
- def self.selenium_finders
12
- super + [:text]
13
- end
14
-
15
11
  end
16
12
 
17
13
  ::PageObject::Elements.tag_to_class[:label] = ::PageObject::Elements::Label
@@ -3,11 +3,6 @@ module PageObject
3
3
  module Elements
4
4
  class Link < Element
5
5
 
6
- def initialize(element, platform)
7
- @element = element
8
- include_platform_for platform
9
- end
10
-
11
6
  protected
12
7
 
13
8
  def self.watir_finders
@@ -18,14 +13,6 @@ module PageObject
18
13
  super.merge({:link => :text, :link_text => :text})
19
14
  end
20
15
 
21
- def self.selenium_finders
22
- super + [:link, :link_text, :title]
23
- end
24
-
25
- def self.selenium_mapping
26
- super.merge(:text => :link_text)
27
- end
28
-
29
16
  end
30
17
 
31
18
  ::PageObject::Elements.tag_to_class[:a] = ::PageObject::Elements::Link
@@ -8,9 +8,6 @@ module PageObject
8
8
  super + [:text]
9
9
  end
10
10
 
11
- def self.selenium_finders
12
- super + [:text]
13
- end
14
11
  end
15
12
 
16
13
  ::PageObject::Elements.tag_to_class[:li] = ::PageObject::Elements::ListItem
@@ -4,11 +4,6 @@ module PageObject
4
4
  class OrderedList < Element
5
5
  include Enumerable
6
6
 
7
- def initialize(element, platform)
8
- @element = element
9
- include_platform_for platform
10
- end
11
-
12
7
  #
13
8
  # iterator that yields with a PageObject::Elements::ListItem
14
9
  #
@@ -20,8 +15,38 @@ module PageObject
20
15
  end
21
16
  end
22
17
 
18
+ #
19
+ # Return the PageObject::Elements::ListItem for the index provided. Index
20
+ # is zero based.
21
+ #
22
+ # @return [PageObject::Elements::ListItem]
23
+ #
24
+ def [](idx)
25
+ Object::PageObject::Elements::ListItem.new(children[idx], :platform => :watir)
26
+ end
27
+
28
+ #
29
+ # Return the number of items contained in the ordered list
30
+ #
31
+ def items
32
+ children.size
33
+ end
34
+
35
+ #
36
+ # Return the ListItem objects that are children of the OrderedList
37
+ #
38
+ def list_items
39
+ children.collect do |obj|
40
+ Object::PageObject::Elements::ListItem.new(obj, :platform => :watir)
41
+ end
42
+ end
43
+
23
44
  protected
24
45
 
46
+ def children
47
+ element.ols(:xpath => child_xpath)
48
+ end
49
+
25
50
  def child_xpath
26
51
  "./child::li"
27
52
  end
@@ -3,9 +3,18 @@ module PageObject
3
3
  module Elements
4
4
  class RadioButton < Element
5
5
 
6
- def initialize(element, platform)
7
- @element = element
8
- include_platform_for platform
6
+ #
7
+ # select the radiobutton
8
+ #
9
+ def select
10
+ element.set
11
+ end
12
+
13
+ #
14
+ # return if it is selected
15
+ #
16
+ def selected?
17
+ element.set?
9
18
  end
10
19
 
11
20
  protected
@@ -14,10 +23,6 @@ module PageObject
14
23
  super + [:value, :label]
15
24
  end
16
25
 
17
- def self.selenium_finders
18
- super + [:value, :label]
19
- end
20
-
21
26
  end
22
27
 
23
28
  ::PageObject::Elements.type_to_class[:radio] = ::PageObject::Elements::RadioButton
@@ -1,11 +1,47 @@
1
-
2
1
  module PageObject
3
2
  module Elements
4
3
  class SelectList < Element
5
4
 
6
- def initialize(element, platform)
7
- @element = element
8
- include_platform_for platform
5
+ #
6
+ # Return the PageObject::Elements::Option for the index provided. Index
7
+ # is zero based.
8
+ #
9
+ # @return [PageObject::Elements::Option]
10
+ #
11
+ def [](idx)
12
+ options[idx]
13
+ end
14
+
15
+ #
16
+ # Return an array of Options contained in the select list.
17
+ #
18
+ # @return [array of PageObject::Elements::Option]
19
+ #
20
+ def options
21
+ element.options.map { |e| ::PageObject::Elements::Option.new(e, :platform => :watir) }
22
+ end
23
+
24
+ #
25
+ # @return [Array<String>] An array of strings representing the text of the currently selected options.
26
+ #
27
+ def selected_options
28
+ element.selected_options.map { |e| e.text }.compact
29
+ end
30
+
31
+ #
32
+ # @return [Array<String>] An array of strings representing the value of the currently selected options.
33
+ #
34
+ def selected_values
35
+ element.selected_options.map { |e| e.value }.compact
36
+ end
37
+
38
+ #
39
+ # Returns true if the select list has one or more options where text or label matches the given value.
40
+ #
41
+ # @param [String, Regexp] value A value.
42
+ # @return [Boolean]
43
+ def include?(value)
44
+ element.include? value
9
45
  end
10
46
 
11
47
  protected
@@ -18,10 +54,6 @@ module PageObject
18
54
  super + [:text, :value, :label]
19
55
  end
20
56
 
21
- def self.selenium_finders
22
- super + [:label]
23
- end
24
-
25
57
  end
26
58
 
27
59
  ::PageObject::Elements.tag_to_class[:select] = ::PageObject::Elements::SelectList
@@ -8,9 +8,6 @@ module PageObject
8
8
  [:class, :id, :index, :text, :title, :xpath]
9
9
  end
10
10
 
11
- def self.selenium_finders
12
- [:class, :css, :id, :name, :text, :title, :xpath, :index]
13
- end
14
11
  end
15
12
 
16
13
  ::PageObject::Elements.tag_to_class[:span] = ::PageObject::Elements::Span
@@ -3,11 +3,6 @@ module PageObject
3
3
  class Table < Element
4
4
  include Enumerable
5
5
 
6
- def initialize(element, platform)
7
- @element = element
8
- include_platform_for platform
9
- end
10
-
11
6
  #
12
7
  # iterator that yields with a PageObject::Elements::TableRow
13
8
  #
@@ -49,6 +44,26 @@ module PageObject
49
44
  end
50
45
  end
51
46
 
47
+ #
48
+ # Return the PageObject::Elements::TableRow for the index provided. Index
49
+ # is zero based. If the index provided is a String then it
50
+ # will be matched with the text from any column. The text can be a substring of the full column text.
51
+ #
52
+ # @return [PageObject::Elements::TableRow]
53
+ #
54
+ def [](idx)
55
+ idx = find_index_by_title(idx) if idx.kind_of?(String)
56
+ return nil unless idx
57
+ initialize_row(element[idx], :platform => :watir)
58
+ end
59
+
60
+ #
61
+ # Returns the number of rows in the table.
62
+ #
63
+ def rows
64
+ element.wd.find_elements(:xpath, child_xpath).size
65
+ end
66
+
52
67
  protected
53
68
 
54
69
  def child_xpath
@@ -59,6 +74,12 @@ module PageObject
59
74
  ::PageObject::Elements::TableRow.new(row_element, platform)
60
75
  end
61
76
 
77
+ def find_index_by_title(row_title)
78
+ element.rows.find_index do |row|
79
+ row.cells.any? { |col| col.text.include? row_title }
80
+ end
81
+ end
82
+
62
83
  end
63
84
 
64
85
  ::PageObject::Elements.tag_to_class[:table] = ::PageObject::Elements::Table
@@ -15,10 +15,6 @@ module PageObject
15
15
  super + [:text]
16
16
  end
17
17
 
18
- def self.selenium_finders
19
- super + [:text]
20
- end
21
-
22
18
  end
23
19
 
24
20
  ::PageObject::Elements.tag_to_class[:td] = ::PageObject::Elements::TableCell
@@ -1,14 +1,10 @@
1
+ require 'watir/elements/html_elements'
1
2
 
2
3
  module PageObject
3
4
  module Elements
4
5
  class TableRow < Element
5
6
  include Enumerable
6
7
 
7
- def initialize(element, platform)
8
- @element = element
9
- include_platform_for platform
10
- end
11
-
12
8
  #
13
9
  # iterator that yields with a PageObject::Elements::TableCell
14
10
  #
@@ -20,6 +16,25 @@ module PageObject
20
16
  end
21
17
  end
22
18
 
19
+ #
20
+ # Return the PageObject::Elements::TableCell for the index provided. Index
21
+ # is zero based. If the index provided is a String then it
22
+ # will be matched with the text from the columns in the first row.
23
+ # The text can be a substring of the full column text.
24
+ #
25
+ def [](idx)
26
+ idx = find_index_by_title(idx) if idx.kind_of?(String)
27
+ return nil unless idx && columns >= idx + 1
28
+ initialize_cell(element[idx], :platform => :watir)
29
+ end
30
+
31
+ #
32
+ # Returns the number of columns in the table.
33
+ #
34
+ def columns
35
+ element.wd.find_elements(:xpath, child_xpath).size
36
+ end
37
+
23
38
  protected
24
39
 
25
40
  def child_xpath
@@ -30,6 +45,16 @@ module PageObject
30
45
  ::PageObject::Elements::TableCell.new(row_element, platform)
31
46
  end
32
47
 
48
+ def find_index_by_title(title)
49
+ table = element.parent
50
+ table = table.parent if table.tag_name == 'tbody'
51
+ if table.instance_of? Watir::HTMLElement
52
+ table = table.to_subtype
53
+ end
54
+ first_row = table[0]
55
+ first_row.cells.find_index {|column| column.text.include? title }
56
+ end
57
+
33
58
  end
34
59
 
35
60
  ::PageObject::Elements.tag_to_class[:tr] = ::PageObject::Elements::TableRow
@@ -3,16 +3,16 @@ module PageObject
3
3
  module Elements
4
4
  class TextArea < Element
5
5
 
6
- def initialize(element, platform)
7
- @element = element
8
- include_platform_for platform
6
+ #
7
+ # Set the value of the TextArea
8
+ #
9
+ def value=(new_value)
10
+ element.set(new_value)
9
11
  end
10
12
 
11
- def self.watir_finders
12
- super + [:label]
13
- end
13
+ protected
14
14
 
15
- def self.selenium_finders
15
+ def self.watir_finders
16
16
  super + [:label]
17
17
  end
18
18
 
@@ -3,13 +3,11 @@ module PageObject
3
3
  module Elements
4
4
  class TextField < Element
5
5
 
6
- def initialize(element, platform)
7
- @element = element
8
- include_platform_for platform
9
- end
10
-
11
- def append(text)
12
- element.send_keys text
6
+ #
7
+ # Set the value of the TextField
8
+ #
9
+ def value=(new_value)
10
+ element.set(new_value)
13
11
  end
14
12
 
15
13
  protected
@@ -18,10 +16,6 @@ module PageObject
18
16
  super + [:title, :value, :text, :label]
19
17
  end
20
18
 
21
- def self.selenium_finders
22
- super + [:title, :value, :text, :label]
23
- end
24
-
25
19
  end
26
20
 
27
21
  ::PageObject::Elements.type_to_class[:text] = ::PageObject::Elements::TextField
@@ -4,11 +4,6 @@ module PageObject
4
4
  class UnorderedList < Element
5
5
  include Enumerable
6
6
 
7
- def initialize(element, platform)
8
- @element = element
9
- include_platform_for platform
10
- end
11
-
12
7
  #
13
8
  # iterator that yields with a PageObject::Elements::ListItem
14
9
  #
@@ -20,6 +15,32 @@ module PageObject
20
15
  end
21
16
  end
22
17
 
18
+ #
19
+ # Return the PageObject::Elements::ListItem for the index provided. Index
20
+ # is zero based.
21
+ #
22
+ # @return [PageObject::Elements::ListItem]
23
+ #
24
+ def [](idx)
25
+ Object::PageObject::Elements::ListItem.new(children[idx], :platform => :watir)
26
+ end
27
+
28
+ #
29
+ # Return the number of items contained in the unordered list
30
+ #
31
+ def items
32
+ children.size
33
+ end
34
+
35
+ #
36
+ # Return the ListItem objects that are children of the
37
+ # UnorderedList
38
+ #
39
+ def list_items
40
+ children.collect do |obj|
41
+ Object::PageObject::Elements::ListItem.new(obj, :platform => :watir)
42
+ end
43
+ end
23
44
 
24
45
  protected
25
46
 
@@ -31,6 +52,10 @@ module PageObject
31
52
  [:class, :id, :index, :xpath]
32
53
  end
33
54
 
55
+ def children
56
+ element.uls(:xpath => child_xpath)
57
+ end
58
+
34
59
  end
35
60
 
36
61
  ::PageObject::Elements.tag_to_class[:ul] = ::PageObject::Elements::UnorderedList