mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge remote branch 'jgagner/master'
Conflicts: lib/capybara/driver/selenium_driver.rb lib/capybara/session.rb spec/driver/selenium_driver_spec.rb
This commit is contained in:
commit
67a2076ecc
9 changed files with 85 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
|
.idea/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
pkg
|
pkg
|
||||||
*~
|
*~
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,10 @@ class Capybara::Driver::Base
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def within_frame(frame_id)
|
||||||
|
raise Capybara::NotSupportedByDriverError
|
||||||
|
end
|
||||||
|
|
||||||
def source
|
def source
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,12 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible?
|
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
|
end
|
||||||
|
|
||||||
def trigger(event)
|
def trigger(event)
|
||||||
|
|
@ -140,6 +145,13 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
|
||||||
browser.manage.delete_all_cookies
|
browser.manage.delete_all_cookies
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def url(path)
|
def url(path)
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ module Capybara
|
||||||
:all, :attach_file, :body, :check, :choose, :click, :click_button, :click_link, :current_url, :drag, :evaluate_script,
|
: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?,
|
: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,
|
: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?,
|
:visit, :wait_until, :within, :within_fieldset, :within_table, :within_frame, :has_link?, :has_no_link?, :has_button?,
|
||||||
:has_field?, :has_no_field?, :has_checked_field?, :has_unchecked_field?, :has_no_table?, :has_table?, :unselect,
|
:has_no_button?, :has_field?, :has_no_field?, :has_checked_field?, :has_unchecked_field?, :has_no_table?, :has_table?,
|
||||||
:has_select?, :has_no_select?
|
:unselect, :has_select?, :has_no_select?
|
||||||
]
|
]
|
||||||
|
|
||||||
attr_reader :mode, :app
|
attr_reader :mode, :app
|
||||||
|
|
@ -119,6 +119,12 @@ module Capybara
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def within_frame frame_id
|
||||||
|
driver.within_frame(frame_id) do
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def has_xpath?(path, options={})
|
def has_xpath?(path, options={})
|
||||||
wait_conditionally_until do
|
wait_conditionally_until do
|
||||||
results = all(:xpath, path, options)
|
results = all(:xpath, path, options)
|
||||||
|
|
|
||||||
|
|
@ -129,3 +129,34 @@ shared_examples_for "driver with header support" do
|
||||||
@driver.response_headers['Content-Type'].should == 'text/html'
|
@driver.response_headers['Content-Type'].should == 'text/html'
|
||||||
end
|
end
|
||||||
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
lib/capybara/spec/views/frame_one.erb
Normal file
8
lib/capybara/spec/views/frame_one.erb
Normal file
|
|
@ -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
lib/capybara/spec/views/frame_two.erb
Normal file
8
lib/capybara/spec/views/frame_two.erb
Normal file
|
|
@ -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
lib/capybara/spec/views/within_frames.erb
Normal file
10
lib/capybara/spec/views/within_frames.erb
Normal file
|
|
@ -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>
|
||||||
|
|
@ -7,5 +7,5 @@ describe Capybara::Driver::Selenium do
|
||||||
|
|
||||||
it_should_behave_like "driver"
|
it_should_behave_like "driver"
|
||||||
it_should_behave_like "driver with javascript support"
|
it_should_behave_like "driver with javascript support"
|
||||||
|
it_should_behave_like "driver with frame support"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue