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
|
2018-04-27 14:01:47 -04:00
|
|
|
before do
|
2012-07-21 16:44:10 -04:00
|
|
|
@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
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
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
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
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
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
|
2012-07-21 16:44:10 -04:00
|
|
|
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
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
|
2012-07-21 16:44:10 -04:00
|
|
|
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
|
2013-11-14 12:43:36 -05:00
|
|
|
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
|
2016-12-08 14:17:21 -05:00
|
|
|
@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
|
2016-12-08 14:17:21 -05:00
|
|
|
@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
|
2018-07-06 11:56:40 -04:00
|
|
|
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
|
2018-07-06 11:56:40 -04:00
|
|
|
# Multiple frames in scope here
|
2018-07-10 17:18:39 -04:00
|
|
|
@session.within_frame { ; }
|
|
|
|
end.to raise_error Capybara::Ambiguous
|
2018-07-06 11:56:40 -04:00
|
|
|
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
|
2016-04-27 13:25:03 -04:00
|
|
|
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
|
2013-07-02 13:10:02 -04:00
|
|
|
@session.within(:css, '#divInMainWindow') do
|
2017-03-07 23:51:57 -05:00
|
|
|
@session.within_frame 'innerParentFrame' do
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session.has_selector?(:css, 'iframe#childFrame')).to be true
|
2013-07-02 13:10:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-27 13:25:03 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'works if the frame is closed', requires: %i[frames js] do
|
2016-04-27 13:25:03 -04:00
|
|
|
@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
|