page-object 0.2.1 → 0.2.2

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.
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ === Version 0.2.2 / 2011-07-31
2
+ * Enhancements
3
+ * Can find frame by name
4
+ * Added #clear method to Element
5
+ * Removed #switch_to_from from PageObject
6
+ * Added #in_frame to Accessors to handle frame and iframe access
7
+ * Fixes
8
+ * Clearing value from text_field before setting value on Selenium
9
+
1
10
  === Version 0.2.1 / 2011-07-29
2
11
  * Enhancements
3
12
  * Added ability to locate div by the contained text
@@ -0,0 +1,8 @@
1
+ Feature: Elements
2
+
3
+ Scenario: Clear an element
4
+ Given I am on the static elements page
5
+ When I type "abcDEF" into the text field
6
+ Then the text field should contain "abcDEF"
7
+ When I clear the text field
8
+ Then the text field should contain ""
@@ -1,12 +1,37 @@
1
1
  Feature: Handling frames
2
2
 
3
- Background:
3
+ Scenario: Accessing elements within the frame
4
4
  Given I am on the frame elements page
5
+ When I type "page-object" into the text field for frame 2 using "id"
6
+ Then I should verify "page-object" is in the text field for frame 2 using "id"
7
+ When I type "page-object" into the text field for frame 2 using "name"
8
+ Then I should verify "page-object" is in the text field for frame 2 using "name"
9
+ When I type "page-object" into the text field for frame 2 using "index"
10
+ Then I should verify "page-object" is in the text field for frame 2 using "index"
5
11
 
6
- Scenario: Switching to a frame by id
7
- When I switch to a frame using id "frame_2"
8
- Then I should see "Frame 2" in the frame
12
+ Scenario: Switching between frames
13
+ Given I am on the frame elements page
14
+ When I type "page-object" into the text field for frame 2 using "id"
15
+ And I type "page-object" into the text field from frame 1 using "id"
16
+ Then I should verify "page-object" is in the text field for frame 2 using "id"
17
+ And I should verify "page-object" is in the text field for frame 1 using "id"
18
+
19
+ Scenario: Accessing elements within the frame
20
+ Given I am on the iframe elements page
21
+ When I type "page-object" into the text field for frame 2 using "id"
22
+ Then I should verify "page-object" is in the text field for frame 2 using "id"
23
+ When I type "page-object" into the text field for frame 2 using "name"
24
+ Then I should verify "page-object" is in the text field for frame 2 using "name"
25
+ When I type "page-object" into the text field for frame 2 using "index"
26
+ Then I should verify "page-object" is in the text field for frame 2 using "index"
9
27
 
10
- Scenario: Switching to a frame by index
11
- When I switch to a frame using index "1"
12
- Then I should see "Frame 2" in the frame
28
+ Scenario: Switching between frames
29
+ Given I am on the iframe elements page
30
+ When I type "page-object" into the text field for frame 2 using "id"
31
+ And I type "page-object" into the text field from frame 1 using "id"
32
+ Then I should verify "page-object" is in the text field for frame 2 using "id"
33
+ And I should verify "page-object" is in the text field for frame 1 using "id"
34
+
35
+ Scenario: Nested frames
36
+ Given I am on the nested frame elements page
37
+ Then I should be able to click the nested link
@@ -0,0 +1 @@
1
+ frame 1
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ <iframe id="three" src="nested_frame_3.html"></iframe>
9
+ </p>
10
+ </body>
11
+ </html>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
+ <title>
6
+ Title
7
+ </title>
8
+ </head>
9
+ <body>
10
+ <p>
11
+ <a id="four" href="success.html" target="_top">this link should open the page success page</a>
12
+ </p>
13
+ </body>
14
+ </html>
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <frameset cols="20%, 80%">
7
+ <frame id="one" src="nested_frame_1.html">
8
+ <frame id="two" src="nested_frame_2.html">
9
+ </frameset>
10
+ </html>
@@ -104,3 +104,7 @@ end
104
104
  When /^I retrieve an ordered list element$/ do
105
105
  @element = @page.ol_id_ordered_list
106
106
  end
107
+
108
+ When /^I clear the text field$/ do
109
+ @page.text_field_id_text_field.clear
110
+ end
@@ -1,5 +1,26 @@
1
1
  class FramePage
2
2
  include PageObject
3
+
4
+ in_frame(:index => 1) do |frame|
5
+ text_field(:text_field_2_index, :name => 'recieverElement', :frame => frame)
6
+ end
7
+ in_frame(:index => 0) do |frame|
8
+ text_field(:text_field_1_index, :name => 'senderElement', :frame => frame)
9
+ end
10
+
11
+ in_frame(:id => 'frame_2') do |frame|
12
+ text_field(:text_field_2_id, :name => 'recieverElement', :frame => frame)
13
+ end
14
+ in_frame(:id => 'frame_1') do |frame|
15
+ text_field(:text_field_1_id, :name => 'senderElement', :frame => frame)
16
+ end
17
+
18
+ in_frame(:name => 'frame2') do |frame|
19
+ text_field(:text_field_2_name, :name => 'recieverElement', :frame => frame)
20
+ end
21
+ in_frame(:name => 'frame1') do |frame|
22
+ text_field(:text_field_1_name, :name => 'senderElement', :frame => frame)
23
+ end
3
24
  end
4
25
 
5
26
  Given /^I am on the frame elements page$/ do
@@ -7,15 +28,46 @@ Given /^I am on the frame elements page$/ do
7
28
  @page.navigate_to(UrlHelper.frame_elements)
8
29
  end
9
30
 
10
- When /^I switch to a frame using id "([^"]*)"$/ do |id|
11
- @page.switch_to_frame(id)
31
+ Given /^I am on the iframe elements page$/ do
32
+ @page = FramePage.new(@browser)
33
+ @page.navigate_to(UrlHelper.iframe_elements)
34
+ end
35
+
36
+ When /^I type "([^"]*)" into the text field for frame 2 using "([^"]*)"$/ do |text, arg_type|
37
+ @page.send "text_field_2_#{arg_type}=".to_sym, text
38
+ end
39
+
40
+ Then /^I should verify "([^"]*)" is in the text field for frame 2 using "([^"]*)"$/ do |text, arg_type|
41
+ result = @page.send "text_field_2_#{arg_type}".to_sym
42
+ result.should == text
43
+ end
44
+
45
+ When /^I type "([^"]*)" into the text field from frame 1 using "([^"]*)"$/ do |text, arg_type|
46
+ @page.send "text_field_1_#{arg_type}=".to_sym, text
47
+ end
48
+
49
+ Then /^I should verify "([^"]*)" is in the text field for frame 1 using "([^"]*)"$/ do |text, arg_type|
50
+ result = @page.send "text_field_1_#{arg_type}".to_sym
51
+ result.should == text
52
+ end
53
+
54
+ class NestedFramePage
55
+ include PageObject
56
+
57
+ in_frame(:id => 'two') do |frame|
58
+ in_frame({:id => 'three'}, frame) do |nested_frame|
59
+ link(:nested_link, :id => 'four', :frame => nested_frame)
60
+ end
61
+ end
12
62
  end
13
63
 
14
- Then /^I should see "([^"]*)" in the frame$/ do |text|
15
- @page.text.should include text
64
+ Given /^I am on the nested frame elements page$/ do
65
+ @page = NestedFramePage.new(@browser)
66
+ @page.navigate_to(UrlHelper.nested_frame_elements)
16
67
  end
17
68
 
18
- When /^I switch to a frame using index "([^"]*)"$/ do |index|
19
- @page.switch_to_frame(index.to_i)
69
+ Then /^I should be able to click the nested link$/ do
70
+ @page.nested_link
71
+ @page.text.should include "Success"
20
72
  end
21
73
 
@@ -16,5 +16,13 @@ module UrlHelper
16
16
  def frame_elements
17
17
  "#{files}/frames.html"
18
18
  end
19
+
20
+ def iframe_elements
21
+ "#{files}/iframes.html"
22
+ end
23
+
24
+ def nested_frame_elements
25
+ "#{files}/nested_frames.html"
26
+ end
19
27
  end
20
28
  end
data/lib/page-object.rb CHANGED
@@ -162,16 +162,6 @@ module PageObject
162
162
  platform.attach_to_window(identifier)
163
163
  end
164
164
 
165
- #
166
- # Switch to a frame within the current context.
167
- #
168
- # @param [String or Fixnum] you can pass the index (zero based) or id for the frame
169
- # you wish to switch to.
170
- #
171
- def switch_to_frame(identifier)
172
- platform.switch_to_frame identifier
173
- end
174
-
175
165
  #
176
166
  # Refresh to current page
177
167
  #
@@ -20,6 +20,29 @@ module PageObject
20
20
  platform.navigate_to url
21
21
  end
22
22
  end
23
+
24
+ #
25
+ # Identify an element as existing within a frame or iframe. A frame parameter
26
+ # is passed to the block and must be passed to the other calls to PageObject.
27
+ # You can nest calls to in_frame by passing the frame to the next level.
28
+ #
29
+ # @example
30
+ # in_frame(:id => 'frame_id') do |frame|
31
+ # text_field(:first_name, :id => 'fname', :frame => frame)
32
+ # end
33
+ #
34
+ # @param [Hash] identifier how we find the frame. The valid keys are:
35
+ # * :id => Watir and Selenium
36
+ # * :index => Watir and Selenium
37
+ # * :name => Watir and Selenium
38
+ # @param frame passed from a previous call to in_frame. Used to nest calls
39
+ # @param block that contains the calls to elements that exist inside the frame.
40
+ #
41
+ def in_frame(identifier, frame=nil, &block)
42
+ frame = [] if frame.nil?
43
+ frame << identifier
44
+ block.call(frame)
45
+ end
23
46
 
24
47
  #
25
48
  # adds three methods to the page object - one to set text in a text field,
@@ -0,0 +1,5 @@
1
+ class String
2
+ def is_integer
3
+ true if Integer(self) rescue false
4
+ end
5
+ end
@@ -137,31 +137,42 @@ module PageObject
137
137
  wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
138
138
  wait.until &block
139
139
  end
140
- #
141
- # Waits until the block returns true
142
- #
143
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
144
- # @param [String] the message to display if the event timeouts
145
- # @param the block to execute when the event occurrs
146
- #
147
- def wait_until(timeout=5, message=nil, &block)
148
- wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
149
- wait.until &block
150
- end
140
+
141
+ #
142
+ # Waits until the block returns true
143
+ #
144
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
145
+ # @param [String] the message to display if the event timeouts
146
+ # @param the block to execute when the event occurrs
147
+ #
148
+ def wait_until(timeout=5, message=nil, &block)
149
+ wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
150
+ wait.until &block
151
+ end
151
152
 
152
- #
153
- # Send keystrokes to this element
154
- #
155
- # @param [String, Symbol, Array]
156
- #
157
- # Examples:
158
- #
159
- # element.send_keys "foo" #=> value: 'foo'
160
- # element.send_keys "tet", :arrow_left, "s" #=> value: 'test'
161
- # element.send_keys [:control, 'a'], :space #=> value: ' '
162
- #
163
- # @see Selenium::WebDriver::Keys::KEYS
164
- #
153
+ #
154
+ # Send keystrokes to this element
155
+ #
156
+ # @param [String, Symbol, Array]
157
+ #
158
+ # Examples:
159
+ #
160
+ # element.send_keys "foo" #=> value: 'foo'
161
+ # element.send_keys "tet", :arrow_left, "s" #=> value: 'test'
162
+ # element.send_keys [:control, 'a'], :space #=> value: ' '
163
+ #
164
+ # @see Selenium::WebDriver::Keys::KEYS
165
+ #
166
+ def send_keys(*args)
167
+ @element.send_keys(*args)
168
+ end
169
+
170
+ #
171
+ # clear the contents of the element
172
+ #
173
+ def clear
174
+ @element.clear
175
+ end
165
176
  end
166
177
  end
167
178
  end
@@ -1,4 +1,5 @@
1
1
  require 'page-object/elements'
2
+ require 'page-object/core_ext/string'
2
3
 
3
4
  module PageObject
4
5
  module Platforms
@@ -104,14 +105,6 @@ module PageObject
104
105
  end
105
106
  end
106
107
 
107
- #
108
- # platform method to handle switching to a frame
109
- # See PageObject#switch_to_frame
110
- #
111
- def switch_to_frame(identifier)
112
- @browser.switch_to.frame(identifier)
113
- end
114
-
115
108
  #
116
109
  # platform method to refresh the page
117
110
  # See PageObject#refresh
@@ -125,9 +118,13 @@ module PageObject
125
118
  # See PageObject::Accessors#text_field
126
119
  #
127
120
  def text_field_value_for(identifier)
121
+ frame_identifiers = identifier.delete(:frame)
128
122
  identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
129
123
  how, what = Elements::TextField.selenium_identifier_for identifier
130
- @browser.find_element(how, what).attribute('value')
124
+ switch_to_frame(frame_identifiers)
125
+ text = @browser.find_element(how, what).attribute('value')
126
+ @browser.switch_to.default_content
127
+ text
131
128
  end
132
129
 
133
130
  #
@@ -135,9 +132,13 @@ module PageObject
135
132
  # See PageObject::Accessors#text_field
136
133
  #
137
134
  def text_field_value_set(identifier, value)
135
+ frame_identifiers = identifier.delete(:frame)
138
136
  identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
139
137
  how, what = Elements::TextField.selenium_identifier_for identifier
138
+ switch_to_frame(frame_identifiers)
139
+ @browser.find_element(how, what).clear
140
140
  @browser.find_element(how, what).send_keys(value)
141
+ @browser.switch_to.default_content
141
142
  end
142
143
 
143
144
  #
@@ -145,9 +146,12 @@ module PageObject
145
146
  # See PageObject::Accessors#text_field
146
147
  #
147
148
  def text_field_for(identifier)
149
+ frame_identifiers = identifier.delete(:frame)
148
150
  identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
149
151
  how, what = Elements::TextField.selenium_identifier_for identifier
152
+ switch_to_frame(frame_identifiers)
150
153
  element = @browser.find_element(how, what)
154
+ @browser.switch_to.default_content
151
155
  Object::PageObject::Elements::TextField.new(element, :platform => :selenium)
152
156
  end
153
157
 
@@ -156,9 +160,13 @@ module PageObject
156
160
  # See PageObject::Accessors#hidden_field
157
161
  #
158
162
  def hidden_field_value_for(identifier)
163
+ frame_identifiers = identifier.delete(:frame)
159
164
  identifier = add_tagname_if_needed identifier, 'input', :type => 'hidden'
160
165
  how, what = Elements::HiddenField.selenium_identifier_for identifier
161
- @browser.find_element(how, what).attribute('value')
166
+ switch_to_frame(frame_identifiers)
167
+ value = @browser.find_element(how, what).attribute('value')
168
+ @browser.switch_to.default_content
169
+ value
162
170
  end
163
171
 
164
172
  #
@@ -166,9 +174,12 @@ module PageObject
166
174
  # See PageObject::Accessors#hidden_field
167
175
  #
168
176
  def hidden_field_for(identifier)
177
+ frame_identifiers = identifier.delete(:frame)
169
178
  identifier = add_tagname_if_needed identifier, 'input', :type => 'hidden'
170
179
  how, what = Elements::HiddenField.selenium_identifier_for identifier
180
+ switch_to_frame(frame_identifiers)
171
181
  element = @browser.find_element(how, what)
182
+ @browser.switch_to.default_content
172
183
  Elements::HiddenField.new(element, :platform => :selenium)
173
184
  end
174
185
 
@@ -177,9 +188,12 @@ module PageObject
177
188
  # See PageObject::Accessors#text_area
178
189
  #
179
190
  def text_area_value_set(identifier, value)
191
+ frame_identifiers = identifier.delete(:frame)
180
192
  identifier = add_tagname_if_needed identifier, 'textarea'
181
193
  how, what = Elements::TextArea.selenium_identifier_for identifier
194
+ switch_to_frame(frame_identifiers)
182
195
  @browser.find_element(how, what).send_keys(value)
196
+ @browser.switch_to.default_content
183
197
  end
184
198
 
185
199
  #
@@ -187,9 +201,13 @@ module PageObject
187
201
  # See PageObject::Accessors#text_area
188
202
  #
189
203
  def text_area_value_for(identifier)
204
+ frame_identifiers = identifier.delete(:frame)
190
205
  identifier = add_tagname_if_needed identifier, 'textarea'
191
206
  how, what = Elements::TextArea.selenium_identifier_for identifier
192
- @browser.find_element(how, what).attribute('value')
207
+ switch_to_frame(frame_identifiers)
208
+ value = @browser.find_element(how, what).attribute('value')
209
+ @browser.switch_to.default_content
210
+ value
193
211
  end
194
212
 
195
213
  #
@@ -197,9 +215,12 @@ module PageObject
197
215
  # See PageObject::Accessors#text_area
198
216
  #
199
217
  def text_area_for(identifier)
218
+ frame_identifiers = identifier.delete(:frame)
200
219
  identifier = add_tagname_if_needed identifier, 'textarea'
201
220
  how, what = Elements::TextArea.selenium_identifier_for identifier
221
+ switch_to_frame(frame_identifiers)
202
222
  element = @browser.find_element(how, what)
223
+ @browser.switch_to.default_content
203
224
  Elements::TextArea.new(element, :platform => :selenium)
204
225
  end
205
226
 
@@ -208,9 +229,13 @@ module PageObject
208
229
  # See PageObject::Accessors#select_list
209
230
  #
210
231
  def select_list_value_for(identifier)
232
+ frame_identifiers = identifier.delete(:frame)
211
233
  identifier = add_tagname_if_needed identifier, 'select'
212
234
  how, what = Elements::SelectList.selenium_identifier_for identifier
213
- @browser.find_element(how, what).attribute('value')
235
+ switch_to_frame(frame_identifiers)
236
+ value = @browser.find_element(how, what).attribute('value')
237
+ @browser.switch_to.default_content
238
+ value
214
239
  end
215
240
 
216
241
  #
@@ -218,9 +243,12 @@ module PageObject
218
243
  # See PageObject::Accessors#select_list
219
244
  #
220
245
  def select_list_value_set(identifier, value)
246
+ frame_identifiers = identifier.delete(:frame)
221
247
  identifier = add_tagname_if_needed identifier, 'select'
222
248
  how, what = Elements::SelectList.selenium_identifier_for identifier
249
+ switch_to_frame(frame_identifiers)
223
250
  @browser.find_element(how, what).send_keys(value)
251
+ @browser.switch_to.default_content
224
252
  end
225
253
 
226
254
  #
@@ -228,9 +256,12 @@ module PageObject
228
256
  # See PageObject::Accessors#select_list
229
257
  #
230
258
  def select_list_for(identifier)
259
+ frame_identifiers = identifier.delete(:frame)
231
260
  identifier = add_tagname_if_needed identifier, 'select'
232
261
  how, what = Elements::SelectList.selenium_identifier_for identifier
262
+ switch_to_frame(frame_identifiers)
233
263
  element = @browser.find_element(how, what)
264
+ @browser.switch_to.default_content
234
265
  Elements::SelectList.new(element, :platform => :selenium)
235
266
  end
236
267
 
@@ -239,9 +270,12 @@ module PageObject
239
270
  # See PageObject::Accessors#link
240
271
  #
241
272
  def click_link_for(identifier)
273
+ frame_identifiers = identifier.delete(:frame)
242
274
  identifier = add_tagname_if_needed identifier, "a"
243
275
  how, what = Elements::Link.selenium_identifier_for identifier
276
+ switch_to_frame frame_identifiers
244
277
  @browser.find_element(how, what).click
278
+ @browser.switch_to.default_content
245
279
  end
246
280
 
247
281
  #
@@ -249,9 +283,12 @@ module PageObject
249
283
  # see PageObject::Accessors#link
250
284
  #
251
285
  def link_for(identifier)
286
+ frame_identifiers = identifier.delete(:frame)
252
287
  identifier = add_tagname_if_needed identifier, "a"
253
288
  how, what = Elements::Link.selenium_identifier_for identifier
289
+ switch_to_frame(frame_identifiers)
254
290
  element = @browser.find_element(how, what)
291
+ @browser.switch_to.default_content
255
292
  Elements::Link.new(element, :platform => :selenium)
256
293
  end
257
294
 
@@ -260,9 +297,12 @@ module PageObject
260
297
  # See PageObject::Accessors#checkbox
261
298
  #
262
299
  def check_checkbox(identifier)
300
+ frame_identifiers = identifier.delete(:frame)
263
301
  identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
264
302
  how, what = Elements::CheckBox.selenium_identifier_for identifier
303
+ switch_to_frame(frame_identifiers)
265
304
  @browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
305
+ @browser.switch_to.default_content
266
306
  end
267
307
 
268
308
  #
@@ -270,9 +310,12 @@ module PageObject
270
310
  # See PageObject::Accessors#checkbox
271
311
  #
272
312
  def uncheck_checkbox(identifier)
313
+ frame_identifiers = identifier.delete(:frame)
273
314
  identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
274
315
  how, what = Elements::CheckBox.selenium_identifier_for identifier
316
+ switch_to_frame(frame_identifiers)
275
317
  @browser.find_element(how, what).click if @browser.find_element(how, what).selected?
318
+ @browser.switch_to.default_content
276
319
  end
277
320
 
278
321
  #
@@ -280,9 +323,13 @@ module PageObject
280
323
  # See PageObject::Accessors#checkbox
281
324
  #
282
325
  def checkbox_checked?(identifier)
326
+ frame_identifiers = identifier.delete(:frame)
283
327
  identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
284
328
  how, what = Elements::CheckBox.selenium_identifier_for identifier
285
- @browser.find_element(how, what).selected?
329
+ switch_to_frame(frame_identifiers)
330
+ value = @browser.find_element(how, what).selected?
331
+ @browser.switch_to.default_content
332
+ value
286
333
  end
287
334
 
288
335
  #
@@ -290,9 +337,12 @@ module PageObject
290
337
  # See PageObject::Accessors#checkbox
291
338
  #
292
339
  def checkbox_for(identifier)
340
+ frame_identifiers = identifier.delete(:frame)
293
341
  identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
294
342
  how, what = Elements::CheckBox.selenium_identifier_for identifier
343
+ switch_to_frame(frame_identifiers)
295
344
  element = @browser.find_element(how, what)
345
+ @browser.switch_to.default_content
296
346
  Elements::CheckBox.new(element, :platform => :selenium)
297
347
  end
298
348
 
@@ -301,9 +351,12 @@ module PageObject
301
351
  # See PageObject::Accessors#radio_button
302
352
  #
303
353
  def select_radio(identifier)
354
+ frame_identifiers = identifier.delete(:frame)
304
355
  identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
305
356
  how, what = Elements::RadioButton.selenium_identifier_for identifier
357
+ switch_to_frame(frame_identifiers)
306
358
  @browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
359
+ @browser.switch_to.default_content
307
360
  end
308
361
 
309
362
  #
@@ -311,9 +364,12 @@ module PageObject
311
364
  # See PageObject::Accessors#radio_button
312
365
  #
313
366
  def clear_radio(identifier)
367
+ frame_identifiers = identifier.delete(:frame)
314
368
  identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
315
369
  how, what = Elements::RadioButton.selenium_identifier_for identifier
370
+ switch_to_frame(frame_identifiers)
316
371
  @browser.find_element(how, what).click if @browser.find_element(how, what).selected?
372
+ @browser.switch_to.default_content
317
373
  end
318
374
 
319
375
  #
@@ -321,9 +377,13 @@ module PageObject
321
377
  # See PageObject::Accessors#radio_button
322
378
  #
323
379
  def radio_selected?(identifier)
380
+ frame_identifiers = identifier.delete(:frame)
324
381
  identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
325
382
  how, what = Elements::RadioButton.selenium_identifier_for identifier
326
- @browser.find_element(how, what).selected?
383
+ switch_to_frame(frame_identifiers)
384
+ value = @browser.find_element(how, what).selected?
385
+ @browser.switch_to.default_content
386
+ value
327
387
  end
328
388
 
329
389
  #
@@ -331,9 +391,12 @@ module PageObject
331
391
  # See PageObject::Accessors#radio_button
332
392
  #
333
393
  def radio_button_for(identifier)
394
+ frame_identifiers = identifier.delete(:frame)
334
395
  identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
335
396
  how, what = Elements::RadioButton.selenium_identifier_for identifier
397
+ switch_to_frame(frame_identifiers)
336
398
  element = @browser.find_element(how, what)
399
+ @browser.switch_to.default_content
337
400
  Object::PageObject::Elements::RadioButton.new(element, :platform => :selenium)
338
401
  end
339
402
 
@@ -342,9 +405,13 @@ module PageObject
342
405
  # See PageObject::Accessors#div
343
406
  #
344
407
  def div_text_for(identifier)
408
+ frame_identifiers = identifier.delete(:frame)
345
409
  identifier = add_tagname_if_needed identifier, 'div'
346
410
  how, what = Elements::Div.selenium_identifier_for identifier
347
- @browser.find_element(how, what).text
411
+ switch_to_frame(frame_identifiers)
412
+ value = @browser.find_element(how, what).text
413
+ @browser.switch_to.default_content
414
+ value
348
415
  end
349
416
 
350
417
  #
@@ -352,9 +419,12 @@ module PageObject
352
419
  # See PageObject::Accessors#div
353
420
  #
354
421
  def div_for(identifier)
422
+ frame_identifiers = identifier.delete(:frame)
355
423
  identifier = add_tagname_if_needed identifier, 'div'
356
424
  how, what = Elements::Div.selenium_identifier_for identifier
425
+ switch_to_frame(frame_identifiers)
357
426
  element = @browser.find_element(how, what)
427
+ @browser.switch_to.default_content
358
428
  Object::PageObject::Elements::Div.new(element, :platform => :selenium)
359
429
  end
360
430
 
@@ -363,9 +433,13 @@ module PageObject
363
433
  # See PageObject::Accessors#span
364
434
  #
365
435
  def span_text_for(identifier)
436
+ frame_identifiers = identifier.delete(:frame)
366
437
  identifier = add_tagname_if_needed identifier, 'span'
367
438
  how, what = Elements::Span.selenium_identifier_for identifier
368
- @browser.find_element(how, what).text
439
+ switch_to_frame(frame_identifiers)
440
+ value = @browser.find_element(how, what).text
441
+ @browser.switch_to.default_content
442
+ value
369
443
  end
370
444
 
371
445
  #
@@ -373,9 +447,12 @@ module PageObject
373
447
  # See PageObject::Accessors#span
374
448
  #
375
449
  def span_for(identifier)
450
+ frame_identifiers = identifier.delete(:frame)
376
451
  identifier = add_tagname_if_needed identifier, 'span'
377
452
  how, what = Elements::Span.selenium_identifier_for identifier
453
+ switch_to_frame(frame_identifiers)
378
454
  element = @browser.find_element(how, what)
455
+ @browser.switch_to.default_content
379
456
  Object::PageObject::Elements::Span.new(element, :platform => :selenium)
380
457
  end
381
458
 
@@ -384,9 +461,12 @@ module PageObject
384
461
  # See PageObject::Accessors#button
385
462
  #
386
463
  def click_button_for(identifier)
464
+ frame_identifiers = identifier.delete(:frame)
387
465
  identifier = add_tagname_if_needed identifier, 'input', :type => 'submit'
388
466
  how, what = Elements::Button.selenium_identifier_for identifier
467
+ switch_to_frame(frame_identifiers)
389
468
  @browser.find_element(how, what).click
469
+ @browser.switch_to.default_content
390
470
  end
391
471
 
392
472
  #
@@ -394,9 +474,12 @@ module PageObject
394
474
  # See PageObject::Accessors#button
395
475
  #
396
476
  def button_for(identifier)
477
+ frame_identifiers = identifier.delete(:frame)
397
478
  identifier = add_tagname_if_needed identifier, 'input', :type => 'submit'
398
479
  how, what = Elements::Button.selenium_identifier_for identifier
480
+ switch_to_frame(frame_identifiers)
399
481
  element = @browser.find_element(how, what)
482
+ @browser.switch_to.default_content
400
483
  Object::PageObject::Elements::Button.new(element, :platform => :selenium)
401
484
  end
402
485
 
@@ -405,9 +488,12 @@ module PageObject
405
488
  # See PageObject::Accessors#table
406
489
  #
407
490
  def table_for(identifier)
491
+ frame_identifiers = identifier.delete(:frame)
408
492
  identifier = add_tagname_if_needed identifier, 'table'
409
493
  how, what = Elements::Table.selenium_identifier_for identifier
494
+ switch_to_frame(frame_identifiers)
410
495
  element = @browser.find_element(how, what)
496
+ @browser.switch_to.default_content
411
497
  Object::PageObject::Elements::Table.new(element, :platform => :selenium)
412
498
  end
413
499
 
@@ -416,9 +502,13 @@ module PageObject
416
502
  # See PageObject::Accessors#cell
417
503
  #
418
504
  def cell_text_for(identifier)
505
+ frame_identifiers = identifier.delete(:frame)
419
506
  identifier = add_tagname_if_needed identifier, 'td'
420
507
  how, what = Elements::TableCell.selenium_identifier_for identifier
421
- @browser.find_element(how, what).text
508
+ switch_to_frame(frame_identifiers)
509
+ value = @browser.find_element(how, what).text
510
+ @browser.switch_to.default_content
511
+ value
422
512
  end
423
513
 
424
514
  #
@@ -426,9 +516,12 @@ module PageObject
426
516
  # See PageObject::Accessors#cell
427
517
  #
428
518
  def cell_for(identifier)
519
+ frame_identifiers = identifier.delete(:frame)
429
520
  identifier = add_tagname_if_needed identifier, 'td'
430
521
  how, what = Elements::TableCell.selenium_identifier_for identifier
522
+ switch_to_frame(frame_identifiers)
431
523
  element = @browser.find_element(how, what)
524
+ @browser.switch_to.default_content
432
525
  Object::PageObject::Elements::TableCell.new(element, :platform => :selenium)
433
526
  end
434
527
 
@@ -437,9 +530,12 @@ module PageObject
437
530
  # See PageObject::Accessors#image
438
531
  #
439
532
  def image_for(identifier)
533
+ frame_identifiers = identifier.delete(:frame)
440
534
  identifier = add_tagname_if_needed identifier, 'img'
441
535
  how, what = Elements::Image.selenium_identifier_for identifier
536
+ switch_to_frame(frame_identifiers)
442
537
  element = @browser.find_element(how, what)
538
+ @browser.switch_to.default_content
443
539
  Object::PageObject::Elements::Image.new(element, :platform => :selenium)
444
540
  end
445
541
 
@@ -448,9 +544,12 @@ module PageObject
448
544
  # See PageObject::Accessors#form
449
545
  #
450
546
  def form_for(identifier)
547
+ frame_identifiers = identifier.delete(:frame)
451
548
  identifier = add_tagname_if_needed identifier, 'form'
452
549
  how, what = Elements::Form.selenium_identifier_for identifier
550
+ switch_to_frame(frame_identifiers)
453
551
  element = @browser.find_element(how, what)
552
+ @browser.switch_to.default_content
454
553
  Object::PageObject::Elements::Form.new(element, :platform => :selenium)
455
554
  end
456
555
 
@@ -459,9 +558,13 @@ module PageObject
459
558
  # See PageObject::Accessors#list_item
460
559
  #
461
560
  def list_item_text_for(identifier)
561
+ frame_identifiers = identifier.delete(:frame)
462
562
  identifier = add_tagname_if_needed identifier, 'li'
463
563
  how, what = Elements::ListItem.selenium_identifier_for identifier
464
- @browser.find_element(how, what).text
564
+ switch_to_frame(frame_identifiers)
565
+ value = @browser.find_element(how, what).text
566
+ @browser.switch_to.default_content
567
+ value
465
568
  end
466
569
 
467
570
  #
@@ -469,9 +572,12 @@ module PageObject
469
572
  # See PageObject::Accessors#list_item
470
573
  #
471
574
  def list_item_for(identifier)
575
+ frame_identifiers = identifier.delete(:frame)
472
576
  identifier = add_tagname_if_needed identifier, 'li'
473
577
  how, what = Elements::ListItem.selenium_identifier_for identifier
578
+ switch_to_frame(frame_identifiers)
474
579
  element = @browser.find_element(how, what)
580
+ @browser.switch_to.default_content
475
581
  Object::PageObject::Elements::ListItem.new(element, :platform => :selenium)
476
582
  end
477
583
 
@@ -480,9 +586,12 @@ module PageObject
480
586
  # See PageObject::Accessors#unordered_list
481
587
  #
482
588
  def unordered_list_for(identifier)
589
+ frame_identifiers = identifier.delete(:frame)
483
590
  identifier = add_tagname_if_needed identifier, 'ul'
484
591
  how, what = Elements::UnorderedList.selenium_identifier_for identifier
592
+ switch_to_frame(frame_identifiers)
485
593
  element = @browser.find_element(how, what)
594
+ @browser.switch_to.default_content
486
595
  Object::PageObject::Elements::UnorderedList.new(element, :platform => :selenium)
487
596
  end
488
597
 
@@ -491,9 +600,12 @@ module PageObject
491
600
  # See PageObject::Accessors#ordered_list
492
601
  #
493
602
  def ordered_list_for(identifier)
603
+ frame_identifiers = identifier.delete(:frame)
494
604
  identifier = add_tagname_if_needed identifier, 'ol'
495
605
  how, what = Elements::OrderedList.selenium_identifier_for identifier
606
+ switch_to_frame(frame_identifiers)
496
607
  element = @browser.find_element(how, what)
608
+ @browser.switch_to.default_content
497
609
  Object::PageObject::Elements::OrderedList.new(element, :platform => :selenium)
498
610
  end
499
611
 
@@ -518,6 +630,14 @@ module PageObject
518
630
  true
519
631
  end
520
632
 
633
+ def switch_to_frame(frame_identifiers)
634
+ if not frame_identifiers.nil?
635
+ frame_identifiers.each do |frame_id|
636
+ value = frame_id.values.first
637
+ @browser.switch_to.frame(value)
638
+ end
639
+ end
640
+ end
521
641
  end
522
642
  end
523
643
  end