page-object 2.2.6 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -1
  3. data/.gitignore +8 -8
  4. data/.rspec +2 -2
  5. data/.ruby-gemset +1 -1
  6. data/.ruby-version +1 -1
  7. data/.travis.yml +17 -17
  8. data/ChangeLog +923 -916
  9. data/Gemfile +13 -13
  10. data/Guardfile +20 -20
  11. data/LICENSE +20 -20
  12. data/README.md +114 -114
  13. data/Rakefile +29 -29
  14. data/cucumber.yml +8 -8
  15. data/lib/page-object.rb +431 -420
  16. data/lib/page-object/accessors.rb +1201 -1175
  17. data/lib/page-object/element_locators.rb +21 -21
  18. data/lib/page-object/elements.rb +62 -61
  19. data/lib/page-object/elements/area.rb +9 -9
  20. data/lib/page-object/elements/audio.rb +9 -9
  21. data/lib/page-object/elements/bold.rb +9 -9
  22. data/lib/page-object/elements/button.rb +12 -12
  23. data/lib/page-object/elements/canvas.rb +10 -10
  24. data/lib/page-object/elements/check_box.rb +9 -9
  25. data/lib/page-object/elements/date_field.rb +10 -0
  26. data/lib/page-object/elements/div.rb +9 -9
  27. data/lib/page-object/elements/element.rb +212 -209
  28. data/lib/page-object/elements/file_field.rb +9 -9
  29. data/lib/page-object/elements/form.rb +9 -9
  30. data/lib/page-object/elements/heading.rb +14 -14
  31. data/lib/page-object/elements/hidden_field.rb +9 -9
  32. data/lib/page-object/elements/image.rb +10 -10
  33. data/lib/page-object/elements/italic.rb +9 -9
  34. data/lib/page-object/elements/label.rb +9 -9
  35. data/lib/page-object/elements/link.rb +9 -9
  36. data/lib/page-object/elements/list_item.rb +9 -9
  37. data/lib/page-object/elements/media.rb +11 -11
  38. data/lib/page-object/elements/option.rb +9 -9
  39. data/lib/page-object/elements/ordered_list.rb +43 -43
  40. data/lib/page-object/elements/paragraph.rb +9 -9
  41. data/lib/page-object/elements/radio_button.rb +9 -9
  42. data/lib/page-object/elements/select_list.rb +42 -42
  43. data/lib/page-object/elements/span.rb +9 -9
  44. data/lib/page-object/elements/table.rb +85 -85
  45. data/lib/page-object/elements/table_cell.rb +10 -10
  46. data/lib/page-object/elements/table_row.rb +52 -52
  47. data/lib/page-object/elements/text_area.rb +9 -9
  48. data/lib/page-object/elements/text_field.rb +10 -10
  49. data/lib/page-object/elements/unordered_list.rb +42 -42
  50. data/lib/page-object/elements/video.rb +9 -9
  51. data/lib/page-object/indexed_properties.rb +41 -41
  52. data/lib/page-object/javascript/angularjs.rb +14 -14
  53. data/lib/page-object/javascript/jquery.rb +14 -14
  54. data/lib/page-object/javascript/prototype.rb +14 -14
  55. data/lib/page-object/javascript/yui.rb +18 -18
  56. data/lib/page-object/javascript_framework_facade.rb +80 -80
  57. data/lib/page-object/locator_generator.rb +183 -182
  58. data/lib/page-object/nested_elements.rb +17 -17
  59. data/lib/page-object/page_factory.rb +108 -108
  60. data/lib/page-object/page_populator.rb +105 -105
  61. data/lib/page-object/platforms/watir.rb +50 -50
  62. data/lib/page-object/platforms/watir/page_object.rb +1155 -1124
  63. data/lib/page-object/section_collection.rb +16 -16
  64. data/lib/page-object/version.rb +4 -4
  65. data/lib/page-object/widgets.rb +98 -98
  66. data/page-object.gemspec +32 -32
  67. metadata +8 -7
@@ -1,17 +1,17 @@
1
- require 'page-object/locator_generator'
2
-
3
- module PageObject
4
- module NestedElements
5
-
6
- def self.included(cls)
7
- ::PageObject::LocatorGenerator.generate_locators(cls)
8
- end
9
-
10
- private
11
-
12
- def locator(identifier)
13
- identifier[0] ? identifier[0] : {:index => 0}
14
- end
15
-
16
- end
17
- end
1
+ require 'page-object/locator_generator'
2
+
3
+ module PageObject
4
+ module NestedElements
5
+
6
+ def self.included(cls)
7
+ ::PageObject::LocatorGenerator.generate_locators(cls)
8
+ end
9
+
10
+ private
11
+
12
+ def locator(identifier)
13
+ identifier[0] ? identifier[0] : {:index => 0}
14
+ end
15
+
16
+ end
17
+ end
@@ -1,108 +1,108 @@
1
- require 'page_navigation'
2
-
3
- module PageObject
4
- #
5
- # Module to facilitate to creating of page objects in step definitions. You
6
- # can make the methods below available to all of your step definitions by adding
7
- # this module to World. This idea was first discussed in Alister Scott's blog
8
- # entry http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/.
9
- #
10
- # @example Making the PageFactory available to your step definitions
11
- # World PageObject::PageFactory
12
- #
13
- # @example Visiting a page for the first time in a Scenario
14
- # visit_page MyPageObject do |page|
15
- # page.name = 'Cheezy'
16
- # end
17
- #
18
- # @example using a page that has already been visited in a Scenario
19
- # on_page MyPageObject do |page|
20
- # page.name.should == 'Cheezy'
21
- # end
22
- #
23
- # If you plan to use the navigate_to method you will need to ensure
24
- # you setup the possible routes ahead of time. You must always have
25
- # a default route in order for this to work. Here is an example of
26
- # how you define routes:
27
- #
28
- # @example Example routes defined in env.rb
29
- # PageObject::PageFactory.routes = {
30
- # :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]],
31
- # :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]]
32
- # }
33
- #
34
- # Notice the first entry of :another_route is passing an argument
35
- # to the method.
36
- #
37
- module PageFactory
38
- include PageNavigation
39
-
40
-
41
- #
42
- # Create and navigate to a page object. The navigation will only work if the
43
- # 'page_url' method was call on the page object.
44
- #
45
- # @param [PageObject, String] a class that has included the
46
- # PageObject module or a string containing the name of the class
47
- # @param Hash values that is pass through to page class a
48
- # available in the @params instance variable.
49
- # @param an optional block to be called
50
- # @return [PageObject] the newly created page object
51
- #
52
- def visit_page(page_class, params={:using_params => {}}, &block)
53
- on_page page_class, params, true, &block
54
- end
55
-
56
- # Support 'visit' for readability of usage
57
- alias_method :visit, :visit_page
58
-
59
- #
60
- # Create a page object.
61
- #
62
- # @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
63
- # @param Hash values that is pass through to page class a
64
- # available in the @params instance variable.
65
- # @param [Boolean] a boolean indicating if the page should be visited? default is false.
66
- # @param [block] an optional block to be called
67
- # @return [PageObject] the newly created page object
68
- #
69
- def on_page(page_class, params={:using_params => {}}, visit=false, &block)
70
- page_class = class_from_string(page_class) if page_class.is_a? String
71
- return super(page_class, params, visit, &block) unless page_class.ancestors.include? PageObject
72
- merged = page_class.params.merge(params[:using_params])
73
- page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
74
- @current_page = page_class.new(@browser, visit)
75
- block.call @current_page if block
76
- @current_page
77
- end
78
-
79
- # Support 'on' for readability of usage
80
- alias_method :on, :on_page
81
-
82
- #
83
- # Create a page object if and only if the current page is the same page to be created
84
- #
85
- # @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
86
- # @param Hash values that is pass through to page class a
87
- # available in the @params instance variable.
88
- # @param [block] an optional block to be called
89
- # @return [PageObject] the newly created page object
90
- #
91
- def if_page(page_class, params={:using_params => {}},&block)
92
- page_class = class_from_string(page_class) if page_class.is_a? String
93
- return @current_page unless @current_page.class == page_class
94
- on_page(page_class, params, false, &block)
95
- end
96
-
97
- # Support 'if' for readability of usage
98
- alias_method :if, :if_page
99
-
100
- private
101
-
102
- def class_from_string(str)
103
- str.split('::').inject(Object) do |mod, class_name|
104
- mod.const_get(class_name)
105
- end
106
- end
107
- end
108
- end
1
+ require 'page_navigation'
2
+
3
+ module PageObject
4
+ #
5
+ # Module to facilitate to creating of page objects in step definitions. You
6
+ # can make the methods below available to all of your step definitions by adding
7
+ # this module to World. This idea was first discussed in Alister Scott's blog
8
+ # entry http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/.
9
+ #
10
+ # @example Making the PageFactory available to your step definitions
11
+ # World PageObject::PageFactory
12
+ #
13
+ # @example Visiting a page for the first time in a Scenario
14
+ # visit_page MyPageObject do |page|
15
+ # page.name = 'Cheezy'
16
+ # end
17
+ #
18
+ # @example using a page that has already been visited in a Scenario
19
+ # on_page MyPageObject do |page|
20
+ # page.name.should == 'Cheezy'
21
+ # end
22
+ #
23
+ # If you plan to use the navigate_to method you will need to ensure
24
+ # you setup the possible routes ahead of time. You must always have
25
+ # a default route in order for this to work. Here is an example of
26
+ # how you define routes:
27
+ #
28
+ # @example Example routes defined in env.rb
29
+ # PageObject::PageFactory.routes = {
30
+ # :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]],
31
+ # :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]]
32
+ # }
33
+ #
34
+ # Notice the first entry of :another_route is passing an argument
35
+ # to the method.
36
+ #
37
+ module PageFactory
38
+ include PageNavigation
39
+
40
+
41
+ #
42
+ # Create and navigate to a page object. The navigation will only work if the
43
+ # 'page_url' method was call on the page object.
44
+ #
45
+ # @param [PageObject, String] a class that has included the
46
+ # PageObject module or a string containing the name of the class
47
+ # @param Hash values that is pass through to page class a
48
+ # available in the @params instance variable.
49
+ # @param an optional block to be called
50
+ # @return [PageObject] the newly created page object
51
+ #
52
+ def visit_page(page_class, params={:using_params => {}}, &block)
53
+ on_page page_class, params, true, &block
54
+ end
55
+
56
+ # Support 'visit' for readability of usage
57
+ alias_method :visit, :visit_page
58
+
59
+ #
60
+ # Create a page object.
61
+ #
62
+ # @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
63
+ # @param Hash values that is pass through to page class a
64
+ # available in the @params instance variable.
65
+ # @param [Boolean] a boolean indicating if the page should be visited? default is false.
66
+ # @param [block] an optional block to be called
67
+ # @return [PageObject] the newly created page object
68
+ #
69
+ def on_page(page_class, params={:using_params => {}}, visit=false, &block)
70
+ page_class = class_from_string(page_class) if page_class.is_a? String
71
+ return super(page_class, params, visit, &block) unless page_class.ancestors.include? PageObject
72
+ merged = page_class.params.merge(params[:using_params])
73
+ page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
74
+ @current_page = page_class.new(@browser, visit)
75
+ block.call @current_page if block
76
+ @current_page
77
+ end
78
+
79
+ # Support 'on' for readability of usage
80
+ alias_method :on, :on_page
81
+
82
+ #
83
+ # Create a page object if and only if the current page is the same page to be created
84
+ #
85
+ # @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
86
+ # @param Hash values that is pass through to page class a
87
+ # available in the @params instance variable.
88
+ # @param [block] an optional block to be called
89
+ # @return [PageObject] the newly created page object
90
+ #
91
+ def if_page(page_class, params={:using_params => {}},&block)
92
+ page_class = class_from_string(page_class) if page_class.is_a? String
93
+ return @current_page unless @current_page.class == page_class
94
+ on_page(page_class, params, false, &block)
95
+ end
96
+
97
+ # Support 'if' for readability of usage
98
+ alias_method :if, :if_page
99
+
100
+ private
101
+
102
+ def class_from_string(str)
103
+ str.split('::').inject(Object) do |mod, class_name|
104
+ mod.const_get(class_name)
105
+ end
106
+ end
107
+ end
108
+ end
@@ -1,105 +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
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