Skip to content

Commit

Permalink
Merge remote branch 'larrytheliquid/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed May 9, 2010
2 parents b1e1982 + 67a2076 commit 8dcaabe
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.DS_Store
pkg
*~
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def body
raise NotImplementedError
end

def within_frame(frame_id)
raise Capybara::NotSupportedByDriverError
end

def source
raise NotImplementedError
end
Expand Down
14 changes: 13 additions & 1 deletion lib/capybara/driver/selenium_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def tag_name
end

def visible?
node.displayed? and node.displayed? != "false"
begin
node.displayed? and node.displayed? != "false"
rescue Selenium::WebDriver::Error::WebDriverError
# rescues the inevitable "Selenium::WebDriver::Error::WebDriverError: element is obsolete" if you check to see if an element that has been removed from the DOM is visible
return false
end
end

def trigger(event)
Expand Down Expand Up @@ -140,6 +145,13 @@ def cleanup!
browser.manage.delete_all_cookies
end

def within_frame(frame_id)
old_window = browser.window_handle
browser.switch_to.frame(frame_id)
yield
browser.switch_to.window old_window
end

private

def url(path)
Expand Down
12 changes: 9 additions & 3 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class Session
:all, :attach_file, :body, :check, :choose, :click, :click_button, :click_link, :current_url, :drag, :evaluate_script,
:field_labeled, :fill_in, :find, :find_button, :find_by_id, :find_field, :find_link, :has_content?, :has_css?,
:has_no_content?, :has_no_css?, :has_no_xpath?, :has_xpath?, :locate, :save_and_open_page, :select, :source, :uncheck,
:visit, :wait_until, :within, :within_fieldset, :within_table, :has_link?, :has_no_link?, :has_button?, :has_no_button?,
:has_field?, :has_no_field?, :has_checked_field?, :has_unchecked_field?, :has_no_table?, :has_table?, :unselect,
:has_select?, :has_no_select?
:visit, :wait_until, :within, :within_fieldset, :within_table, :within_frame, :has_link?, :has_no_link?, :has_button?,
:has_no_button?, :has_field?, :has_no_field?, :has_checked_field?, :has_unchecked_field?, :has_no_table?, :has_table?,
:unselect, :has_select?, :has_no_select?
]

attr_reader :mode, :app
Expand Down Expand Up @@ -119,6 +119,12 @@ def within_table(locator)
end
end

def within_frame frame_id
driver.within_frame(frame_id) do
yield
end
end

def has_xpath?(path, options={})
wait_conditionally_until do
results = all(:xpath, path, options)
Expand Down
31 changes: 31 additions & 0 deletions lib/capybara/spec/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,34 @@
@driver.response_headers['Content-Type'].should == 'text/html'
end
end

shared_examples_for "driver with frame support" do
describe '#within_frame' do
before(:each) do
@driver.visit('/within_frames')
end

it "should find the div in frameOne" do
@driver.within_frame("frameOne") do
@driver.find("//*[@id='divInFrameOne']")[0].text.should eql 'This is the text of divInFrameOne'
end
end
it "should find the div in FrameTwo" do
@driver.within_frame("frameTwo") do
@driver.find("//*[@id='divInFrameTwo']")[0].text.should eql 'This is the text of divInFrameTwo'
end
end
it "should find the text div in the main window after finding text in frameOne" do
@driver.within_frame("frameOne") do
@driver.find("//*[@id='divInFrameOne']")[0].text.should eql 'This is the text of divInFrameOne'
end
@driver.find("//*[@id='divInMainWindow']")[0].text.should eql 'This is the text for divInMainWindow'
end
it "should find the text div in the main window after finding text in frameTwo" do
@driver.within_frame("frameTwo") do
@driver.find("//*[@id='divInFrameTwo']")[0].text.should eql 'This is the text of divInFrameTwo'
end
@driver.find("//*[@id='divInMainWindow']")[0].text.should eql 'This is the text for divInMainWindow'
end
end
end
8 changes: 8 additions & 0 deletions lib/capybara/spec/views/frame_one.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>This is the title of frame one</title>
</head>
<body>
<div id="divInFrameOne">This is the text of divInFrameOne</div>
</body>
</html>
8 changes: 8 additions & 0 deletions lib/capybara/spec/views/frame_two.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>This is the title of frame two</title>
</head>
<body>
<div id="divInFrameTwo">This is the text of divInFrameTwo</div>
</body>
</html>
10 changes: 10 additions & 0 deletions lib/capybara/spec/views/within_frames.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>With Frames</title>
</head>
<body>
<div id="divInMainWindow">This is the text for divInMainWindow</div>
<iframe src="/frame_one" id="frameOne"></iframe>
<iframe src="/frame_two" id="frameTwo"></iframe>
</body>
</html>
2 changes: 1 addition & 1 deletion spec/driver/selenium_driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

it_should_behave_like "driver"
it_should_behave_like "driver with javascript support"

it_should_behave_like "driver with frame support"
end

0 comments on commit 8dcaabe

Please sign in to comment.