centric_page_object 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +17 -0
  8. data/ChangeLog +931 -0
  9. data/Gemfile +12 -0
  10. data/Guardfile +20 -0
  11. data/LICENSE +20 -0
  12. data/README.md +114 -0
  13. data/Rakefile +29 -0
  14. data/centric_page_object.gemspec +31 -0
  15. data/cucumber.yml +8 -0
  16. data/lib/page-object/accessors.rb +1201 -0
  17. data/lib/page-object/element_locators.rb +21 -0
  18. data/lib/page-object/elements/area.rb +9 -0
  19. data/lib/page-object/elements/audio.rb +9 -0
  20. data/lib/page-object/elements/bold.rb +9 -0
  21. data/lib/page-object/elements/button.rb +12 -0
  22. data/lib/page-object/elements/canvas.rb +10 -0
  23. data/lib/page-object/elements/check_box.rb +9 -0
  24. data/lib/page-object/elements/date_field.rb +10 -0
  25. data/lib/page-object/elements/div.rb +9 -0
  26. data/lib/page-object/elements/element.rb +212 -0
  27. data/lib/page-object/elements/file_field.rb +9 -0
  28. data/lib/page-object/elements/form.rb +9 -0
  29. data/lib/page-object/elements/heading.rb +14 -0
  30. data/lib/page-object/elements/hidden_field.rb +9 -0
  31. data/lib/page-object/elements/image.rb +10 -0
  32. data/lib/page-object/elements/italic.rb +9 -0
  33. data/lib/page-object/elements/label.rb +9 -0
  34. data/lib/page-object/elements/link.rb +9 -0
  35. data/lib/page-object/elements/list_item.rb +9 -0
  36. data/lib/page-object/elements/media.rb +11 -0
  37. data/lib/page-object/elements/option.rb +9 -0
  38. data/lib/page-object/elements/ordered_list.rb +43 -0
  39. data/lib/page-object/elements/paragraph.rb +9 -0
  40. data/lib/page-object/elements/radio_button.rb +9 -0
  41. data/lib/page-object/elements/select_list.rb +42 -0
  42. data/lib/page-object/elements/span.rb +9 -0
  43. data/lib/page-object/elements/table.rb +85 -0
  44. data/lib/page-object/elements/table_cell.rb +10 -0
  45. data/lib/page-object/elements/table_row.rb +52 -0
  46. data/lib/page-object/elements/text_area.rb +9 -0
  47. data/lib/page-object/elements/text_field.rb +10 -0
  48. data/lib/page-object/elements/unordered_list.rb +42 -0
  49. data/lib/page-object/elements/video.rb +9 -0
  50. data/lib/page-object/elements.rb +62 -0
  51. data/lib/page-object/indexed_properties.rb +41 -0
  52. data/lib/page-object/javascript/angularjs.rb +14 -0
  53. data/lib/page-object/javascript/jquery.rb +14 -0
  54. data/lib/page-object/javascript/prototype.rb +14 -0
  55. data/lib/page-object/javascript/yui.rb +19 -0
  56. data/lib/page-object/javascript_framework_facade.rb +80 -0
  57. data/lib/page-object/locator_generator.rb +183 -0
  58. data/lib/page-object/nested_elements.rb +17 -0
  59. data/lib/page-object/page_factory.rb +108 -0
  60. data/lib/page-object/page_populator.rb +105 -0
  61. data/lib/page-object/platforms/watir/page_object.rb +1155 -0
  62. data/lib/page-object/platforms/watir.rb +50 -0
  63. data/lib/page-object/section_collection.rb +16 -0
  64. data/lib/page-object/version.rb +4 -0
  65. data/lib/page-object/widgets.rb +98 -0
  66. data/lib/page-object.rb +431 -0
  67. data/pageobject.gems +1 -0
  68. metadata +239 -0
@@ -0,0 +1,105 @@
1
+ module PageObject
2
+ module PagePopulator
3
+
4
+ #
5
+ # This method will populate all matched page TextFields,
6
+ # TextAreas, SelectLists, FileFields, Checkboxes, and Radio Buttons from the
7
+ # Hash passed as an argument. The way it find an element is by
8
+ # matching the Hash key to the name you provided when declaring
9
+ # the element on your page.
10
+ #
11
+ # Checkbox and Radio Button values must be true or false.
12
+ #
13
+ # @example
14
+ # class ExamplePage
15
+ # include PageObject
16
+ #
17
+ # text_field(:username, :id => 'username_id')
18
+ # checkbox(:active, :id => 'active_id')
19
+ # end
20
+ #
21
+ # ...
22
+ #
23
+ # @browser = Watir::Browser.new :firefox
24
+ # example_page = ExamplePage.new(@browser)
25
+ # example_page.populate_page_with :username => 'a name', :active => true
26
+ #
27
+ # @param data [Hash] the data to use to populate this page. The key
28
+ # can be either a string or a symbol. The value must be a string
29
+ # for TextField, TextArea, SelectList, and FileField and must be true or
30
+ # false for a Checkbox or RadioButton.
31
+ #
32
+ def populate_page_with(data)
33
+ data.to_h.each do |key, value|
34
+ populate_section(key, value) if value.respond_to?(:to_h)
35
+ populate_value(self, key, value)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def populate_section(section, data)
42
+ return unless self.respond_to? section
43
+ data.to_h.each do |key, value|
44
+ populate_value(self.send(section), key, value)
45
+ end
46
+ end
47
+
48
+ def populate_value(receiver, key, value)
49
+ populate_checkbox(receiver, key, value) if is_checkbox?(receiver, key) and is_enabled?(receiver, key)
50
+ populate_radiobuttongroup(receiver, key, value) if is_radiobuttongroup?(receiver, key)
51
+ populate_radiobutton(receiver, key, value) if is_radiobutton?(receiver, key) and is_enabled?(receiver, key)
52
+ populate_select_list(receiver, key, value) if is_select_list?(receiver, key)
53
+ populate_text(receiver, key, value) if is_text?(receiver, key) and is_enabled?(receiver, key)
54
+ end
55
+
56
+ def populate_text(receiver, key, value)
57
+ receiver.send "#{key}=", value
58
+ end
59
+
60
+ def populate_checkbox(receiver, key, value)
61
+ return receiver.send "check_#{key}" if value
62
+ receiver.send "uncheck_#{key}"
63
+ end
64
+
65
+ def populate_radiobutton(receiver, key, value)
66
+ receiver.send "select_#{key}" if value
67
+ end
68
+
69
+ def populate_radiobuttongroup(receiver, key, value)
70
+ receiver.send("select_#{key}", value)
71
+ end
72
+
73
+ def populate_select_list(receiver, key, value)
74
+ receiver.send "#{key}=", value
75
+ end
76
+
77
+ def is_text?(receiver, key)
78
+ return false if is_select_list?(receiver, key)
79
+ receiver.respond_to?("#{key}=".to_sym)
80
+ end
81
+
82
+ def is_checkbox?(receiver, key)
83
+ receiver.respond_to?("check_#{key}".to_sym)
84
+ end
85
+
86
+ def is_radiobutton?(receiver, key)
87
+ receiver.respond_to?("select_#{key}".to_sym)
88
+ end
89
+
90
+ def is_radiobuttongroup?(receiver, key)
91
+ receiver.respond_to?("select_#{key}".to_sym) and receiver.respond_to?("#{key}_values")
92
+ end
93
+
94
+ def is_select_list?(receiver, key)
95
+ receiver.respond_to?("#{key}_options".to_sym)
96
+ end
97
+
98
+ def is_enabled?(receiver, key)
99
+ return false if is_radiobuttongroup?(receiver, key)
100
+ return true if (receiver.send "#{key}_element").tag_name == "textarea"
101
+ element = receiver.send("#{key}_element")
102
+ element.enabled? and element.present?
103
+ end
104
+ end
105
+ end