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)
|
||||
# @param [Capybara::Node::Element] frame element
|
||||
# @overload within_frame(name)
|
||||
# @param [String] name name/id of a frame
|
||||
# @overload within_frame([kind = :frame], locator, options = {})
|
||||
# @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)
|
||||
# @param [Integer] index index of a frame
|
||||
#
|
||||
def within_frame(locator)
|
||||
# @param [Integer] index index of a frame (0 based)
|
||||
def within_frame(*args)
|
||||
scopes.push(nil)
|
||||
|
||||
#support older driver frame api for now
|
||||
frame = case locator
|
||||
frame = case args[0]
|
||||
when Capybara::Node::Element
|
||||
locator
|
||||
when String
|
||||
find(:frame, locator)
|
||||
args[0]
|
||||
when String, Hash
|
||||
find(:frame, *args)
|
||||
when Symbol
|
||||
find(*args)
|
||||
when Integer
|
||||
all(:frame, minimum: locator+1)[locator]
|
||||
idx = args[0]
|
||||
all(:frame, minimum: idx+1)[idx]
|
||||
else
|
||||
raise ArgumentError
|
||||
end
|
||||
|
|
|
@ -41,6 +41,18 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
|||
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
|
||||
@session.within_frame 'parentFrame' do
|
||||
@session.within_frame 'childFrame' do
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<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_parent" id="parentFrame"></iframe>
|
||||
</body>
|
||||
|
|
Loading…
Add table
Reference in a new issue