page-object 0.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/ChangeLog +10 -0
  2. data/features/button.feature +2 -1
  3. data/features/check_box.feature +2 -1
  4. data/features/div.feature +2 -1
  5. data/features/element.feature +2 -0
  6. data/features/form.feature +2 -1
  7. data/features/hidden_field.feature +4 -3
  8. data/features/image.feature +2 -1
  9. data/features/link.feature +1 -1
  10. data/features/list_item.feature +2 -1
  11. data/features/ordered_list.feature +2 -1
  12. data/features/paragraph.feature +2 -1
  13. data/features/radio_button.feature +2 -1
  14. data/features/select_list.feature +14 -1
  15. data/features/span.feature +2 -1
  16. data/features/step_definitions/button_steps.rb +4 -0
  17. data/features/step_definitions/check_box_steps.rb +4 -0
  18. data/features/step_definitions/div_steps.rb +4 -0
  19. data/features/step_definitions/element_steps.rb +8 -0
  20. data/features/step_definitions/form_steps.rb +4 -0
  21. data/features/step_definitions/hidden_field_steps.rb +5 -1
  22. data/features/step_definitions/image_steps.rb +4 -0
  23. data/features/step_definitions/link_steps.rb +6 -0
  24. data/features/step_definitions/list_item_steps.rb +4 -0
  25. data/features/step_definitions/ordered_list_steps.rb +4 -0
  26. data/features/step_definitions/paragraph_steps.rb +4 -0
  27. data/features/step_definitions/radio_button_steps.rb +4 -0
  28. data/features/step_definitions/select_list_steps.rb +18 -1
  29. data/features/step_definitions/span_steps.rb +4 -0
  30. data/features/step_definitions/table_cell_steps.rb +4 -0
  31. data/features/step_definitions/table_steps.rb +4 -0
  32. data/features/step_definitions/text_area_steps.rb +4 -0
  33. data/features/step_definitions/text_field_steps.rb +9 -1
  34. data/features/step_definitions/unordered_list_steps.rb +3 -0
  35. data/features/table.feature +5 -1
  36. data/features/table_cell.feature +2 -1
  37. data/features/text_area.feature +2 -1
  38. data/features/text_field.feature +8 -1
  39. data/features/unordered_list.feature +2 -1
  40. data/lib/page-object/accessors.rb +191 -68
  41. data/lib/page-object/elements/element.rb +8 -1
  42. data/lib/page-object/elements/text_field.rb +4 -0
  43. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +34 -7
  44. data/lib/page-object/platforms/watir_webdriver/select_list.rb +26 -2
  45. data/lib/page-object/version.rb +1 -1
  46. data/page-object.gemspec +1 -1
  47. data/spec/page-object/elements/element_spec.rb +37 -2
  48. data/spec/page-object/elements/select_list_spec.rb +49 -8
  49. data/spec/page-object/elements/text_field_spec.rb +8 -2
  50. metadata +13 -13
data/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ === Version 0.6.1 / 2012-1-18
2
+ * Enhancements
3
+ * Added #disabled? method to Element
4
+ * Added #selected_options method to SelectList
5
+ * Added #include? and #selected? to SelectList
6
+ * Added #append to TextField
7
+ * generates a method to determine if an element exists (Thanks Nicholas Munson)
8
+ * better message when calling platform method via method_missing (Thanks Alex Rodionov)
9
+ * Updated to use selenium-webdriver 2.17.0
10
+
1
11
  === Version 0.6 / 2012-1-10
2
12
  * Enhancements
3
13
  * Added ?_elements methods to ElementLocator so you can find all elements that match an identifier
@@ -82,5 +82,6 @@ Feature: Button
82
82
 
83
83
  Scenario: Finding a button dynamically
84
84
  When I find a button while the script is executing
85
- Then I should be able to click the button element
85
+ Then I should see that the button exists
86
+ And I should be able to click the button element
86
87
 
@@ -41,4 +41,5 @@ Feature: Check Box
41
41
 
42
42
  Scenario: Finding a check box dynamically
43
43
  When I select the first check box while the script is executing
44
- Then the First check box should be selected
44
+ Then I should see that the checkbox exists
45
+ And the First check box should be selected
data/features/div.feature CHANGED
@@ -39,4 +39,5 @@ Feature: Div
39
39
 
40
40
  Scenario: Finding a div dynamically
41
41
  When I get the text from a div while the script is executing
42
- Then the text should be "page-object rocks!"
42
+ Then I should see that the div exists
43
+ And the text should be "page-object rocks!"
@@ -12,8 +12,10 @@ Feature: Elements
12
12
  Scenario: Elements enabled?
13
13
  When I check an enabled button
14
14
  Then it should know it is enabled
15
+ And it should know that is it not disabled
15
16
  When I check a disabled button
16
17
  Then it should know it is not enabled
18
+ And it should know that it is disabled
17
19
 
18
20
  Scenario: Link element methods
19
21
  When I retrieve a link element
@@ -30,4 +30,5 @@ Feature: Form
30
30
 
31
31
  Scenario: Finding a form dynamically
32
32
  When I locate a form while the script is executing
33
- Then I should be able to submit the form
33
+ Then I should see that the form exists
34
+ And I should be able to submit the form
@@ -9,7 +9,7 @@ Feature: Hidden Fields
9
9
 
10
10
  Scenario Outline: Locating hidden fields on the Page
11
11
  When I search for the hidden field by "<search_by>"
12
- Then hidden field element should contains "12345"
12
+ Then the hidden field element should contain "12345"
13
13
 
14
14
  Scenarios:
15
15
  | search_by |
@@ -25,7 +25,7 @@ Feature: Hidden Fields
25
25
 
26
26
  Scenario Outline: Locating a hidden field using multiple parameters
27
27
  When I search for the hidden field by "<param1>" and "<param2>"
28
- Then hidden field element should contains "12345"
28
+ Then the hidden field element should contain "12345"
29
29
 
30
30
  Scenarios:
31
31
  | param1 | param2 |
@@ -34,4 +34,5 @@ Feature: Hidden Fields
34
34
 
35
35
  Scenario: Finding a hidden field dynamically
36
36
  When I find a hidden field while the script is executing
37
- Then hidden field element should contains "12345"
37
+ Then I should see that the hidden field exists
38
+ And the hidden field element should contain "12345"
@@ -35,5 +35,6 @@ Feature: Image
35
35
 
36
36
  Scenario: Finding an image dynamically
37
37
  When I get the image element while the script is executing
38
- Then the image should be "106" pixels wide
38
+ Then I should see that the image exists
39
+ And the image should be "106" pixels wide
39
40
  And the image should be "106" pixels tall
@@ -39,4 +39,4 @@ Feature: Links
39
39
 
40
40
  Scenario: Finding a link dynamically
41
41
  When I select a link while the script is executing
42
- Then the page should contain the text "Success"
42
+ And the page should contain the text "Success"
@@ -30,4 +30,5 @@ Feature: List item
30
30
 
31
31
  Scenario: Finding a list item dynamically
32
32
  When I search for the list item while the script is executing
33
- Then the text should be "Item One"
33
+ Then I should see that the list item exists
34
+ And the text should be "Item One"
@@ -34,5 +34,6 @@ Feature: Ordered list
34
34
 
35
35
  Scenario: Finding a ordered list dynamically
36
36
  When I search for the ordered list while the script is executing
37
- And I get the first item from the list
37
+ Then I should see that the ordered list exists
38
+ When I get the first item from the list
38
39
  Then the list items text should be "Number One"
@@ -30,4 +30,5 @@ Feature: Paragraph
30
30
 
31
31
  Scenario: Finding a paragraph dynamically
32
32
  When I get the text from a paragraph while the script is executing
33
- Then the text should be "Static Elements Page"
33
+ Then I should see that the paragraph exists
34
+ And the text should be "Static Elements Page"
@@ -43,4 +43,5 @@ Feature: Radio Buttons
43
43
 
44
44
  Scenario: Finding a radio button dynamically
45
45
  When I select the radio button while the script is executing
46
- Then the "Milk" radio button should be selected
46
+ Then I should see that the radio button exists
47
+ And the "Milk" radio button should be selected
@@ -41,4 +41,17 @@ Feature: Select List
41
41
 
42
42
  Scenario: Finding a select list dynamically
43
43
  When I find a select list while the script is executing
44
- Then I should be able to select "Test 2" from the list
44
+ Then I should see that the select list exists
45
+ And I should be able to select "Test 2" from the list
46
+
47
+ Scenario: Getting the selected option
48
+ When I select "Test 2" from the select list
49
+ Then the selected option should be "Test 2"
50
+
51
+ Scenario: Determining if a select list includes some option
52
+ Then the select list should include "Test 2"
53
+
54
+ Scenario: It should know if an option is selected
55
+ When I select "Test 2" from the select list
56
+ Then the select list should know that "Test 2" is selected
57
+
@@ -31,4 +31,5 @@ Feature: Span
31
31
 
32
32
  Scenario: Finding a span dynamically
33
33
  When I get the text from a span while the script is executing
34
- Then the text should be "My alert"
34
+ Then I should see that the span exists
35
+ And the text should be "My alert"
@@ -37,3 +37,7 @@ end
37
37
  Then /^I should be able to click the button element$/ do
38
38
  @button.click
39
39
  end
40
+
41
+ Then /^I should see that the button exists$/ do
42
+ @page.button_id?.should == true
43
+ end
@@ -29,3 +29,7 @@ end
29
29
  When /^I select the first check box while the script is executing$/ do
30
30
  @page.checkbox_element(:id => 'cb_id').check
31
31
  end
32
+
33
+ Then /^I should see that the checkbox exists$/ do
34
+ @page.button_id?.should == true
35
+ end
@@ -13,3 +13,7 @@ end
13
13
  When /^I get the text from a div while the script is executing$/ do
14
14
  @text = @page.div_element(:id => 'div_id').text
15
15
  end
16
+
17
+ Then /^I should see that the div exists$/ do
18
+ @page.div_id?.should == true
19
+ end
@@ -124,6 +124,14 @@ Then /^it should know it is not enabled$/ do
124
124
  @element.should_not be_enabled
125
125
  end
126
126
 
127
+ Then /^it should know that is it not disabled$/ do
128
+ @element.should_not be_disabled
129
+ end
130
+
131
+ Then /^it should know that it is disabled$/ do
132
+ @element.should be_disabled
133
+ end
134
+
127
135
  When /^I set the focus to the test text_field using the onfocus event$/ do
128
136
  @page.text_field_element(:id => 'onfocus_text_field').fire_event('onfocus')
129
137
  end
@@ -13,3 +13,7 @@ end
13
13
  When /^I locate a form while the script is executing$/ do
14
14
  @element = @page.form_element(:id => 'form_id')
15
15
  end
16
+
17
+ Then /^I should see that the form exists$/ do
18
+ @page.form_id?.should == true
19
+ end
@@ -10,7 +10,7 @@ When /^I search for the hidden field by "([^\"]*)"$/ do |how|
10
10
  @element = @page.send "hidden_field_#{how}_element"
11
11
  end
12
12
 
13
- Then /^hidden field element should contains "([^\"]*)"$/ do |text|
13
+ Then /^the hidden field element should contain "([^\"]*)"$/ do |text|
14
14
  @element.value.should == text
15
15
  end
16
16
 
@@ -21,3 +21,7 @@ end
21
21
  When /^I find a hidden field while the script is executing$/ do
22
22
  @element = @page.hidden_field_element(:id => 'hidden_field_id')
23
23
  end
24
+
25
+ Then /^I should see that the hidden field exists$/ do
26
+ @page.hidden_field_id?.should == true
27
+ end
@@ -21,3 +21,7 @@ end
21
21
  When /^I get the image element while the script is executing$/ do
22
22
  @element = @page.image_element(:id => 'image_id')
23
23
  end
24
+
25
+ Then /^I should see that the image exists$/ do
26
+ @page.image_id?.should == true
27
+ end
@@ -18,3 +18,9 @@ When /^I select a link while the script is executing$/ do
18
18
  link = @page.link_element(:id => 'link_id')
19
19
  link.click
20
20
  end
21
+
22
+ Then /^I should see that the link exists$/ do
23
+ require 'ruby-debug'
24
+ debugger
25
+ @page.link_id?.should == true
26
+ end
@@ -13,3 +13,7 @@ end
13
13
  When /^I search for the list item while the script is executing$/ do
14
14
  @text = @page.list_item_element(:id => 'li_id').text
15
15
  end
16
+
17
+ Then /^I should see that the list item exists$/ do
18
+ @page.li_id?.should == true
19
+ end
@@ -13,3 +13,7 @@ end
13
13
  When /^I search for the ordered list while the script is executing$/ do
14
14
  @list = @page.ordered_list_element(:id => 'ol_id')
15
15
  end
16
+
17
+ Then /^I should see that the ordered list exists$/ do
18
+ @page.ol_id?.should == true
19
+ end
@@ -14,3 +14,7 @@ end
14
14
  When /^I get the text from a paragraph while the script is executing$/ do
15
15
  @text = @page.paragraph_element(:id => 'p_id').text
16
16
  end
17
+
18
+ Then /^I should see that the paragraph exists$/ do
19
+ @page.p_id?.should == true
20
+ end
@@ -21,3 +21,7 @@ end
21
21
  When /^I select the radio button while the script is executing$/ do
22
22
  @page.radio_button_element(:id => 'milk_id').select
23
23
  end
24
+
25
+ Then /^I should see that the radio button exists$/ do
26
+ @page.milk_id?.should == true
27
+ end
@@ -23,6 +23,23 @@ When /^I find a select list while the script is executing$/ do
23
23
  @select_list = @page.select_list_element(:id => 'sel_list_id')
24
24
  end
25
25
 
26
- Then /^I should be able to select "([^"]*)" from the list$/ do |value|
26
+ Then /^I should be able to select "([^\"]*)" from the list$/ do |value|
27
27
  @select_list.select(value)
28
28
  end
29
+
30
+ Then /^I should see that the select list exists$/ do
31
+ @page.sel_list_id?.should == true
32
+ end
33
+
34
+ Then /^the selected option should be "([^\"]*)"$/ do |text|
35
+ @page.select_list_element(:id => 'sel_list_id').selected_options[0].should == text
36
+ end
37
+
38
+ Then /^the select list should include "([^\"]*)"$/ do |text|
39
+ @page.sel_list_id_element.should include text
40
+ end
41
+
42
+ Then /^the select list should know that "([^\"]*)" is selected$/ do |text|
43
+ @page.sel_list_id_element.selected?(text).should be_true
44
+ end
45
+
@@ -13,3 +13,7 @@ end
13
13
  When /^I get the text from a span while the script is executing$/ do
14
14
  @text = @page.span_element(:id => 'span_id').text
15
15
  end
16
+
17
+ Then /^I should see that the span exists$/ do
18
+ @page.span_id?.should == true
19
+ end
@@ -9,3 +9,7 @@ end
9
9
  When /^I retrieve a table cell element while the script is executing$/ do
10
10
  @cell_data = @page.cell_element(:id => 'cell_id').text
11
11
  end
12
+
13
+ Then /^I should see that the cell exists$/ do
14
+ @page.cell_id?.should == true
15
+ end
@@ -34,3 +34,7 @@ Then /^the data for the last row should be "([^\"]*)" and "([^\"]*)"$/ do |col1,
34
34
  @element.last_row[0].text.should == col1
35
35
  @element.last_row[1].text.should == col2
36
36
  end
37
+
38
+ Then /^I should see that the table exists$/ do
39
+ @page.table_id?.should == true
40
+ end
@@ -29,3 +29,7 @@ end
29
29
  When /^I clear the text area$/ do
30
30
  @page.text_area_id_element.clear
31
31
  end
32
+
33
+ Then /^I should see that the text area exists$/ do
34
+ @page.text_area_id?.should == true
35
+ end
@@ -22,6 +22,14 @@ When /^I find a text field while the script is executing$/ do
22
22
  @text_field = @page.text_field_element(:id => 'text_field_id')
23
23
  end
24
24
 
25
- Then /^I should be able to type "([^"]*)" into the field element$/ do |value|
25
+ Then /^I should be able to type "([^\"]*)" into the field element$/ do |value|
26
26
  @text_field.value = value
27
27
  end
28
+
29
+ Then /^I should see that the text field exists$/ do
30
+ @page.text_field_id?.should == true
31
+ end
32
+
33
+ When /^I append "([^\"]*)" to the text field$/ do |text|
34
+ @page.text_field_id_element.append text
35
+ end
@@ -14,3 +14,6 @@ When /^I search for the unordered list while the script is executing$/ do
14
14
  @list = @page.unordered_list_element(:id => 'ul_id')
15
15
  end
16
16
 
17
+ Then /^I should see that the unordered list exists$/ do
18
+ @page.ul_id?.should == true
19
+ end
@@ -49,4 +49,8 @@ Feature: Table
49
49
 
50
50
  Scenario: Finding a table dynamically
51
51
  When I retrieve a table element while the script is executing
52
- Then the data for row "1" should be "Data1" and "Data2"
52
+ And the data for row "1" should be "Data1" and "Data2"
53
+
54
+ @watir_only
55
+ Scenario: Finding an existing table
56
+ Then I should see that the table exists
@@ -40,4 +40,5 @@ Feature: Table Cell
40
40
 
41
41
  Scenario: Finding a table cell dynamically
42
42
  When I retrieve a table cell element while the script is executing
43
- Then the cell data should be 'Data4'
43
+ Then I should see that the cell exists
44
+ And the cell data should be 'Data4'
@@ -34,7 +34,8 @@ Feature: Text Area
34
34
 
35
35
  Scenario: Finding a text area dynamically
36
36
  When I find a text area while the script is executing
37
- Then I should be able to type "I found it" into the area element
37
+ Then I should see that the text area exists
38
+ And I should be able to type "I found it" into the area element
38
39
 
39
40
  Scenario: Clearing the text area
40
41
  When I type "abcdefghijklmnop" into the text area
@@ -41,4 +41,11 @@ Feature: Text Fields
41
41
 
42
42
  Scenario: Finding a text field dynamically
43
43
  When I find a text field while the script is executing
44
- Then I should be able to type "I found it" into the field element
44
+ Then I should see that the text field exists
45
+ And I should be able to type "I found it" into the field element
46
+
47
+ Scenario: Appending text to a text field
48
+ When I type "abcd" into the text field
49
+ And I append "efg" to the text field
50
+ Then the text field should contain "abcdefg"
51
+
@@ -34,5 +34,6 @@ Feature: Unordered list
34
34
 
35
35
  Scenario: Finding a unordered list dynamically
36
36
  When I search for the unordered list while the script is executing
37
- And I get the first item from the list
37
+ Then I should see that the unordered list exists
38
+ When I get the first item from the list
38
39
  Then the list items text should be "Item One"
@@ -45,13 +45,14 @@ module PageObject
45
45
  end
46
46
 
47
47
  #
48
- # adds three methods to the page object - one to set text in a text field,
49
- # another to retrieve text from a text field and another to return the text
50
- # field element.
48
+ # adds four methods to the page object - one to set text in a text field,
49
+ # another to retrieve text from a text field, another to return the text
50
+ # field element, another to check the text field's existence.
51
51
  #
52
52
  # @example
53
53
  # text_field(:first_name, :id => "first_name")
54
- # # will generate 'first_name', 'first_name=' and 'first_name_element' methods
54
+ # # will generate 'first_name', 'first_name=', 'first_name_element',
55
+ # # 'first_name?' methods
55
56
  #
56
57
  # @param [String] the name used for the generated methods
57
58
  # @param [Hash] identifier how we find a text field. You can use a multiple paramaters
@@ -81,16 +82,21 @@ module PageObject
81
82
  return call_block(&block) if block_given?
82
83
  platform.text_field_for(identifier.clone)
83
84
  end
85
+ define_method("#{name}?") do
86
+ return call_block(&block).exists? if block_given?
87
+ platform.text_field_for(identifier.clone).exists?
88
+ end
84
89
  alias_method "#{name}_text_field".to_sym, "#{name}_element".to_sym
85
90
  end
86
91
 
87
92
  #
88
- # adds two methods to the page object - one to get the text from a hidden field
89
- # and another to retrieve the hidden field element.
93
+ # adds three methods to the page object - one to get the text from a hidden field,
94
+ # another to retrieve the hidden field element, and another to check the hidden
95
+ # field's existence.
90
96
  #
91
97
  # @example
92
98
  # hidden_field(:user_id, :id => "user_identity")
93
- # # will generate 'user_id' and 'user_id_element' methods
99
+ # # will generate 'user_id', 'user_id_element' and 'user_id?' methods
94
100
  #
95
101
  # @param [String] the name used for the generated methods
96
102
  # @param [Hash] identifier how we find a hidden field. You can use a multiple paramaters
@@ -115,17 +121,22 @@ module PageObject
115
121
  return call_block(&block) if block_given?
116
122
  platform.hidden_field_for(identifier.clone)
117
123
  end
124
+ define_method("#{name}?") do
125
+ return call_block(&block).exists? if block_given?
126
+ platform.hidden_field_for(identifier.clone).exists?
127
+ end
118
128
  alias_method "#{name}_hidden_field".to_sym, "#{name}_element".to_sym
119
129
  end
120
130
 
121
131
  #
122
- # adds three methods to the page object - one to set text in a text area,
123
- # another to retrieve text from a text area and another to return the text
124
- # area element.
132
+ # adds four methods to the page object - one to set text in a text area,
133
+ # another to retrieve text from a text area, another to return the text
134
+ # area element, and another to check the text area's existence.
125
135
  #
126
136
  # @example
127
137
  # text_area(:address, :id => "address")
128
- # # will generate 'address', 'address=' and 'address_element methods
138
+ # # will generate 'address', 'address=', 'address_element',
139
+ # # 'address?' methods
129
140
  #
130
141
  # @param [String] the name used for the generated methods
131
142
  # @param [Hash] identifier how we find a text area. You can use a multiple paramaters
@@ -152,17 +163,22 @@ module PageObject
152
163
  return call_block(&block) if block_given?
153
164
  platform.text_area_for(identifier.clone)
154
165
  end
166
+ define_method("#{name}?") do
167
+ return call_block(&block).exists? if block_given?
168
+ platform.text_area_for(identifier.clone).exists?
169
+ end
155
170
  alias_method "#{name}_text_area".to_sym, "#{name}_element".to_sym
156
171
  end
157
172
 
158
173
  #
159
- # adds three methods - one to select an item in a drop-down,
160
- # another to fetch the currently selected item and another
161
- # to retrieve the select list element.
174
+ # adds four methods - one to select an item in a drop-down,
175
+ # another to fetch the currently selected item, another
176
+ # to retrieve the select list element, and another to check the
177
+ # drop down's existence.
162
178
  #
163
179
  # @example
164
180
  # select_list(:state, :id => "state")
165
- # # will generate 'state', 'state=' and 'state_element' methods
181
+ # # will generate 'state', 'state=', 'state_element', 'state?' methods
166
182
  #
167
183
  # @param [String] the name used for the generated methods
168
184
  # @param [Hash] identifier how we find a select list. You can use a multiple paramaters
@@ -189,17 +205,21 @@ module PageObject
189
205
  return call_block(&block) if block_given?
190
206
  platform.select_list_for(identifier.clone)
191
207
  end
208
+ define_method("#{name}?") do
209
+ return call_block(&block).exists? if block_given?
210
+ platform.select_list_for(identifier.clone).exists?
211
+ end
192
212
  alias_method "#{name}_select_list".to_sym, "#{name}_element".to_sym
193
213
  end
194
214
 
195
215
  #
196
- # adds two methods - one to select a link and another
216
+ # adds three methods - one to select a link, another
197
217
  # to return a PageObject::Elements::Link object representing
198
- # the link.
218
+ # the link, and another that checks the link's existence.
199
219
  #
200
220
  # @example
201
221
  # link(:add_to_cart, :text => "Add to Cart")
202
- # # will generate 'add_to_cart' and 'add_to_cart_element' methods
222
+ # # will generate 'add_to_cart', 'add_to_cart_element', and 'add_to_cart?' methods
203
223
  #
204
224
  # @param [String] the name used for the generated methods
205
225
  # @param [Hash] identifier how we find a link. You can use a multiple paramaters
@@ -224,17 +244,23 @@ module PageObject
224
244
  return call_block(&block) if block_given?
225
245
  platform.link_for(identifier.clone)
226
246
  end
247
+ define_method("#{name}?") do
248
+ return call_block(&block).exists? if block_given?
249
+ platform.link_for(identifier.clone).exists?
250
+ end
227
251
  alias_method "#{name}_link".to_sym, "#{name}_element".to_sym
228
252
  end
229
253
 
230
254
  #
231
- # adds four methods - one to check, another to uncheck, another
232
- # to return the state of a checkbox, and a final method to return
233
- # a PageObject::Elements::CheckBox object representing the checkbox.
255
+ # adds five methods - one to check, another to uncheck, another
256
+ # to return the state of a checkbox, another to return
257
+ # a PageObject::Elements::CheckBox object representing the checkbox, and
258
+ # a final method to check the checkbox's existence.
234
259
  #
235
260
  # @example
236
261
  # checkbox(:active, :name => "is_active")
237
- # # will generate 'check_active', 'uncheck_active', 'active_checked?' and 'active_element' methods
262
+ # # will generate 'check_active', 'uncheck_active', 'active_checked?',
263
+ # # 'active_element', and 'active?' methods
238
264
  #
239
265
  # @param [String] the name used for the generated methods
240
266
  # @param [Hash] identifier how we find a checkbox. You can use a multiple paramaters
@@ -264,18 +290,24 @@ module PageObject
264
290
  return call_block(&block) if block_given?
265
291
  platform.checkbox_for(identifier.clone)
266
292
  end
293
+ define_method("#{name}?") do
294
+ return call_block(&block).exists? if block_given?
295
+ platform.checkbox_for(identifier.clone).exists?
296
+ end
267
297
  alias_method "#{name}_checkbox".to_sym, "#{name}_element".to_sym
268
298
  end
269
299
 
270
300
  #
271
- # adds four methods - one to select, another to clear,
272
- # another to return if a radio button is selected, and
301
+ # adds five methods - one to select, another to clear,
302
+ # another to return if a radio button is selected,
273
303
  # another method to return a PageObject::Elements::RadioButton
274
- # object representing the radio button element
304
+ # object representing the radio button element, and another to check
305
+ # the radio button's existence.
275
306
  #
276
307
  # @example
277
308
  # radio_button(:north, :id => "north")
278
- # # will generate 'select_north', 'clear_north', 'north_selected?' and 'north_element' methods
309
+ # # will generate 'select_north', 'clear_north', 'north_selected?',
310
+ # # 'north_element', and 'north?' methods
279
311
  #
280
312
  # @param [String] the name used for the generated methods
281
313
  # @param [Hash] identifier how we find a radio button. You can use a multiple paramaters
@@ -305,16 +337,20 @@ module PageObject
305
337
  return call_block(&block) if block_given?
306
338
  platform.radio_button_for(identifier.clone)
307
339
  end
340
+ define_method("#{name}?") do
341
+ return call_block(&block).exists? if block_given?
342
+ platform.radio_button_for(identifier.clone).exists?
343
+ end
308
344
  alias_method "#{name}_radio_button".to_sym, "#{name}_element".to_sym
309
345
  end
310
346
 
311
347
  #
312
- # adds two methods - one to click a button and another to
313
- # return the button element.
348
+ # adds three methods - one to click a button, another to
349
+ # return the button element, and another to check the button's existence.
314
350
  #
315
351
  # @example
316
352
  # button(:purchase, :id => 'purchase')
317
- # # will generate 'purchase' and 'purchase_element' methods
353
+ # # will generate 'purchase', 'purchase_element', and 'purchase?' methods
318
354
  #
319
355
  # @param [String] the name used for the generated methods
320
356
  # @param [Hash] identifier how we find a button. You can use a multiple paramaters
@@ -339,16 +375,20 @@ module PageObject
339
375
  return call_block(&block) if block_given?
340
376
  platform.button_for(identifier.clone)
341
377
  end
378
+ define_method("#{name}?") do
379
+ return call_block(&block).exists? if block_given?
380
+ platform.button_for(identifier.clone).exists?
381
+ end
342
382
  alias_method "#{name}_button".to_sym, "#{name}_element".to_sym
343
383
  end
344
384
 
345
385
  #
346
- # adds two methods - one to retrieve the text from a div
347
- # and another to return the div element
386
+ # adds three methods - one to retrieve the text from a div,
387
+ # another to return the div element, and another to check the div's existence.
348
388
  #
349
389
  # @example
350
390
  # div(:message, :id => 'message')
351
- # # will generate 'message' and 'message_element' methods
391
+ # # will generate 'message', 'message_element', and 'message?' methods
352
392
  #
353
393
  # @param [String] the name used for the generated methods
354
394
  # @param [Hash] identifier how we find a div. You can use a multiple paramaters
@@ -370,16 +410,20 @@ module PageObject
370
410
  return call_block(&block) if block_given?
371
411
  platform.div_for(identifier.clone)
372
412
  end
413
+ define_method("#{name}?") do
414
+ return call_block(&block).exists? if block_given?
415
+ platform.div_for(identifier.clone).exists?
416
+ end
373
417
  alias_method "#{name}_div".to_sym, "#{name}_element".to_sym
374
418
  end
375
419
 
376
420
  #
377
- # adds two methods - one to retrieve the text from a span
378
- # and another to return the span element
421
+ # adds three methods - one to retrieve the text from a span,
422
+ # another to return the span element, and another to check the span's existence.
379
423
  #
380
424
  # @example
381
425
  # span(:alert, :id => 'alert')
382
- # # will generate 'alert' and 'alert_element' methods
426
+ # # will generate 'alert', 'alert_element', and 'alert?' methods
383
427
  #
384
428
  # @param [String] the name used for the generated methods
385
429
  # @param [Hash] identifier how we find a span. You can use a multiple paramaters
@@ -400,15 +444,21 @@ module PageObject
400
444
  return call_block(&block) if block_given?
401
445
  platform.span_for(identifier.clone)
402
446
  end
447
+ define_method("#{name}?") do
448
+ return call_block(&block).exists? if block_given?
449
+ platform.span_for(identifier.clone).exists?
450
+ end
403
451
  alias_method "#{name}_span".to_sym, "#{name}_element".to_sym
404
452
  end
405
453
 
406
454
  #
407
- # adds a method to retrieve the table element
455
+ # adds two methods - one to retrieve the table element, and another to
456
+ # check the table's existence. The existence method does not work
457
+ # on Selenium so it should not be called.
408
458
  #
409
459
  # @example
410
460
  # table(:cart, :id => 'shopping_cart')
411
- # # will generate a 'cart_element' method
461
+ # # will generate a 'cart_element' and 'cart?' method
412
462
  #
413
463
  # @param [String] the name used for the generated methods
414
464
  # @param [Hash] identifier how we find a table. You can use a multiple paramaters
@@ -425,16 +475,21 @@ module PageObject
425
475
  return call_block(&block) if block_given?
426
476
  platform.table_for(identifier.clone)
427
477
  end
478
+ define_method("#{name}?") do
479
+ return call_block(&block).exists? if block_given?
480
+ platform.table_for(identifier.clone).exists?
481
+ end
428
482
  alias_method "#{name}_table".to_sym, "#{name}_element".to_sym
429
483
  end
430
484
 
431
485
  #
432
- # adds two methods one to retrieve the text from a table cell
433
- # and another to return the table cell element
486
+ # adds three methods - one to retrieve the text from a table cell,
487
+ # another to return the table cell element, and another to check the cell's
488
+ # existence.
434
489
  #
435
490
  # @example
436
491
  # cell(:total, :id => 'total_cell')
437
- # # will generate 'total' and 'total_element' methods
492
+ # # will generate 'total', 'total_element', and 'total?' methods
438
493
  #
439
494
  # @param [String] the name used for the generated methods
440
495
  # @param [Hash] identifier how we find a cell. You can use a multiple paramaters
@@ -456,15 +511,20 @@ module PageObject
456
511
  return call_block(&block) if block_given?
457
512
  platform.cell_for(identifier.clone)
458
513
  end
514
+ define_method("#{name}?") do
515
+ return call_block(&block).exists? if block_given?
516
+ platform.cell_for(identifier.clone).exists?
517
+ end
459
518
  alias_method "#{name}_cell".to_sym, "#{name}_element".to_sym
460
519
  end
461
520
 
462
521
  #
463
- # adds a method to retrieve the image element
522
+ # adds two methods - one to retrieve the image element, and another to
523
+ # check the image's existence.
464
524
  #
465
525
  # @example
466
526
  # image(:logo, :id => 'logo')
467
- # # will generate a 'logo_element' method
527
+ # # will generate 'logo_element' and 'logo?' methods
468
528
  #
469
529
  # @param [String] the name used for the generated methods
470
530
  # @param [Hash] identifier how we find an image. You can use a multiple paramaters
@@ -483,15 +543,20 @@ module PageObject
483
543
  return call_block(&block) if block_given?
484
544
  platform.image_for(identifier.clone)
485
545
  end
546
+ define_method("#{name}?") do
547
+ return call_block(&block).exists? if block_given?
548
+ platform.image_for(identifier.clone).exists?
549
+ end
486
550
  alias_method "#{name}_image".to_sym, "#{name}_element".to_sym
487
551
  end
488
552
 
489
553
  #
490
- # adds a method to retrieve the form element
554
+ # adds two methods - one to retrieve the form element, and another to
555
+ # check the form's existence.
491
556
  #
492
557
  # @example
493
558
  # form(:login, :id => 'login')
494
- # # will generate a 'login_element' method
559
+ # # will generate 'login_element' and 'login?' methods
495
560
  #
496
561
  # @param [String] the name used for the generated methods
497
562
  # @param [Hash] identifier how we find a form. You can use a multiple paramaters
@@ -508,16 +573,21 @@ module PageObject
508
573
  return call_block(&block) if block_given?
509
574
  platform.form_for(identifier.clone)
510
575
  end
576
+ define_method("#{name}?") do
577
+ return call_block(&block).exists? if block_given?
578
+ platform.form_for(identifier.clone).exists?
579
+ end
511
580
  alias_method "#{name}_form".to_sym, "#{name}_element".to_sym
512
581
  end
513
582
 
514
583
  #
515
- # adds two methods - one to retrieve the text from a list item
516
- # and another to return the list item element
584
+ # adds three methods - one to retrieve the text from a list item,
585
+ # another to return the list item element, and another to check the list item's
586
+ # existence.
517
587
  #
518
588
  # @example
519
589
  # list_item(:item_one, :id => 'one')
520
- # # will generate 'item_one' and 'item_one_element' methods
590
+ # # will generate 'item_one', 'item_one_element', and 'item_one?' methods
521
591
  #
522
592
  # @param [String] the name used for the generated methods
523
593
  # @param [Hash] identifier how we find a list item. You can use a multiple paramaters
@@ -538,15 +608,20 @@ module PageObject
538
608
  return call_block(&block) if block_given?
539
609
  platform.list_item_for(identifier.clone)
540
610
  end
611
+ define_method("#{name}?") do
612
+ return call_block(&block).exists? if block_given?
613
+ platform.list_item_for(identifier.clone).exists?
614
+ end
541
615
  alias_method "#{name}_list_item".to_sym, "#{name}_element".to_sym
542
616
  end
543
617
 
544
618
  #
545
- # adds a method to retrieve the unordered list element
619
+ # adds two methods - one to retrieve the unordered list element, and another to
620
+ # check it's existence.
546
621
  #
547
622
  # @example
548
623
  # unordered_list(:menu, :id => 'main_menu')
549
- # # will generate a 'menu_element' method
624
+ # # will generate 'menu_element' and 'menu?' methods
550
625
  #
551
626
  # @param [String] the name used for the generated methods
552
627
  # @param [Hash] identifier how we find an unordered list. You can use a multiple paramaters
@@ -563,15 +638,20 @@ module PageObject
563
638
  return call_block(&block) if block_given?
564
639
  platform.unordered_list_for(identifier.clone)
565
640
  end
641
+ define_method("#{name}?") do
642
+ return call_block(&block).exists? if block_given?
643
+ platform.unordered_list_for(identifier.clone).exists?
644
+ end
566
645
  alias_method "#{name}_unordered_list".to_sym, "#{name}_element".to_sym
567
646
  end
568
647
 
569
648
  #
570
- # adds a method to retrieve the ordered list element
649
+ # adds two methods - one to retrieve the ordered list element, and another to
650
+ # test it's existence.
571
651
  #
572
652
  # @example
573
653
  # ordered_list(:top_five, :id => 'top')
574
- # # will generate a 'top_five_element' method
654
+ # # will generate 'top_five_element' and 'top_five?' methods
575
655
  #
576
656
  # @param [String] the name used for the generated methods
577
657
  # @param [Hash] identifier how we find an ordered list. You can use a multiple paramaters
@@ -588,15 +668,20 @@ module PageObject
588
668
  return call_block(&block) if block_given?
589
669
  platform.ordered_list_for(identifier.clone)
590
670
  end
671
+ define_method("#{name}?") do
672
+ return call_block(&block).exists? if block_given?
673
+ platform.ordered_list_for(identifier.clone).exists?
674
+ end
591
675
  alias_method "#{name}_ordered_list".to_sym, "#{name}_element".to_sym
592
676
  end
593
677
 
594
678
  #
595
- # adds a method to retrieve the text of a h1 and a h1 element
679
+ # adds three methods - one to retrieve the text of a h1 element, another to
680
+ # retrieve a h1 element, and another to check for it's existence.
596
681
  #
597
682
  # @example
598
683
  # h1(:title, :id => 'title')
599
- # # will generate a 'title' and 'title_element' method
684
+ # # will generate 'title', 'title_element', and 'title?' methods
600
685
  #
601
686
  # @param [String] the name used for the generated methods
602
687
  # @param [Hash] identifier how we find a H1. You can use a multiple paramaters
@@ -617,15 +702,20 @@ module PageObject
617
702
  return call_block(&block) if block_given?
618
703
  platform.h1_for(identifier.clone)
619
704
  end
705
+ define_method("#{name}?") do
706
+ return call_block(&block).exists? if block_given?
707
+ platform.h1_for(identifier.clone).exists?
708
+ end
620
709
  alias_method "#{name}_h1".to_sym, "#{name}_element".to_sym
621
710
  end
622
711
 
623
712
  #
624
- # adds a method to retrieve the text of a h2 and a h2 element
713
+ # adds three methods - one to retrieve the text of a h2 element, another
714
+ # to retrieve a h2 element, and another to check for it's existence.
625
715
  #
626
716
  # @example
627
717
  # h2(:title, :id => 'title')
628
- # # will generate a 'title' and 'title_element' method
718
+ # # will generate 'title', 'title_element', and 'title?' methods
629
719
  #
630
720
  # @param [String] the name used for the generated methods
631
721
  # @param [Hash] identifier how we find a H2. You can use a multiple paramaters
@@ -646,15 +736,20 @@ module PageObject
646
736
  return call_block(&block) if block_given?
647
737
  platform.h2_for(identifier.clone)
648
738
  end
739
+ define_method("#{name}?") do
740
+ return call_block(&block).exists? if block_given?
741
+ platform.h2_for(identifier.clone).exists?
742
+ end
649
743
  alias_method "#{name}_h2".to_sym, "#{name}_element".to_sym
650
744
  end
651
745
 
652
746
  #
653
- # adds a method to retrieve the text of a h3 and a h3 element
747
+ # adds three methods - one to retrieve the text of a h3 element,
748
+ # another to return a h3 element, and another to check for it's existence.
654
749
  #
655
750
  # @example
656
751
  # h3(:title, :id => 'title')
657
- # # will generate a 'title' and 'title_element' method
752
+ # # will generate 'title', 'title_element', and 'title?' methods
658
753
  #
659
754
  # @param [String] the name used for the generated methods
660
755
  # @param [Hash] identifier how we find a H3. You can use a multiple paramaters
@@ -675,15 +770,20 @@ module PageObject
675
770
  return call_block(&block) if block_given?
676
771
  platform.h3_for(identifier.clone)
677
772
  end
773
+ define_method("#{name}?") do
774
+ return call_block(&block).exists? if block_given?
775
+ platform.h3_for(identifier.clone).exists?
776
+ end
678
777
  alias_method "#{name}_h3".to_sym, "#{name}_element".to_sym
679
778
  end
680
779
 
681
780
  #
682
- # adds a method to retrieve the text of a h4 and a h4 element
781
+ # adds three methods - one to retrieve the text of a h4 element,
782
+ # another to return a h4 element, and another to check for it's existence.
683
783
  #
684
784
  # @example
685
785
  # h4(:title, :id => 'title')
686
- # # will generate a 'title' and 'title_element' method
786
+ # # will generate 'title', 'title_element', and 'title?' methods
687
787
  #
688
788
  # @param [String] the name used for the generated methods
689
789
  # @param [Hash] identifier how we find a H4. You can use a multiple paramaters
@@ -704,15 +804,20 @@ module PageObject
704
804
  return call_block(&block) if block_given?
705
805
  platform.h4_for(identifier.clone)
706
806
  end
807
+ define_method("#{name}?") do
808
+ return call_block(&block).exists? if block_given?
809
+ platform.h4_for(identifier.clone).exists?
810
+ end
707
811
  alias_method "#{name}_h4".to_sym, "#{name}_element".to_sym
708
812
  end
709
813
 
710
814
  #
711
- # adds a method to retrieve the text of a h5 and a h5 element
815
+ # adds three methods - one to retrieve the text of a h5 element,
816
+ # another to return a h5 element, and another to check for it's existence.
712
817
  #
713
818
  # @example
714
819
  # h5(:title, :id => 'title')
715
- # # will generate a 'title' and 'title_element' method
820
+ # # will generate 'title', 'title_element', and 'title?' methods
716
821
  #
717
822
  # @param [String] the name used for the generated methods
718
823
  # @param [Hash] identifier how we find a H5. You can use a multiple paramaters
@@ -733,15 +838,20 @@ module PageObject
733
838
  return call_block(&block) if block_given?
734
839
  platform.h5_for(identifier.clone)
735
840
  end
841
+ define_method("#{name}?") do
842
+ return call_block(&block).exists? if block_given?
843
+ platform.h5_for(identifier.clone).exists?
844
+ end
736
845
  alias_method "#{name}_h5".to_sym, "#{name}_element".to_sym
737
846
  end
738
847
 
739
848
  #
740
- # adds a method to retrieve the text of a h6 and a h6 element
849
+ # adds three methods - one to retrieve the text of a h6 element,
850
+ # another to return a h6 element, and another to check for it's existence.
741
851
  #
742
852
  # @example
743
853
  # h6(:title, :id => 'title')
744
- # # will generate a 'title' and 'title_element' method
854
+ # # will generate 'title', 'title_element', and 'title?' methods
745
855
  #
746
856
  # @param [String] the name used for the generated methods
747
857
  # @param [Hash] identifier how we find a H6. You can use a multiple paramaters
@@ -762,15 +872,20 @@ module PageObject
762
872
  return call_block(&block) if block_given?
763
873
  platform.h6_for(identifier.clone)
764
874
  end
875
+ define_method("#{name}?") do
876
+ return call_block(&block).exists? if block_given?
877
+ platform.h6_for(identifier.clone).exists?
878
+ end
765
879
  alias_method "#{name}_h6".to_sym, "#{name}_element".to_sym
766
880
  end
767
881
 
768
882
  #
769
- # adds a method to retrieve the text of a paragraph and a paragraph element
883
+ # adds three methods - one to retrieve the text of a paragraph, another
884
+ # to retrieve a paragraph element, and another to check the paragraph's existence.
770
885
  #
771
886
  # @example
772
887
  # paragraph(:title, :id => 'title')
773
- # # will generate a 'title' and 'title_element' method
888
+ # # will generate 'title', 'title_element', and 'title?' methods
774
889
  #
775
890
  # @param [String] the name used for the generated methods
776
891
  # @param [Hash] identifier how we find a paragraph. You can use a multiple paramaters
@@ -791,16 +906,20 @@ module PageObject
791
906
  return call_block(&block) if block_given?
792
907
  platform.paragraph_for(identifier.clone)
793
908
  end
909
+ define_method("#{name}?") do
910
+ return call_block(&block).exists? if block_given?
911
+ platform.paragraph_for(identifier.clone).exists?
912
+ end
794
913
  alias_method "#{name}_paragraph".to_sym, "#{name}_element".to_sym
795
914
  end
796
915
 
797
916
  #
798
- # adds a method to set the file for a file field and to retrieve
799
- # the file field element
917
+ # adds three methods - one to set the file for a file field, another to retrieve
918
+ # the file field element, and another to check it's existence.
800
919
  #
801
920
  # @example
802
921
  # file_field(:the_file, :id => 'file_to_upload')
803
- # # will generate a 'the_file=' and 'the_file_element' method
922
+ # # will generate 'the_file=', 'the_file_element', and 'the_file?' methods
804
923
  #
805
924
  # @param [String] the name used for the generated methods
806
925
  # @param [Hash] identifier how we find a file_field. You can use a multiple paramaters
@@ -822,6 +941,10 @@ module PageObject
822
941
  return call_block(&block) if block_given?
823
942
  platform.file_field_for(identifier.clone)
824
943
  end
944
+ define_method("#{name}?") do
945
+ return call_block(&block).exists? if block_given?
946
+ platform.file_field_for(identifier.clone).exists?
947
+ end
825
948
  end
826
949
  end
827
950
  end