page-object 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/ChangeLog +26 -2
  2. data/features/button.feature +5 -0
  3. data/features/check_box.feature +4 -2
  4. data/features/div.feature +4 -0
  5. data/features/form.feature +3 -0
  6. data/features/hidden_field.feature +4 -0
  7. data/features/image.feature +5 -0
  8. data/features/link.feature +4 -0
  9. data/features/list_item.feature +4 -0
  10. data/features/ordered_list.feature +5 -0
  11. data/features/radio_button.feature +4 -0
  12. data/features/select_list.feature +5 -1
  13. data/features/span.feature +4 -0
  14. data/features/step_definitions/accessor_steps.rb +0 -266
  15. data/features/step_definitions/button_steps.rb +23 -0
  16. data/features/step_definitions/check_box_steps.rb +31 -0
  17. data/features/step_definitions/div_steps.rb +15 -0
  18. data/features/step_definitions/element_steps.rb +0 -4
  19. data/features/step_definitions/form_steps.rb +15 -0
  20. data/features/step_definitions/hidden_field_steps.rb +23 -0
  21. data/features/step_definitions/image_steps.rb +23 -0
  22. data/features/step_definitions/link_steps.rb +20 -0
  23. data/features/step_definitions/list_item_steps.rb +15 -0
  24. data/features/step_definitions/ordered_list_steps.rb +15 -0
  25. data/features/step_definitions/radio_button_steps.rb +23 -0
  26. data/features/step_definitions/select_list_steps.rb +28 -0
  27. data/features/step_definitions/span_steps.rb +15 -0
  28. data/features/step_definitions/table_cell_steps.rb +11 -0
  29. data/features/step_definitions/table_steps.rb +12 -0
  30. data/features/step_definitions/text_area_steps.rb +27 -0
  31. data/features/step_definitions/text_field_steps.rb +27 -0
  32. data/features/step_definitions/unordered_list_steps.rb +16 -0
  33. data/features/table.feature +4 -0
  34. data/features/table_cell.feature +3 -0
  35. data/features/text_area.feature +4 -0
  36. data/features/text_field.feature +4 -0
  37. data/features/unordered_list.feature +5 -0
  38. data/lib/page-object.rb +8 -3
  39. data/lib/page-object/element_locators.rb +277 -0
  40. data/lib/page-object/platforms/selenium/page_object.rb +6 -5
  41. data/lib/page-object/platforms/watir/page_object.rb +2 -2
  42. data/lib/page-object/platforms/watir/text_area.rb +1 -1
  43. data/lib/page-object/version.rb +1 -1
  44. data/page-object.gemspec +2 -2
  45. data/spec/page-object/element_locators_spec.rb +113 -0
  46. data/spec/page-object/page-object_spec.rb +4 -4
  47. metadata +40 -5
@@ -0,0 +1,23 @@
1
+ When /^I click the button$/ do
2
+ @page.button_id
3
+ end
4
+
5
+ When /^I search for the button by "([^\"]*)"$/ do |how|
6
+ @how = how
7
+ end
8
+
9
+ When /^I search for the button by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @how = "#{param1}_#{param2}"
11
+ end
12
+
13
+ Then /^I should be able to click the button$/ do
14
+ @page.send "button_#{@how}"
15
+ end
16
+
17
+ When /^I find a button while the script is executing$/ do
18
+ @button = @page.button_element(:id => 'button_id')
19
+ end
20
+
21
+ Then /^I should be able to click the button element$/ do
22
+ @button.click
23
+ end
@@ -0,0 +1,31 @@
1
+ When /^I select the First check box$/ do
2
+ @page.check_cb_id
3
+ end
4
+
5
+ Then /^the First check box should be selected$/ do
6
+ @page.cb_id_checked?.should be_true
7
+ end
8
+
9
+ When /^I unselect the First check box$/ do
10
+ @page.uncheck_cb_id
11
+ end
12
+
13
+ Then /^the First check box should not be selected$/ do
14
+ @page.cb_id_checked?.should be_false
15
+ end
16
+
17
+ When /^I search for the check box by "([^\"]*)"$/ do |how|
18
+ @how = how
19
+ end
20
+
21
+ When /^I search for the check box by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
22
+ @how = "#{param1}_#{param2}"
23
+ end
24
+
25
+ Then /^I should be able to check the check box$/ do
26
+ @page.send "check_cb_#{@how}".to_sym
27
+ end
28
+
29
+ When /^I select the first check box while the script is executing$/ do
30
+ @page.checkbox_element(:id => 'cb_id').check
31
+ end
@@ -0,0 +1,15 @@
1
+ When /^I get the text from the div$/ do
2
+ @text = @page.div_id
3
+ end
4
+
5
+ When /^I search for the div by "([^\"]*)"$/ do |how|
6
+ @text = @page.send "div_#{how}".to_sym
7
+ end
8
+
9
+ When /^I search for the div by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @text = @page.send "div_#{param1}_#{param2}".to_sym
11
+ end
12
+
13
+ When /^I get the text from a div while the script is executing$/ do
14
+ @text = @page.div_element(:id => 'div_id').text
15
+ end
@@ -1,7 +1,3 @@
1
- When /^I select a link labeled "([^"]*)" and index "([^"]*)"$/ do |label, index|
2
- @page.send "#{label.downcase}#{index}".to_sym
3
- end
4
-
5
1
  When /^I retrieve a check box element$/ do
6
2
  @element = @page.cb_id_element
7
3
  end
@@ -0,0 +1,15 @@
1
+ Then /^I should be able to submit the form$/ do
2
+ @element.submit
3
+ end
4
+
5
+ When /^I locate the form by "([^\"]*)"$/ do |how|
6
+ @element = @page.send "form_#{how}_element"
7
+ end
8
+
9
+ When /^I locate the form using "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @element = @page.send "form_#{param1}_#{param2}_element"
11
+ end
12
+
13
+ When /^I locate a form while the script is executing$/ do
14
+ @element = @page.form_element(:id => 'form_id')
15
+ end
@@ -0,0 +1,23 @@
1
+ When /^I retrieve the hidden field element$/ do
2
+ @element = @page.hidden_field_id_element
3
+ end
4
+
5
+ Then /^I should see the hidden field contains "([^\"]*)"$/ do |text|
6
+ @page.hidden_field_id.should == text
7
+ end
8
+
9
+ When /^I search for the hidden field by "([^\"]*)"$/ do |how|
10
+ @element = @page.send "hidden_field_#{how}_element"
11
+ end
12
+
13
+ Then /^hidden field element should contains "([^\"]*)"$/ do |text|
14
+ @element.value.should == text
15
+ end
16
+
17
+ When /^I search for the hidden field by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
18
+ @element = @page.send "hidden_field_#{param1}_#{param2}_element"
19
+ end
20
+
21
+ When /^I find a hidden field while the script is executing$/ do
22
+ @element = @page.hidden_field_element(:id => 'hidden_field_id')
23
+ end
@@ -0,0 +1,23 @@
1
+ When /^I get the image element$/ do
2
+ @element = @page.image_id_image
3
+ end
4
+
5
+ Then /^the image should be "([^\"]*)" pixels wide$/ do |width|
6
+ @element.width.should == width.to_i
7
+ end
8
+
9
+ Then /^the image should be "([^\"]*)" pixels tall$/ do |height|
10
+ @element.height.should == height.to_i
11
+ end
12
+
13
+ When /^I get the image element by "([^\"]*)"$/ do |how|
14
+ @element = @page.send "image_#{how}_element"
15
+ end
16
+
17
+ When /^I get the image element by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
18
+ @element = @page.send "image_#{param1}_#{param2}_element"
19
+ end
20
+
21
+ When /^I get the image element while the script is executing$/ do
22
+ @element = @page.image_element(:id => 'image_id')
23
+ end
@@ -0,0 +1,20 @@
1
+ When /^I select the link labeled "([^\"]*)"$/ do |text|
2
+ @page.google_search_id
3
+ end
4
+
5
+ When /^I search for the link by "([^\"]*)"$/ do |how|
6
+ @how = how
7
+ end
8
+
9
+ Then /^I should be able to select the link$/ do
10
+ @page.send "google_search_#{@how}".to_sym
11
+ end
12
+
13
+ When /^I select a link labeled "([^"]*)" and index "([^"]*)"$/ do |label, index|
14
+ @page.send "#{label.downcase}#{index}".to_sym
15
+ end
16
+
17
+ When /^I select a link while the script is executing$/ do
18
+ link = @page.link_element(:id => 'link_id')
19
+ link.click
20
+ end
@@ -0,0 +1,15 @@
1
+ When /^I get the text from the list item$/ do
2
+ @text = @page.li_id
3
+ end
4
+
5
+ When /^I search for the list item by "([^\"]*)"$/ do |how|
6
+ @text = @page.send "li_#{how}"
7
+ end
8
+
9
+ When /^I search for the list item by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @text = @page.send "li_#{param1}_#{param2}"
11
+ end
12
+
13
+ When /^I search for the list item while the script is executing$/ do
14
+ @text = @page.list_item_element(:id => 'li_id').text
15
+ end
@@ -0,0 +1,15 @@
1
+ When /^I get the first item from the ordered list$/ do
2
+ @element = @page.ol_id_element[0]
3
+ end
4
+
5
+ When /^I search for the ordered list by "([^\"]*)"$/ do |how|
6
+ @list = @page.send "ol_#{how}_element"
7
+ end
8
+
9
+ When /^I search for the ordered list by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @list = @page.send "ol_#{param1}_#{param2}_element"
11
+ end
12
+
13
+ When /^I search for the ordered list while the script is executing$/ do
14
+ @list = @page.ordered_list_element(:id => 'ol_id')
15
+ end
@@ -0,0 +1,23 @@
1
+ When /^I select the "([^\"]*)" radio button$/ do |how|
2
+ @page.send "select_#{how.downcase}_id".to_sym
3
+ end
4
+
5
+ Then /^the "([^\"]*)" radio button should be selected$/ do |how|
6
+ @page.send "#{how.downcase}_id_selected?".to_sym
7
+ end
8
+
9
+ When /^I search for the radio button by "([^\"]*)"$/ do |how|
10
+ @how = how
11
+ end
12
+
13
+ When /^I search for the radio button by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
14
+ @how = "#{param1}_#{param2}"
15
+ end
16
+
17
+ When /^I select the radio button$/ do
18
+ @page.send "select_milk_#{@how}".to_sym
19
+ end
20
+
21
+ When /^I select the radio button while the script is executing$/ do
22
+ @page.radio_button_element(:id => 'milk_id').select
23
+ end
@@ -0,0 +1,28 @@
1
+ When /^I select "([^\"]*)" from the select list$/ do |text|
2
+ @page.sel_list_id = text
3
+ end
4
+
5
+ When /^I search for the select list by "([^\"]*)"$/ do |how|
6
+ @how = how
7
+ end
8
+
9
+ When /^I search for the select list by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @how = "#{param1}_#{param2}"
11
+ end
12
+
13
+ Then /^I should be able to select "([^\"]*)"$/ do |value|
14
+ @page.send "sel_list_#{@how}=".to_sym, value
15
+ end
16
+
17
+ Then /^the value for the selected item should be "([^\"]*)"$/ do |value|
18
+ result = @page.send "sel_list_#{@how}".to_sym
19
+ result.should == value
20
+ end
21
+
22
+ When /^I find a select list while the script is executing$/ do
23
+ @select_list = @page.select_list_element(:id => 'sel_list_id')
24
+ end
25
+
26
+ Then /^I should be able to select "([^"]*)" from the list$/ do |value|
27
+ @select_list.select(value)
28
+ end
@@ -0,0 +1,15 @@
1
+ When /^I get the text from the span$/ do
2
+ @text = @page.span_id
3
+ end
4
+
5
+ When /^I search for the span by "([^\"]*)"$/ do |how|
6
+ @text = @page.send "span_#{how}".to_sym
7
+ end
8
+
9
+ When /^I search for the span by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @text = @page.send "span_#{param1}_#{param2}".to_sym
11
+ end
12
+
13
+ When /^I get the text from a span while the script is executing$/ do
14
+ @text = @page.span_element(:id => 'span_id').text
15
+ end
@@ -0,0 +1,11 @@
1
+ When /^I search for the table cell by "([^\"]*)"$/ do |how|
2
+ @cell_data = @page.send "cell_#{how}"
3
+ end
4
+
5
+ When /^I retrieve a table cell element by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
6
+ @cell_data = @page.send "cell_#{param1}_#{param2}"
7
+ end
8
+
9
+ When /^I retrieve a table cell element while the script is executing$/ do
10
+ @cell_data = @page.cell_element(:id => 'cell_id').text
11
+ end
@@ -12,3 +12,15 @@ end
12
12
  Then /^the cell data should be '([^"]*)'$/ do |expected|
13
13
  @cell_data.should == expected
14
14
  end
15
+
16
+ When /^I retrieve a table element by "([^\"]*)"$/ do |how|
17
+ @element = @page.send "table_#{how}_element"
18
+ end
19
+
20
+ When /^I retrieve a table element by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
21
+ @element = @page.send "table_#{param1}_#{param2}_element"
22
+ end
23
+
24
+ When /^I retrieve a table element while the script is executing$/ do
25
+ @element = @page.table_element(:id => 'table_id')
26
+ end
@@ -0,0 +1,27 @@
1
+ When /^I type "([^\"]*)" into the text area$/ do |text|
2
+ @page.text_area_id = text
3
+ end
4
+
5
+ Then /^the text area should contain "([^\"]*)"$/ do |expected_text|
6
+ @page.text_area_id.should == expected_text
7
+ end
8
+
9
+ When /^I search for the text area by "([^\"]*)"$/ do |how|
10
+ @how = how
11
+ end
12
+
13
+ When /^I search for the text area by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
14
+ @how = "#{param1}_#{param2}"
15
+ end
16
+
17
+ Then /^I should be able to type "([^\"]*)" into the area$/ do |value|
18
+ @page.send "text_area_#{@how}=".to_sym, value
19
+ end
20
+
21
+ When /^I find a text area while the script is executing$/ do
22
+ @text_area = @page.text_area_element(:id => 'text_area_id')
23
+ end
24
+
25
+ Then /^I should be able to type "([^"]*)" into the area element$/ do |value|
26
+ @text_area.value = value
27
+ end
@@ -0,0 +1,27 @@
1
+ When /^I type "([^\"]*)" into the text field$/ do |text|
2
+ @page.text_field_id = text
3
+ end
4
+
5
+ Then /^the text field should contain "([^\"]*)"$/ do |expected_text|
6
+ @page.text_field_id.should == expected_text
7
+ end
8
+
9
+ When /^I search for the text field by "([^\"]*)"$/ do |how|
10
+ @how = how
11
+ end
12
+
13
+ When /^I search for the text field by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
14
+ @how = "#{param1}_#{param2}"
15
+ end
16
+
17
+ Then /^I should be able to type "([^\"]*)" into the field$/ do |value|
18
+ @page.send "text_field_#{@how}=".to_sym, value
19
+ end
20
+
21
+ When /^I find a text field while the script is executing$/ do
22
+ @text_field = @page.text_field_element(:id => 'text_field_id')
23
+ end
24
+
25
+ Then /^I should be able to type "([^"]*)" into the field element$/ do |value|
26
+ @text_field.value = value
27
+ end
@@ -0,0 +1,16 @@
1
+ When /^I get the first item from the unordered list$/ do
2
+ @element = @page.ul_id_element[0]
3
+ end
4
+
5
+ When /^I search for the unordered list by "([^\"]*)"$/ do |how|
6
+ @list = @page.send "ul_#{how}_element"
7
+ end
8
+
9
+ When /^I search for the unordered list by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
10
+ @list = @page.send "ul_#{param1}_#{param2}_element"
11
+ end
12
+
13
+ When /^I search for the unordered list while the script is executing$/ do
14
+ @list = @page.unordered_list_element(:id => 'ul_id')
15
+ end
16
+
@@ -44,3 +44,7 @@ Feature: Table
44
44
  | param1 | param2 |
45
45
  | class | index |
46
46
  | name | index |
47
+
48
+ Scenario: Finding a table dynamically
49
+ When I retrieve a table element while the script is executing
50
+ Then the data for row "1" should be "Data1" and "Data2"
@@ -38,3 +38,6 @@ Feature: Table Cell
38
38
  | class | index |
39
39
  | name | index |
40
40
 
41
+ Scenario: Finding a table cell dynamically
42
+ When I retrieve a table cell element while the script is executing
43
+ Then the cell data should be 'Data4'
@@ -31,3 +31,7 @@ Feature: Text Area
31
31
  | param1 | param2 |
32
32
  | class | index |
33
33
  | name | index |
34
+
35
+ Scenario: Finding a text area dynamically
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,3 +37,7 @@ Feature: Text Fields
37
37
  When I retrieve a text field
38
38
  Then I should know it exists
39
39
  And I should know it is visible
40
+
41
+ Scenario: Finding a text field dynamically
42
+ When I find a text field while the script is executing
43
+ Then I should be able to type "I found it" into the field element
@@ -31,3 +31,8 @@ Feature: Unordered list
31
31
  | param1 | param2 |
32
32
  | class | index |
33
33
  | name | index |
34
+
35
+ Scenario: Finding a unordered list dynamically
36
+ When I search for the unordered list while the script is executing
37
+ And I get the first item from the list
38
+ Then the list items text should be "Item One"
@@ -1,6 +1,7 @@
1
1
  require 'page-object/version'
2
2
  require 'page-object/accessors'
3
3
  require 'page-object/platforms'
4
+ require 'page-object/element_locators'
4
5
 
5
6
  #
6
7
  # Module that when included adds functionality to a page object. This module
@@ -32,6 +33,8 @@ require 'page-object/platforms'
32
33
  #
33
34
  module PageObject
34
35
  include LoadsPlatform
36
+ include ElementLocators
37
+
35
38
  # @return [Watir::Browser or Selenium::WebDriver::Driver] the platform browser passed to the constructor
36
39
  attr_reader :browser
37
40
  # @return [PageObject::WatirPageObject or PageObject::SeleniumPageObject] the platform page object
@@ -160,13 +163,15 @@ module PageObject
160
163
  #
161
164
  # @param [Hash] either :title or :url of the other window. The url does not need to
162
165
  # be the entire url - it can just be the page name like index.html
166
+ # @param block if present the block is executed and then execution is returned to the
167
+ # calling window
163
168
  #
164
- def attach_to_window(identifier)
169
+ def attach_to_window(identifier, &block)
165
170
  begin
166
- platform.attach_to_window(identifier)
171
+ platform.attach_to_window(identifier, &block)
167
172
  rescue
168
173
  sleep 1
169
- platform.attach_to_window(identifier)
174
+ platform.attach_to_window(identifier, &block)
170
175
  end
171
176
  end
172
177