page-object 0.0.2 → 0.0.3

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 (35) hide show
  1. data/ChangeLog +20 -2
  2. data/features/div.feature +1 -1
  3. data/features/element.feature +160 -0
  4. data/features/html/images/circle.png +0 -0
  5. data/features/html/static_elements.html +8 -0
  6. data/features/image.feature +32 -0
  7. data/features/span.feature +37 -0
  8. data/features/step_definitions/accessor_steps.rb +29 -3
  9. data/features/step_definitions/element_steps.rb +33 -0
  10. data/features/support/page.rb +13 -0
  11. data/lib/page-object/accessors.rb +32 -2
  12. data/lib/page-object/elements.rb +2 -0
  13. data/lib/page-object/elements/button.rb +13 -0
  14. data/lib/page-object/elements/element.rb +1 -0
  15. data/lib/page-object/elements/image.rb +26 -0
  16. data/lib/page-object/elements/link.rb +11 -0
  17. data/lib/page-object/elements/span.rb +12 -0
  18. data/lib/page-object/platforms/selenium_button.rb +13 -0
  19. data/lib/page-object/platforms/selenium_element.rb +63 -1
  20. data/lib/page-object/platforms/selenium_image.rb +22 -0
  21. data/lib/page-object/platforms/selenium_link.rb +13 -0
  22. data/lib/page-object/platforms/selenium_table.rb +1 -1
  23. data/lib/page-object/platforms/watir_element.rb +63 -1
  24. data/lib/page-object/platforms/watir_image.rb +20 -0
  25. data/lib/page-object/selenium_page_object.rb +29 -0
  26. data/lib/page-object/version.rb +1 -1
  27. data/lib/page-object/watir_page_object.rb +29 -0
  28. data/page-object.gemspec +2 -2
  29. data/spec/page-object/accessors_spec.rb +64 -0
  30. data/spec/page-object/elements/button_spec.rb +11 -0
  31. data/spec/page-object/elements/element_spec.rb +50 -0
  32. data/spec/page-object/elements/image_spec.rb +62 -0
  33. data/spec/page-object/elements/link_spec.rb +11 -0
  34. data/spec/page-object/elements/span_spec.rb +22 -0
  35. metadata +22 -4
data/ChangeLog CHANGED
@@ -1,4 +1,21 @@
1
- === Version 0.0.2
1
+ == Version 0.0.3 / 2011-06-02
2
+ * Enhancements
3
+ * Added support for the following elements
4
+ * span
5
+ * image
6
+
7
+ * Added the following methods to Element
8
+ * value
9
+ * ==
10
+ * tag_name
11
+ * attribute
12
+ * click
13
+
14
+ * Updated to use selenium-webdriver 0.2.1
15
+
16
+ * Updated to use watir-webdriver 0.2.4
17
+
18
+ === Version 0.0.2 / 2011-05-30
2
19
  * Enhancements
3
20
  * Added support for the following elements
4
21
  * div
@@ -6,7 +23,8 @@
6
23
  * table
7
24
  * table row
8
25
  * table cell
9
- * added #text to element
26
+
27
+ * Added text method to element
10
28
 
11
29
  === Version 0.0.1 / 2011-05-22
12
30
  * Enhancements
data/features/div.feature CHANGED
@@ -36,7 +36,7 @@ Feature: Div
36
36
 
37
37
 
38
38
  @selenium_only
39
- Scenario Outline: Locating divs on Watir only
39
+ Scenario Outline: Locating divs on Selenium only
40
40
  When I search for the div by "<search_by>"
41
41
  Then the text should be "page-object rocks!"
42
42
 
@@ -0,0 +1,160 @@
1
+ Feature: Elements
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Link element methods
7
+ When I retrieve a link element
8
+ Then I should know it exists
9
+ And I should know it is visible
10
+ And I should know its' text is "Google Search"
11
+ And I should know it is equal to itself
12
+ And I should know its' tag name is "a"
13
+ And I should know the attribute "readonly" is false
14
+ And I should be able to click it
15
+
16
+ @watir_only
17
+ Scenario: Link element methods for watir
18
+ When I retrieve a link element
19
+ Then I should know its' value is ""
20
+
21
+
22
+ Scenario: Button element methods
23
+ When I retrieve a button element
24
+ Then I should know it exists
25
+ And I should know it is visible
26
+ And I should know its' value is "Click Me"
27
+ And I should know it is equal to itself
28
+ And I should know its' tag name is "input"
29
+ And I should know the attribute "readonly" is false
30
+ And I should be able to click it
31
+
32
+ @watir_only
33
+ Scenario: Button element methods for watir
34
+ When I retrieve a button element
35
+ Then I should know its' text is "Click Me"
36
+
37
+ Scenario: Check Box element methods
38
+ When I retrieve a check box element
39
+ Then I should know it exists
40
+ And I should know it is visible
41
+ And I should know its' text is ""
42
+ And I should know its' value is "1"
43
+ And I should know it is equal to itself
44
+ And I should know its' tag name is "input"
45
+ And I should know the attribute "readonly" is false
46
+ And I should be able to click it
47
+
48
+ Scenario: Div element methods
49
+ When I retrieve the div element
50
+ Then I should know it exists
51
+ And I should know it is visible
52
+ And I should know its' text is "page-object rocks!"
53
+ And I should know it is equal to itself
54
+ And I should know its' tag name is "div"
55
+ And I should know the attribute "readonly" is false
56
+ And I should be able to click it
57
+
58
+ @watir_only
59
+ Scenario: Div element methods for watir
60
+ When I retrieve the div element
61
+ Then I should know its' value is ""
62
+
63
+ @selenium_only
64
+ Scenario: Div element methods for selenium
65
+ When I retrieve the div element
66
+ Then I should know its' value is nil
67
+
68
+ Scenario: Radio Button element methods
69
+ When I retrieve a radio button
70
+ Then I should know it exists
71
+ And I should know it is visible
72
+ And I should know its' text is ""
73
+ And I should know its' value is "Milk"
74
+ And I should know it is equal to itself
75
+ And I should know its' tag name is "input"
76
+ And I should know the attribute "readonly" is false
77
+ And I should be able to click it
78
+
79
+ Scenario: Select List element methods
80
+ When I retrieve a select list
81
+ Then I should know it exists
82
+ And I should know it is visible
83
+ And I should know its' text includes "Test 1"
84
+ And I should know its' value is "option1"
85
+ And I should know it is equal to itself
86
+ And I should know its' tag name is "select"
87
+ And I should know the attribute "readonly" is false
88
+ And I should be able to click it
89
+
90
+ Scenario: Table element methods
91
+ When I retrieve a table element
92
+ Then I should know it is visible
93
+ And I should know its' text includes "Data1"
94
+ And I should know it is equal to itself
95
+ And I should know its' tag name is "table"
96
+ And I should know the attribute "readonly" is false
97
+ And I should be able to click it
98
+
99
+ @watir_only
100
+ Scenario: Table element methods in watir
101
+ When I retrieve a table element
102
+ Then I should know it exists
103
+ And I should know its' value is ""
104
+
105
+ @selenium_only
106
+ Scenario: Table element methods in selenium
107
+ When I retrieve a table element
108
+ Then I should know its' value is nil
109
+
110
+ Scenario: Table Cell element methods
111
+ When I retrieve table cell
112
+ Then I should know it exists
113
+ And I should know it is visible
114
+ And I should know its' text includes "Data4"
115
+ And I should know it is equal to itself
116
+ And I should know its' tag name is "td"
117
+ And I should know the attribute "readonly" is false
118
+ And I should be able to click it
119
+
120
+ @watir_only
121
+ Scenario: Table Cell element methods in watir
122
+ When I retrieve table cell
123
+ Then I should know its' value is ""
124
+
125
+ @selenium_only
126
+ Scenario: Table Cell element methods in selenium
127
+ When I retrieve table cell
128
+ Then I should know its' value is nil
129
+
130
+ Scenario: Text Field element methods
131
+ When I retrieve a text field
132
+ Then I should know it exists
133
+ And I should know it is visible
134
+ And I should know its' text includes ""
135
+ And I should know its' value is ""
136
+ And I should know it is equal to itself
137
+ And I should know its' tag name is "input"
138
+ And I should know the attribute "readonly" is false
139
+ And I should be able to click it
140
+
141
+ Scenario: Image element methods
142
+ When I get the image element
143
+ Then I should know it exists
144
+ And I should know it is visible
145
+ And I should know its' text includes ""
146
+ And I should know it is equal to itself
147
+ And I should know its' tag name is "img"
148
+ And I should know the attribute "readonly" is false
149
+ And I should be able to click it
150
+
151
+ @watir_only
152
+ Scenario: Image element methods in watir
153
+ When I get the image element
154
+ Then I should know its' value is ""
155
+
156
+ @selenium_only
157
+ Scenario: Image element methods in selenium
158
+ When I get the image element
159
+ Then I should know its' value is nil
160
+
Binary file
@@ -32,6 +32,11 @@
32
32
  page-object rocks!
33
33
  </div>
34
34
 
35
+ <h3>Span</h3>
36
+ <span id="span_id" name="span_name" class="span_class">
37
+ My alert
38
+ </span>
39
+
35
40
  <h3>Table</h3>
36
41
  <table id='table_id' name='table_name' class='table_class' border='1'>
37
42
  <tr>
@@ -46,6 +51,9 @@
46
51
  <form method="get" action="success.html">
47
52
  <input id='button_id' name='button_name' class='button_class' type="submit" value="Click Me">
48
53
  </form>
54
+
55
+ <h3>Image</h3>
56
+ <img src="images/circle.png" id="image_id" name="image_name" class="image_class">
49
57
  </body>
50
58
  </html>
51
59
 
@@ -0,0 +1,32 @@
1
+ Feature: Image
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Getting the image element
7
+ When I get the image element
8
+ Then the image should be "106" pixels wide
9
+ And the image should be "106" pixels tall
10
+
11
+ Scenario Outline: Locating an image on the page
12
+ When I get the image element by "<search_by>"
13
+ Then the image should be "106" pixels wide
14
+ And the image should be "106" pixels tall
15
+
16
+ Scenarios:
17
+ | search_by |
18
+ | id |
19
+ | class |
20
+ | name |
21
+ | xpath |
22
+
23
+ @watir_only
24
+ Scenario Outline: Locating an image on the page with Watir
25
+ When I get the image element by "<search_by>"
26
+ Then the image should be "106" pixels wide
27
+ And the image should be "106" pixels tall
28
+
29
+ Scenarios:
30
+ | search_by |
31
+ | index |
32
+
@@ -0,0 +1,37 @@
1
+ Feature: Span
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Getting the text from a span
7
+ When I get the text from the span
8
+ Then the text should be "My alert"
9
+
10
+ Scenario Outline: Locating spans on the page
11
+ When I search for the span by "<search_by>"
12
+ Then the text should be "My alert"
13
+
14
+ Scenarios:
15
+ | search_by |
16
+ | id |
17
+ | class |
18
+ | xpath |
19
+
20
+ @watir_only
21
+ Scenario Outline: Locating span on Watir only
22
+ When I search for the span by "<search_by>"
23
+ Then the text should be "My alert"
24
+
25
+ Scenarios:
26
+ | search_by |
27
+ | index |
28
+
29
+
30
+ @selenium_only
31
+ Scenario Outline: Locating span on Watir only
32
+ When I search for the span by "<search_by>"
33
+ Then the text should be "My alert"
34
+
35
+ Scenarios:
36
+ | search_by |
37
+ | name |
@@ -88,17 +88,26 @@ When /^I select the radio button$/ do
88
88
  end
89
89
 
90
90
  When /^I get the text from the div$/ do
91
- @div_text = @page.div_id
91
+ @text = @page.div_id
92
92
  end
93
93
 
94
94
  Then /^the text should be "([^"]*)"$/ do |expected_text|
95
- @div_text.should == expected_text
95
+ @text.should == expected_text
96
96
  end
97
97
 
98
98
  When /^I search for the div by "([^"]*)"$/ do |how|
99
- @div_text = @page.send "div_#{how}".to_sym
99
+ @text = @page.send "div_#{how}".to_sym
100
100
  end
101
101
 
102
+ When /^I get the text from the span$/ do
103
+ @text = @page.span_id
104
+ end
105
+
106
+ When /^I search for the span by "([^"]*)"$/ do |how|
107
+ @text = @page.send "span_#{how}".to_sym
108
+ end
109
+
110
+
102
111
  When /^I click the button$/ do
103
112
  @page.button_id
104
113
  end
@@ -123,3 +132,20 @@ end
123
132
  When /^I retrieve a table element by "([^"]*)"$/ do |how|
124
133
  @element = @page.send "table_#{how}_table"
125
134
  end
135
+
136
+ When /^I get the image element$/ do
137
+ @element = @page.image_id_image
138
+ end
139
+
140
+ Then /^the image should be "([^"]*)" pixels wide$/ do |width|
141
+ @element.width.should == width.to_i
142
+ end
143
+
144
+ Then /^the image should be "([^"]*)" pixels tall$/ do |height|
145
+ @element.height.should == height.to_i
146
+ end
147
+
148
+ When /^I get the image element by "([^"]*)"$/ do |how|
149
+ @element = @page.send "image_#{how}_image"
150
+ end
151
+
@@ -44,3 +44,36 @@ Then /^I should know it is visible$/ do
44
44
  @element.should be_visible
45
45
  end
46
46
 
47
+ Then /^I should know its' text is "([^"]*)"$/ do |text|
48
+ @element.text.should == text
49
+ end
50
+
51
+ Then /^I should know its' text includes "([^"]*)"$/ do |text|
52
+ @element.text.should include text
53
+ end
54
+
55
+ Then /^I should know its' value is "([^"]*)"$/ do |value|
56
+ @element.value.should == value
57
+ end
58
+
59
+ Then /^I should know its' value is nil$/ do
60
+ @element.value.should be_nil
61
+ end
62
+
63
+ Then /^I should know it is equal to itself$/ do
64
+ @element.should == @element
65
+ end
66
+
67
+ Then /^I should know its' tag name is "([^"]*)"$/ do |tagname|
68
+ @element.tag_name.should == tagname
69
+ end
70
+
71
+ Then /^I should know the attribute "([^"]*)" is false$/ do |attr_name|
72
+ @attr = @element.attribute(attr_name)
73
+ @attr.should be_false if @attr.is_a? FalseClass
74
+ @attr.should == "false" if @attr.is_a? String
75
+ end
76
+
77
+ Then /^I should be able to click it$/ do
78
+ @element.click
79
+ end
@@ -49,6 +49,12 @@ class Page
49
49
  div(:div_index, :index => 0)
50
50
  div(:div_xpath, :xpath => '//div')
51
51
 
52
+ span(:span_id, :id => 'span_id')
53
+ span(:span_name, :name => 'span_name')
54
+ span(:span_class, :class => 'span_class')
55
+ span(:span_index, :index => 0)
56
+ span(:span_xpath, :xpath => '//span')
57
+
52
58
  table(:table_id, :id => 'table_id')
53
59
  table(:table_name, :name => 'table_name')
54
60
  table(:table_class, :class => 'table_class')
@@ -67,4 +73,11 @@ class Page
67
73
  button(:button_index, :index => 0)
68
74
  button(:button_xpath, :xpath=> "//input[@type='submit']")
69
75
  button(:button_text, :text => 'Click Me')
76
+
77
+ image(:image_id, :id => 'image_id')
78
+ image(:image_name, :name => 'image_name')
79
+ image(:image_class, :class => 'image_class')
80
+ image(:image_index, :index => 0)
81
+ image(:image_xpath, :xpath => '//img')
82
+
70
83
  end
@@ -196,7 +196,7 @@ module PageObject
196
196
  # will generate a 'message' and 'message_div' methods
197
197
  #
198
198
  # @param the name used for the generated methods
199
- # @param identifier how we find a checkbox. The valid values are:
199
+ # @param identifier how we find a div. The valid values are:
200
200
  # :class => Watir and Selenium
201
201
  # :id => Watir and Selenium
202
202
  # :index => Watir only
@@ -204,7 +204,7 @@ module PageObject
204
204
  # :xpath => Watir and Selenium
205
205
  #
206
206
  def div(name, identifier)
207
- define_method("#{name}") do
207
+ define_method(name) do
208
208
  platform.div_text_for identifier
209
209
  end
210
210
  define_method("#{name}_div") do
@@ -212,6 +212,30 @@ module PageObject
212
212
  end
213
213
  end
214
214
 
215
+ #
216
+ # adds two methods - one to retrieve the text from a span
217
+ # and another to return the span element
218
+ #
219
+ # Example: span(:alert, {:id => 'alert'})
220
+ # will generate a 'alert' and 'alert_div' methods
221
+ #
222
+ # @param the name used for the generated methods
223
+ # @param identifier how we find a span. The valid values are:
224
+ # :class => Watir and Selenium
225
+ # :id => Watir and Selenium
226
+ # :index => Watir only
227
+ # :name => Selenium only
228
+ # :xpath => Watir and Selenium
229
+ #
230
+ def span(name, identifier)
231
+ define_method(name) do
232
+ platform.span_text_for identifier
233
+ end
234
+ define_method("#{name}_span") do
235
+ platform.span_for identifier
236
+ end
237
+ end
238
+
215
239
  #
216
240
  # adds a method to retrieve the table element
217
241
  #
@@ -255,5 +279,11 @@ module PageObject
255
279
  platform.cell_for identifier
256
280
  end
257
281
  end
282
+
283
+ def image(name, identifier)
284
+ define_method("#{name}_image") do
285
+ platform.image_for identifier
286
+ end
287
+ end
258
288
  end
259
289
  end