1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/spec/session/frame/within_frame_spec.rb

102 lines
3.4 KiB
Ruby
Raw Normal View History

2016-03-07 19:52:19 -05:00
# frozen_string_literal: true
2018-02-28 19:11:41 -05:00
2016-10-04 14:10:29 -04:00
Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
before do
@session.visit('/within_frames')
end
2012-07-13 06:59:57 -04:00
2018-07-10 17:18:39 -04:00
it 'should find the div in frameOne' do
@session.within_frame('frameOne') do
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
2012-07-13 06:59:57 -04:00
end
end
2016-07-15 14:00:14 -04:00
2018-07-10 17:18:39 -04:00
it 'should find the div in FrameTwo' do
@session.within_frame('frameTwo') do
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
2012-07-13 06:59:57 -04:00
end
end
2016-07-15 14:00:14 -04:00
2018-07-10 17:18:39 -04:00
it 'should find the text div in the main window after finding text in frameOne' do
@session.within_frame('frameOne') do
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
2012-07-13 06:59:57 -04:00
end
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
end
2016-07-15 14:00:14 -04:00
2018-07-10 17:18:39 -04:00
it 'should find the text div in the main window after finding text in frameTwo' do
@session.within_frame('frameTwo') do
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
2012-07-13 06:59:57 -04:00
end
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
end
2016-07-15 14:00:14 -04:00
2018-07-10 17:18:39 -04:00
it 'should return the result of executing the block' do
expect(@session.within_frame('frameOne') { 'return value' }).to eql 'return value'
2012-07-13 06:59:57 -04:00
end
2016-07-15 14:00:14 -04:00
2018-07-10 17:18:39 -04:00
it 'should find the div given Element' do
2013-01-08 03:40:12 -05:00
element = @session.find(:id, 'frameOne')
@session.within_frame element do
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
2013-01-08 03:40:12 -05:00
end
2013-02-22 14:06:12 -05:00
end
2016-07-15 14:00:14 -04:00
2018-07-10 17:18:39 -04:00
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
2018-07-10 17:18:39 -04:00
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
2018-07-10 17:18:39 -04:00
it 'should default to the :frame selector when no options passed' do
container = @session.find(:css, '#divInMainWindow')
@session.within(container) do
# Ensure only one frame in scope
@session.within_frame do
expect(@session).to have_css('body#parentBody')
end
end
2018-07-10 17:18:39 -04:00
expect do
# Multiple frames in scope here
2018-07-10 17:18:39 -04:00
@session.within_frame { ; }
end.to raise_error Capybara::Ambiguous
end
2018-07-10 17:18:39 -04:00
it 'should find multiple nested frames' do
2013-02-22 14:06:12 -05:00
@session.within_frame 'parentFrame' do
@session.within_frame 'childFrame' do
2018-02-28 19:11:41 -05:00
@session.within_frame 'grandchildFrame1' do
# dummy
end
@session.within_frame 'grandchildFrame2' do
# dummy
end
end
2013-02-22 14:06:12 -05:00
end
end
2016-07-15 14:00:14 -04:00
2018-07-10 17:18:39 -04:00
it 'should reset scope when changing frames' do
@session.within(:css, '#divInMainWindow') do
@session.within_frame 'innerParentFrame' do
2018-07-10 17:18:39 -04:00
expect(@session.has_selector?(:css, 'iframe#childFrame')).to be true
end
end
end
2018-07-10 17:18:39 -04:00
it 'works if the frame is closed', requires: %i[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
2012-07-13 06:59:57 -04:00
end