page-object 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +15 -0
- data/features/button.feature +1 -0
- data/features/element.feature +60 -56
- data/features/frames.feature +1 -0
- data/features/generic_elements.feature +24 -0
- data/features/html/multi_elements.html +4 -0
- data/features/html/nested_elements.html +4 -1
- data/features/html/static_elements.html +15 -1
- data/features/label.feature +44 -0
- data/features/link.feature +1 -0
- data/features/sample-app/public/prototype.html +1 -0
- data/features/step_definitions/element_steps.rb +22 -6
- data/features/step_definitions/frames_steps.rb +4 -0
- data/features/step_definitions/generic_element_steps.rb +19 -0
- data/features/step_definitions/label_steps.rb +19 -0
- data/features/support/page.rb +17 -0
- data/lib/page-object.rb +7 -0
- data/lib/page-object/accessors.rb +73 -1
- data/lib/page-object/element_locators.rb +36 -0
- data/lib/page-object/elements.rb +2 -1
- data/lib/page-object/elements/button.rb +2 -2
- data/lib/page-object/elements/element.rb +6 -6
- data/lib/page-object/elements/label.rb +19 -0
- data/lib/page-object/elements/link.rb +2 -2
- data/lib/page-object/elements/text_field.rb +1 -1
- data/lib/page-object/nested_elements.rb +8 -0
- data/lib/page-object/page_factory.rb +6 -0
- data/lib/page-object/platforms/selenium_webdriver/element.rb +17 -17
- data/lib/page-object/platforms/selenium_webdriver/form.rb +2 -2
- data/lib/page-object/platforms/selenium_webdriver/image.rb +2 -2
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +54 -1
- data/lib/page-object/platforms/selenium_webdriver/select_list.rb +2 -2
- data/lib/page-object/platforms/selenium_webdriver/table.rb +2 -2
- data/lib/page-object/platforms/watir_webdriver/element.rb +14 -14
- data/lib/page-object/platforms/watir_webdriver/form.rb +2 -2
- data/lib/page-object/platforms/watir_webdriver/image.rb +2 -2
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +72 -9
- data/lib/page-object/platforms/watir_webdriver/select_list.rb +5 -5
- data/lib/page-object/platforms/watir_webdriver/table.rb +2 -2
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +1 -1
- data/spec/page-object/accessors_spec.rb +15 -3
- data/spec/page-object/element_locators_spec.rb +24 -0
- data/spec/page-object/elements/button_spec.rb +2 -2
- data/spec/page-object/elements/label_spec.rb +29 -0
- data/spec/page-object/elements/link_spec.rb +2 -2
- data/spec/page-object/page-object_spec.rb +7 -1
- data/spec/page-object/page_factory_spec.rb +26 -0
- data/spec/page-object/platforms/watir_webdriver_spec.rb +1 -0
- metadata +26 -15
data/features/link.feature
CHANGED
@@ -58,19 +58,19 @@ Then /^I should know it is not visible$/ do
|
|
58
58
|
@element.should_not be_visible
|
59
59
|
end
|
60
60
|
|
61
|
-
Then /^I should know
|
61
|
+
Then /^I should know the text is "(.*)"$/ do |text|
|
62
62
|
@element.text.should == text
|
63
63
|
end
|
64
64
|
|
65
|
-
Then /^I should know
|
65
|
+
Then /^I should know the text includes "(.*)"$/ do |text|
|
66
66
|
@element.text.should include text
|
67
67
|
end
|
68
68
|
|
69
|
-
Then /^I should know
|
69
|
+
Then /^I should know the value is "(.*)"$/ do |value|
|
70
70
|
@element.value.should == value
|
71
71
|
end
|
72
72
|
|
73
|
-
Then /^I should know
|
73
|
+
Then /^I should know the value is nil$/ do
|
74
74
|
@element.value.should be_nil
|
75
75
|
end
|
76
76
|
|
@@ -78,11 +78,11 @@ Then /^I should know it is equal to itself$/ do
|
|
78
78
|
@element.should == @element
|
79
79
|
end
|
80
80
|
|
81
|
-
Then /^I should know
|
81
|
+
Then /^I should know the tag name is "(.+)"$/ do |tagname|
|
82
82
|
@element.tag_name.should == tagname
|
83
83
|
end
|
84
84
|
|
85
|
-
Then /^I should know the attribute "(
|
85
|
+
Then /^I should know the attribute "(.+)" is false$/ do |attr_name|
|
86
86
|
@attr = @element.attribute(attr_name)
|
87
87
|
@attr.should be_false if @attr.is_a? FalseClass
|
88
88
|
@attr.should == "false" if @attr.is_a? String
|
@@ -155,3 +155,19 @@ end
|
|
155
155
|
Then /^I should have a div parent$/ do
|
156
156
|
@parent.should be_instance_of ::PageObject::Elements::Div
|
157
157
|
end
|
158
|
+
|
159
|
+
Then /^I should know that the text_field has the focus$/ do
|
160
|
+
element = @page.element_with_focus
|
161
|
+
element.should_not be_nil
|
162
|
+
element.class.should == PageObject::Elements::TextField
|
163
|
+
end
|
164
|
+
|
165
|
+
When /^I set the focus to the test text_field$/ do
|
166
|
+
@page.text_field_element(:id => 'onfocus_text_field').focus
|
167
|
+
end
|
168
|
+
|
169
|
+
When /^I retrieve the label element$/ do
|
170
|
+
@element = @page.label_id_element
|
171
|
+
end
|
172
|
+
|
173
|
+
|
@@ -42,6 +42,10 @@ Then /^I should verify "([^\"]*)" is in the text field for frame 2 using "([^\"]
|
|
42
42
|
result.should == text
|
43
43
|
end
|
44
44
|
|
45
|
+
#Then /^I should be able to get the text fields text from frame 2 using "([^\"]*)"$/ do |arg_type|
|
46
|
+
# @page.send("text_field_2_#{arg_type}_element").text
|
47
|
+
#end
|
48
|
+
|
45
49
|
When /^I type "([^\"]*)" into the text field from frame 1 using "([^\"]*)"$/ do |text, arg_type|
|
46
50
|
@page.send "text_field_1_#{arg_type}=".to_sym, text
|
47
51
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
When /^I get the text from the article$/ do
|
2
|
+
@text = @page.article_id
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^I get the text from the header$/ do
|
6
|
+
@text = @page.header_id
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I get the text from the footer$/ do
|
10
|
+
@text = @page.footer_id
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I get the text from the summary$/ do
|
14
|
+
@text = @page.summary_id
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I get the text from the details$/ do
|
18
|
+
@text = @page.details_id
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
When /^I get the text from the label$/ do
|
2
|
+
@text = @page.label_id
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^I search for the label by "([^\"]*)"$/ do |how|
|
6
|
+
@text = @page.send "label_#{how}".to_sym
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I search for the label by "(.*)" and "(.*)"$/ do |param1, param2|
|
10
|
+
@text = @page.send "label_#{param1}_#{param2}".to_sym
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I get the text from a label while the script is executing$/ do
|
14
|
+
@text = @page.label_element(:id => 'label_id').text
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^I should see that the label exists$/ do
|
18
|
+
@page.label_id?.should be_true
|
19
|
+
end
|
data/features/support/page.rb
CHANGED
@@ -54,6 +54,7 @@ class Page
|
|
54
54
|
link(:google_search_href, :href => "success.html")
|
55
55
|
link(:google_search_text, :text => "Google Search")
|
56
56
|
link(:google_search_index, :index => 0)
|
57
|
+
link(:google_search_css, :css => "a.link_class")
|
57
58
|
|
58
59
|
select_list(:sel_list_id, :id => "sel_list_id")
|
59
60
|
select_list(:sel_list_class, :class => "sel_list_class")
|
@@ -127,6 +128,7 @@ class Page
|
|
127
128
|
button(:button_xpath, :xpath=> "//input[@type='submit']")
|
128
129
|
button(:button_text, :text => 'Click Me')
|
129
130
|
button(:button_value, :value => 'Click Me')
|
131
|
+
button(:button_css, :css => "input[type='submit']")
|
130
132
|
button(:button_class_index, :class => "button_class", :index => 0)
|
131
133
|
button(:button_name_index, :name => "button_name", :index => 0)
|
132
134
|
|
@@ -256,8 +258,23 @@ class Page
|
|
256
258
|
file_field(:file_field_class_index, :class => 'file_field_class', :index => 0)
|
257
259
|
file_field(:file_field_name_index, :name => 'file_field_name', :index => 0)
|
258
260
|
file_field(:file_field_xpath, :xpath => "//input[@type='file']")
|
261
|
+
|
262
|
+
label(:label_id, :id => 'label_id')
|
263
|
+
label(:label_name, :name => 'label_name')
|
264
|
+
label(:label_class, :class => 'label_class')
|
265
|
+
label(:label_text, :text => 'page-object is the best!')
|
266
|
+
label(:label_index, :index => 0)
|
267
|
+
label(:label_xpath, :xpath => '//label')
|
268
|
+
label(:label_class_index, :class => "label_class", :index => 0)
|
269
|
+
label(:label_name_index, :name => "label_name", :index => 0)
|
259
270
|
|
260
271
|
link(:open_window, :text => 'New Window')
|
261
272
|
link(:child, :id => 'child')
|
273
|
+
|
274
|
+
element(:article_id, :article, :id => 'article_id')
|
275
|
+
element(:header_id, :header, :id => 'header_id')
|
276
|
+
element(:footer_id, :footer, :id => 'footer_id')
|
277
|
+
element(:summary_id, :summary, :id => 'summary_id')
|
278
|
+
element(:details_id, :details, :id => 'details_id')
|
262
279
|
end
|
263
280
|
|
data/lib/page-object.rb
CHANGED
@@ -283,6 +283,13 @@ module PageObject
|
|
283
283
|
platform.attach_to_window(identifier, &block)
|
284
284
|
end
|
285
285
|
end
|
286
|
+
|
287
|
+
#
|
288
|
+
# Find the element that has focus on the page
|
289
|
+
#
|
290
|
+
def element_with_focus
|
291
|
+
platform.element_with_focus
|
292
|
+
end
|
286
293
|
|
287
294
|
#
|
288
295
|
# Refresh to current page
|
@@ -14,12 +14,15 @@ module PageObject
|
|
14
14
|
# 'goto' method to take you to the page.
|
15
15
|
#
|
16
16
|
# @param [String] the url for the page.
|
17
|
+
# @param [Symbol] a method name to call to get the url
|
17
18
|
#
|
18
19
|
def page_url(url)
|
19
20
|
define_method("goto") do
|
21
|
+
url = url.kind_of?(Symbol) ? self.send(url) : url
|
20
22
|
platform.navigate_to url
|
21
23
|
end
|
22
24
|
end
|
25
|
+
alias_method :direct_url, :page_url
|
23
26
|
|
24
27
|
#
|
25
28
|
# Creates a method that compares the expected_title of a page against the actual.
|
@@ -111,7 +114,7 @@ module PageObject
|
|
111
114
|
self.send("#{name}_element").value
|
112
115
|
end
|
113
116
|
define_method("#{name}=") do |value|
|
114
|
-
|
117
|
+
return platform.text_field_value_set(identifier.clone, value) unless block_given?
|
115
118
|
self.send("#{name}_element").value = value
|
116
119
|
end
|
117
120
|
define_method("#{name}_element") do
|
@@ -261,6 +264,7 @@ module PageObject
|
|
261
264
|
# @param [Hash] identifier how we find a link. You can use a multiple paramaters
|
262
265
|
# by combining of any of the following except xpath. The valid keys are:
|
263
266
|
# * :class => Watir and Selenium
|
267
|
+
# * :css => Watir and Selenium
|
264
268
|
# * :href => Watir and Selenium
|
265
269
|
# * :id => Watir and Selenium
|
266
270
|
# * :index => Watir and Selenium
|
@@ -392,6 +396,7 @@ module PageObject
|
|
392
396
|
# @param [Hash] identifier how we find a button. You can use a multiple paramaters
|
393
397
|
# by combining of any of the following except xpath. The valid keys are:
|
394
398
|
# * :class => Watir and Selenium
|
399
|
+
# * :css => Watir and Selenium
|
395
400
|
# * :id => Watir and Selenium
|
396
401
|
# * :index => Watir and Selenium
|
397
402
|
# * :name => Watir and Selenium
|
@@ -982,5 +987,72 @@ module PageObject
|
|
982
987
|
platform.file_field_for(identifier.clone).exists?
|
983
988
|
end
|
984
989
|
end
|
990
|
+
|
991
|
+
#
|
992
|
+
# adds three methods - one to retrieve the text from a label,
|
993
|
+
# another to return the label element, and another to check the label's existence.
|
994
|
+
#
|
995
|
+
# @example
|
996
|
+
# label(:message, :id => 'message')
|
997
|
+
# # will generate 'message', 'message_element', and 'message?' methods
|
998
|
+
#
|
999
|
+
# @param [String] the name used for the generated methods
|
1000
|
+
# @param [Hash] identifier how we find a label. You can use a multiple paramaters
|
1001
|
+
# by combining of any of the following except xpath. The valid keys are:
|
1002
|
+
# * :class => Watir and Selenium
|
1003
|
+
# * :id => Watir and Selenium
|
1004
|
+
# * :index => Watir and Selenium
|
1005
|
+
# * :name => Watir and Selenium
|
1006
|
+
# * :text => Watir and Selenium
|
1007
|
+
# * :xpath => Watir and Selenium
|
1008
|
+
# @param optional block to be invoked when element method is called
|
1009
|
+
#
|
1010
|
+
def label(name, identifier=nil, &block)
|
1011
|
+
define_method(name) do
|
1012
|
+
return platform.label_text_for identifier.clone unless block_given?
|
1013
|
+
self.send("#{name}_element").text
|
1014
|
+
end
|
1015
|
+
define_method("#{name}_element") do
|
1016
|
+
return call_block(&block) if block_given?
|
1017
|
+
platform.label_for(identifier.clone)
|
1018
|
+
end
|
1019
|
+
define_method("#{name}?") do
|
1020
|
+
return call_block(&block).exists? if block_given?
|
1021
|
+
platform.label_for(identifier.clone).exists?
|
1022
|
+
end
|
1023
|
+
alias_method "#{name}_label".to_sym, "#{name}_element".to_sym
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
#
|
1027
|
+
# adds three methods - one to retrieve the text of an element, another
|
1028
|
+
# to retrieve an element, and another to check the element's existence.
|
1029
|
+
#
|
1030
|
+
# @example
|
1031
|
+
# element(:title, :id => 'title')
|
1032
|
+
# # will generate 'title', 'title_element', and 'title?' methods
|
1033
|
+
#
|
1034
|
+
# @param [String] the name used for the generated methods
|
1035
|
+
# @param [Hash] identifier how we find an element. You can use a multiple paramaters
|
1036
|
+
# by combining of any of the following except xpath. The valid keys are:
|
1037
|
+
# * :class => Watir and Selenium
|
1038
|
+
# * :id => Watir and Selenium
|
1039
|
+
# * :index => Watir and Selenium
|
1040
|
+
# * :name => Watir and Selenium
|
1041
|
+
# * :xpath => Watir and Selenium
|
1042
|
+
# @param optional block to be invoked when element method is called
|
1043
|
+
#
|
1044
|
+
def element(name, tag, identifier=nil, &block)
|
1045
|
+
define_method("#{name}") do
|
1046
|
+
self.send("#{name}_element").text
|
1047
|
+
end
|
1048
|
+
define_method("#{name}_element") do
|
1049
|
+
return call_block(&block) if block_given?
|
1050
|
+
platform.element_for(tag, identifier.clone)
|
1051
|
+
end
|
1052
|
+
define_method("#{name}?") do
|
1053
|
+
self.send("#{name}_element").exists?
|
1054
|
+
end
|
1055
|
+
end
|
1056
|
+
|
985
1057
|
end
|
986
1058
|
end
|
@@ -7,6 +7,7 @@ module PageObject
|
|
7
7
|
# @param [Hash] identifier how we find a button. You can use a multiple paramaters
|
8
8
|
# by combining of any of the following except xpath. The valid keys are:
|
9
9
|
# * :class => Watir and Selenium
|
10
|
+
# * :css => Watir and Selenium
|
10
11
|
# * :id => Watir and Selenium
|
11
12
|
# * :index => Watir and Selenium
|
12
13
|
# * :name => Watir and Selenium
|
@@ -26,6 +27,7 @@ module PageObject
|
|
26
27
|
# @param [Hash] identifier how we find a button. You can use a multiple paramaters
|
27
28
|
# by combining of any of the following except xpath. The valid keys are:
|
28
29
|
# * :class => Watir and Selenium
|
30
|
+
# * :css => Watir and Selenium
|
29
31
|
# * :id => Watir and Selenium
|
30
32
|
# * :index => Watir and Selenium
|
31
33
|
# * :name => Watir and Selenium
|
@@ -189,6 +191,7 @@ module PageObject
|
|
189
191
|
# @param [Hash] identifier how we find a link. You can use a multiple paramaters
|
190
192
|
# by combining of any of the following except xpath. The valid keys are:
|
191
193
|
# * :class => Watir and Selenium
|
194
|
+
# * :css => Watir and Selenium
|
192
195
|
# * :href => Watir and Selenium
|
193
196
|
# * :id => Watir and Selenium
|
194
197
|
# * :index => Watir and Selenium
|
@@ -208,6 +211,7 @@ module PageObject
|
|
208
211
|
# @param [Hash] identifier how we find a link. You can use a multiple paramaters
|
209
212
|
# by combining of any of the following except xpath. The valid keys are:
|
210
213
|
# * :class => Watir and Selenium
|
214
|
+
# * :css => Watir and Selenium
|
211
215
|
# * :href => Watir and Selenium
|
212
216
|
# * :id => Watir and Selenium
|
213
217
|
# * :index => Watir and Selenium
|
@@ -763,6 +767,38 @@ module PageObject
|
|
763
767
|
platform.paragraphs_for(identifier.clone)
|
764
768
|
end
|
765
769
|
|
770
|
+
#
|
771
|
+
# Finds a label
|
772
|
+
#
|
773
|
+
# @param [Hash] identifier how we find a label. You can use a multiple paramaters
|
774
|
+
# by combining of any of the following except xpath. The valid keys are:
|
775
|
+
# * :class => Watir and Selenium
|
776
|
+
# * :id => Watir and Selenium
|
777
|
+
# * :index => Watir and Selenium
|
778
|
+
# * :name => Watir and Selenium
|
779
|
+
# * :text => Watir and Selenium
|
780
|
+
# * :xpath => Watir and Selenium
|
781
|
+
#
|
782
|
+
def label_element(identifier)
|
783
|
+
platform.label_for(identifier.clone)
|
784
|
+
end
|
785
|
+
|
786
|
+
#
|
787
|
+
# Finds all labels that match the provided identifier
|
788
|
+
#
|
789
|
+
# @param [Hash] identifier how we find a label. You can use a multiple paramaters
|
790
|
+
# by combining of any of the following except xpath. The valid keys are:
|
791
|
+
# * :class => Watir and Selenium
|
792
|
+
# * :id => Watir and Selenium
|
793
|
+
# * :index => Watir and Selenium
|
794
|
+
# * :name => Watir and Selenium
|
795
|
+
# * :text => Watir and Selenium
|
796
|
+
# * :xpath => Watir and Selenium
|
797
|
+
#
|
798
|
+
def label_elements(identifier)
|
799
|
+
platform.labels_for(identifier.clone)
|
800
|
+
end
|
801
|
+
|
766
802
|
#
|
767
803
|
# Finds a paragraph
|
768
804
|
#
|
data/lib/page-object/elements.rb
CHANGED
@@ -17,7 +17,7 @@ module PageObject
|
|
17
17
|
# method to return the element for a tag_name
|
18
18
|
#
|
19
19
|
def element_class_for(tag_name, type=nil)
|
20
|
-
return type_to_class[type] if type
|
20
|
+
return type_to_class[type.to_sym] if type
|
21
21
|
tag_to_class[tag_name.to_sym] || ::PageObject::Elements::Element
|
22
22
|
end
|
23
23
|
|
@@ -48,5 +48,6 @@ require 'page-object/elements/ordered_list'
|
|
48
48
|
require 'page-object/elements/option'
|
49
49
|
require 'page-object/elements/heading'
|
50
50
|
require 'page-object/elements/paragraph'
|
51
|
+
require 'page-object/elements/label'
|
51
52
|
require 'page-object/elements/file_field'
|
52
53
|
|
@@ -11,11 +11,11 @@ module PageObject
|
|
11
11
|
protected
|
12
12
|
|
13
13
|
def self.watir_finders
|
14
|
-
super + [:text, :value, :src, :alt]
|
14
|
+
super + [:text, :value, :src, :alt, :css]
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.selenium_finders
|
18
|
-
super + [:value, :src, :alt]
|
18
|
+
super + [:value, :src, :alt, :css]
|
19
19
|
end
|
20
20
|
|
21
21
|
def include_platform_for platform
|
@@ -22,21 +22,21 @@ module PageObject
|
|
22
22
|
# click the element
|
23
23
|
#
|
24
24
|
def click
|
25
|
-
|
25
|
+
element.click
|
26
26
|
end
|
27
27
|
|
28
28
|
#
|
29
29
|
# double click the element
|
30
30
|
#
|
31
31
|
def double_click
|
32
|
-
|
32
|
+
element.double_click
|
33
33
|
end
|
34
34
|
|
35
35
|
#
|
36
36
|
# return true if the element is enabled
|
37
37
|
#
|
38
38
|
def enabled?
|
39
|
-
|
39
|
+
element.enabled?
|
40
40
|
end
|
41
41
|
|
42
42
|
#
|
@@ -50,11 +50,11 @@ module PageObject
|
|
50
50
|
# get the value of the given CSS property
|
51
51
|
#
|
52
52
|
def style(property)
|
53
|
-
|
53
|
+
element.style property
|
54
54
|
end
|
55
55
|
|
56
56
|
def inspect
|
57
|
-
|
57
|
+
element.inspect
|
58
58
|
end
|
59
59
|
|
60
60
|
# @private
|
@@ -105,7 +105,7 @@ module PageObject
|
|
105
105
|
protected
|
106
106
|
|
107
107
|
def self.should_build_watir_xpath identifier
|
108
|
-
['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].include? identifier[:tag_name] and identifier[:name]
|
108
|
+
['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label'].include? identifier[:tag_name] and identifier[:name]
|
109
109
|
end
|
110
110
|
|
111
111
|
def self.build_xpath_for identifier
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Elements
|
3
|
+
class Label < Element
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def self.watir_finders
|
8
|
+
super + [:text]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.selenium_finders
|
12
|
+
super + [:text]
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
::PageObject::Elements.tag_to_class[:label] = ::PageObject::Elements::Label
|
18
|
+
end
|
19
|
+
end
|