mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Fix Issue #1690 - within_Frame error with selenium
This commit is contained in:
parent
bf82309aa6
commit
dc011724a6
5 changed files with 33 additions and 17 deletions
|
@ -6,6 +6,12 @@ Release date: Unreleased
|
|||
### Added
|
||||
* 'check', 'uncheck', and 'choose' will now click the associated label if the checkbox/radio button is not visible
|
||||
|
||||
#Version 2.7.1
|
||||
Release date: Unreleased
|
||||
|
||||
### Fixed
|
||||
* Issue where within_Frame would fail with Selenium if the frame is removed from within itself [Thomas Walpole]
|
||||
|
||||
# Version 2.7.0
|
||||
Release date: 2016-04-07
|
||||
|
||||
|
|
|
@ -143,23 +143,16 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
#
|
||||
def within_frame(frame_handle)
|
||||
frame_handle = frame_handle.native if frame_handle.is_a?(Capybara::Node::Base)
|
||||
if !browser.switch_to.respond_to?(:parent_frame)
|
||||
# Selenium Webdriver < 2.43 doesnt support moving back to the parent
|
||||
@frame_handles[browser.window_handle] ||= []
|
||||
@frame_handles[browser.window_handle] << frame_handle
|
||||
end
|
||||
@frame_handles[browser.window_handle] ||= []
|
||||
@frame_handles[browser.window_handle] << frame_handle
|
||||
browser.switch_to.frame(frame_handle)
|
||||
yield
|
||||
ensure
|
||||
if browser.switch_to.respond_to?(:parent_frame)
|
||||
browser.switch_to.parent_frame
|
||||
else
|
||||
# There doesnt appear to be any way in Selenium Webdriver < 2.43 to move back to a parent frame
|
||||
# other than going back to the root and then reiterating down
|
||||
@frame_handles[browser.window_handle].pop
|
||||
browser.switch_to.default_content
|
||||
@frame_handles[browser.window_handle].each { |fh| browser.switch_to.frame(fh) }
|
||||
end
|
||||
# would love to use browser.switch_to.parent_frame here
|
||||
# but it has an issue if the current frame is removed from within it
|
||||
@frame_handles[browser.window_handle].pop
|
||||
browser.switch_to.default_content
|
||||
@frame_handles[browser.window_handle].each { |fh| browser.switch_to.frame(fh) }
|
||||
end
|
||||
|
||||
def current_window_handle
|
||||
|
|
|
@ -40,7 +40,7 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
|||
@session.within_frame 'childFrame' do
|
||||
@session.within_frame 'grandchildFrame1' do end
|
||||
@session.within_frame 'grandchildFrame2' do end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
it "should reset scope when changing frames" do
|
||||
|
@ -50,4 +50,14 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "works if the frame is closed", :requires => [:frames, :js] do
|
||||
@session.within_frame 'parentFrame' do
|
||||
@session.within_frame 'childFrame' do
|
||||
@session.click_link 'Close Window'
|
||||
end
|
||||
expect(@session).to have_selector(:css, 'body#parentBody')
|
||||
expect(@session).not_to have_selector(:css, '#childFrame')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>This is the child frame title</title>
|
||||
<script>
|
||||
function closeWin() {
|
||||
var iframe = window.parent.document.getElementById('childFrame')
|
||||
iframe.parentNode.removeChild(iframe)
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<body id="childBody">
|
||||
<a href="javascript:void(0)" onClick="closeWin()">Close Window</a>
|
||||
<iframe src="/frame_one" id="grandchildFrame1"></iframe>
|
||||
<iframe src="/frame_two" id="grandchildFrame2"></iframe>
|
||||
</body>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<title>This is the parent frame title</title>
|
||||
</head>
|
||||
<body>
|
||||
<body id="parentBody">
|
||||
<iframe src='/frame_child' id='childFrame'></iframe>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue