Browse files

added in_iframe methods to match watir-webdriver changes

  • Loading branch information...
1 parent 6e15bd1 commit e2e7d596751084bc94fa1796c75f93481cfcebf9 @cheezy committed Feb 4, 2014
View
6 ChangeLog
@@ -1,3 +1,9 @@
+=== Version 0.9.6 / 2014-2-4
+* Enhancements
+ * Updated to use the latest watir-webdriver 0.6.7
+* Fixes
+ * Added in_iframe methods to match the updates to the watir-webdriver gem.
+
=== Version 0.9.5 / 2014-1-22
* Enhancements
* Updated to use the latest selenium-webdriver 2.39.0
View
31 features/step_definitions/frames_steps.rb
@@ -28,13 +28,40 @@ class FramePage
end
+class IFramePage
+ include PageObject
+
+ in_iframe(:id => 'frame_two_2') do |frame|
+ text_field(:text_field_2_id, :name => 'recieverElement', :frame => frame)
+ end
+ in_iframe(:id => 'frame_one_1') do |frame|
+ text_field(:text_field_1_id, :name => 'senderElement', :frame => frame)
+ end
+
+ in_iframe(:name => 'frame2') do |frame|
+ text_field(:text_field_2_name, :name => 'recieverElement', :frame => frame)
+ end
+ in_iframe(:name => 'frame1') do |frame|
+ text_field(:text_field_1_name, :name => 'senderElement', :frame => frame)
+ end
+
+ in_iframe(:index => 1) do |frame|
+ text_field(:text_field_2_index, :name => 'recieverElement', :frame => frame)
+ end
+ in_iframe(:index => 0) do |frame|
+ text_field(:text_field_1_index, :name => 'senderElement', :frame => frame)
+ end
+
+end
+
+
Given /^I am on the frame elements page$/ do
@page = FramePage.new(@browser)
@page.navigate_to(UrlHelper.frame_elements)
end
Given /^I am on the iframe elements page$/ do
- @page = FramePage.new(@browser)
+ @page = IFramePage.new(@browser)
@page.navigate_to(UrlHelper.iframe_elements)
end
@@ -64,7 +91,7 @@ class NestedFramePage
include PageObject
in_frame(:id => 'two') do |frame|
- in_frame({:id => 'three'}, frame) do |nested_frame|
+ in_iframe({:id => 'three'}, frame) do |nested_frame|
link(:nested_link, :id => 'four', :frame => nested_frame)
end
end
View
28 lib/page-object/accessors.rb
@@ -133,7 +133,7 @@ def expected_element_visible(element_name, timeout=::PageObject.default_element_
end
#
- # Identify an element as existing within a frame or iframe. A frame parameter
+ # Identify an element as existing within a frame . A frame parameter
# is passed to the block and must be passed to the other calls to PageObject.
# You can nest calls to in_frame by passing the frame to the next level.
#
@@ -152,7 +152,31 @@ def expected_element_visible(element_name, timeout=::PageObject.default_element_
#
def in_frame(identifier, frame=nil, &block)
frame = [] if frame.nil?
- frame << identifier
+ frame << {frame: identifier}
+ block.call(frame)
+ end
+
+ #
+ # Identify an element as existing within an iframe. A frame parameter
+ # is passed to the block and must be passed to the other calls to PageObject.
+ # You can nest calls to in_frame by passing the frame to the next level.
+ #
+ # @example
+ # in_iframe(:id => 'frame_id') do |frame|
+ # text_field(:first_name, :id => 'fname', :frame => frame)
+ # end
+ #
+ # @param [Hash] identifier how we find the frame. The valid keys are:
+ # * :id => Watir and Selenium
+ # * :index => Watir and Selenium
+ # * :name => Watir and Selenium
+ # * :regexp => Watir only
+ # @param frame passed from a previous call to in_iframe. Used to nest calls
+ # @param block that contains the calls to elements that exist inside the iframe.
+ #
+ def in_iframe(identifier, frame=nil, &block)
+ frame = [] if frame.nil?
+ frame << {iframe: identifier}
block.call(frame)
end
View
15 lib/page-object/platforms/selenium_webdriver/page_object.rb
@@ -147,7 +147,17 @@ def element_with_focus
# See PageObject#in_frame
#
def in_frame(identifier, frame=nil, &block)
- switch_to_frame([identifier])
+ switch_to_frame([frame: identifier])
+ block.call(nil)
+ @browser.switch_to.default_content
+ end
+
+ #
+ # platform method to switch to an iframe and execute a block
+ # See PageObject#in_frame
+ #
+ def in_iframe(identifier, frame=nil, &block)
+ switch_to_frame([iframe: identifier])
block.call(nil)
@browser.switch_to.default_content
end
@@ -1088,7 +1098,8 @@ def supported_identifier(identifier, tag, additional)
def switch_to_frame(frame_identifiers)
unless frame_identifiers.nil?
- frame_identifiers.each do |frame_id|
+ frame_identifiers.each do |frame|
+ frame_id = frame.values.first
value = frame_id.values.first
@browser.switch_to.frame(value)
end
View
25 lib/page-object/platforms/watir_webdriver/page_object.rb
@@ -141,7 +141,17 @@ def element_with_focus
#
def in_frame(identifier, frame=nil, &block)
frame = [] if frame.nil?
- frame << identifier
+ frame << {frame: identifier}
+ block.call(frame)
+ end
+
+ #
+ # platform method to switch to an iframe and execute a block
+ # See PageObject#in_frame
+ #
+ def in_iframe(identifier, frame=nil, &block)
+ frame = [] if frame.nil?
+ frame << {iframe: identifier}
block.call(frame)
end
@@ -994,13 +1004,15 @@ def add_tagname_if_needed identifier, tag
def nested_frames(frame_identifiers)
return if frame_identifiers.nil?
frame_str = ''
- frame_identifiers.each do |id|
+ frame_identifiers.each do |frame|
+ id = frame.values.first
+ type = frame.keys.first
value = id.values.first
if value.is_a?(Regexp)
- frame_str += "frame(:#{id.keys.first} => #{value.inspect})."
+ frame_str += "#{type.to_s}(:#{id.keys.first} => #{value.inspect})."
else
- frame_str += "frame(:#{id.keys.first} => #{value})." if value.to_s.is_integer
- frame_str += "frame(:#{id.keys.first} => '#{value}')." unless value.to_s.is_integer
+ frame_str += "#{type.to_s}(:#{id.keys.first} => #{value})." if value.to_s.is_integer
+ frame_str += "#{type.to_s}(:#{id.keys.first} => '#{value}')." unless value.to_s.is_integer
end
end
frame_str
@@ -1028,7 +1040,8 @@ def call_for_watir_elements(identifier, call)
def switch_to_frame(frame_identifiers)
unless frame_identifiers.nil?
- frame_identifiers.each do |frame_id|
+ frame_identifiers.each do |frame|
+ frame_id = frame.values.first
value = frame_id.values.first
@browser.wd.switch_to.frame(value)
end

0 comments on commit e2e7d59

Please sign in to comment.