1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Frame focus via Capybara::Element

Fixes #465.
This commit is contained in:
Matthew Horan 2013-02-17 16:23:43 -05:00
parent 15bb56012e
commit ca8b3a2c0c
3 changed files with 17 additions and 7 deletions

View file

@ -70,11 +70,13 @@ module Capybara::Webkit
command("CurrentUrl")
end
def frame_focus(frame_id_or_index=nil)
if frame_id_or_index.is_a? Fixnum
command("FrameFocus", "", frame_id_or_index.to_s)
elsif frame_id_or_index
command("FrameFocus", frame_id_or_index)
def frame_focus(selector=nil)
if selector.respond_to?(:base)
selector.base.invoke('focus')
elsif selector.is_a? Fixnum
command("FrameFocus", "", selector.to_s)
elsif selector
command("FrameFocus", selector)
else
command("FrameFocus")
end

View file

@ -82,8 +82,8 @@ module Capybara::Webkit
browser.resize_window(width, height)
end
def within_frame(frame_id_or_index)
browser.frame_focus(frame_id_or_index)
def within_frame(selector)
browser.frame_focus(selector)
begin
yield
ensure

View file

@ -72,6 +72,14 @@ describe Capybara::Webkit::Driver do
end
end
it "finds frames by element" do
frame = driver.find('//iframe').first
element = double(Capybara::Node::Base, base: frame)
driver.within_frame(element) do
driver.find("//*[contains(., 'goodbye')]").should_not be_empty
end
end
it "raises error for missing frame by index" do
expect { driver.within_frame(1) { } }.
to raise_error(Capybara::Webkit::InvalidResponseError)