mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Allow within_frame to accept a selector type and locator
This commit is contained in:
parent
de9f57c7f4
commit
53b99af750
3 changed files with 26 additions and 12 deletions
|
@ -338,22 +338,24 @@ module Capybara
|
||||||
#
|
#
|
||||||
# @overload within_frame(element)
|
# @overload within_frame(element)
|
||||||
# @param [Capybara::Node::Element] frame element
|
# @param [Capybara::Node::Element] frame element
|
||||||
# @overload within_frame(name)
|
# @overload within_frame([kind = :frame], locator, options = {})
|
||||||
# @param [String] name name/id of a frame
|
# @param [Symobl] kind Optional selector type (:css, :xpath, :field, etc.) - Defaults to :frame
|
||||||
|
# @param [String] locator The locator for the given selector kind. For :frame this is the name/id of a frame/iframe element
|
||||||
# @overload within_frame(index)
|
# @overload within_frame(index)
|
||||||
# @param [Integer] index index of a frame
|
# @param [Integer] index index of a frame (0 based)
|
||||||
#
|
def within_frame(*args)
|
||||||
def within_frame(locator)
|
|
||||||
scopes.push(nil)
|
scopes.push(nil)
|
||||||
|
|
||||||
#support older driver frame api for now
|
frame = case args[0]
|
||||||
frame = case locator
|
|
||||||
when Capybara::Node::Element
|
when Capybara::Node::Element
|
||||||
locator
|
args[0]
|
||||||
when String
|
when String, Hash
|
||||||
find(:frame, locator)
|
find(:frame, *args)
|
||||||
|
when Symbol
|
||||||
|
find(*args)
|
||||||
when Integer
|
when Integer
|
||||||
all(:frame, minimum: locator+1)[locator]
|
idx = args[0]
|
||||||
|
all(:frame, minimum: idx+1)[idx]
|
||||||
else
|
else
|
||||||
raise ArgumentError
|
raise ArgumentError
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,6 +41,18 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should find the div given selector and locator" do
|
||||||
|
@session.within_frame(:css, '#frameOne') do
|
||||||
|
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should default to the :frame selector kind when only options passed" do
|
||||||
|
@session.within_frame(name: 'my frame one') do
|
||||||
|
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should find multiple nested frames" do
|
it "should find multiple nested frames" do
|
||||||
@session.within_frame 'parentFrame' do
|
@session.within_frame 'parentFrame' do
|
||||||
@session.within_frame 'childFrame' do
|
@session.within_frame 'childFrame' do
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="divInMainWindow">This is the text for divInMainWindow</div>
|
<div id="divInMainWindow">This is the text for divInMainWindow</div>
|
||||||
<iframe src="/frame_one" id="frameOne"></iframe>
|
<iframe src="/frame_one" id="frameOne" name="my frame one"></iframe>
|
||||||
<iframe src="/frame_two" id="frameTwo"></iframe>
|
<iframe src="/frame_two" id="frameTwo"></iframe>
|
||||||
<iframe src="/frame_parent" id="parentFrame"></iframe>
|
<iframe src="/frame_parent" id="parentFrame"></iframe>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Add table
Reference in a new issue