2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#visit' do
|
|
|
|
it "should fetch a response from the driver with a relative url" do
|
|
|
|
@session.visit('/')
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content('Hello world!')
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit('/foo')
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content('Another World')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fetch a response from the driver with an absolute url with a port" do
|
|
|
|
# Preparation
|
|
|
|
@session.visit('/')
|
|
|
|
root_uri = URI.parse(@session.current_url)
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit("http://#{root_uri.host}:#{root_uri.port}/")
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content('Hello world!')
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit("http://#{root_uri.host}:#{root_uri.port}/foo")
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content('Another World')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2013-11-10 08:31:08 -05:00
|
|
|
it "should fetch a response when absolute URI doesn't have a trailing slash" do
|
|
|
|
# Preparation
|
|
|
|
@session.visit('/foo/bar')
|
|
|
|
root_uri = URI.parse(@session.current_url)
|
|
|
|
|
2014-10-05 18:16:11 -04:00
|
|
|
@session.visit("http://#{root_uri.host}:#{root_uri.port}")
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content('Hello world!')
|
2013-11-10 08:31:08 -05:00
|
|
|
end
|
|
|
|
|
2016-10-04 14:10:29 -04:00
|
|
|
it "raises any errors caught inside the server", requires: [:server] do
|
2014-03-02 09:49:00 -05:00
|
|
|
quietly { @session.visit("/error") }
|
|
|
|
expect do
|
|
|
|
@session.visit("/")
|
|
|
|
end.to raise_error(TestApp::TestAppError)
|
|
|
|
end
|
|
|
|
|
2014-06-19 13:20:50 -04:00
|
|
|
it "should be able to open non-http url", requires: [:about_scheme] do
|
|
|
|
@session.visit("about:blank")
|
|
|
|
@session.assert_no_selector :xpath, "/html/body/*"
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "when Capybara.always_include_port is true" do
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
let(:root_uri) do
|
|
|
|
@session.visit('/')
|
|
|
|
URI.parse(@session.current_url)
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
before(:each) do
|
|
|
|
Capybara.always_include_port = true
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
after(:each) do
|
|
|
|
Capybara.always_include_port = false
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fetch a response from the driver with an absolute url without a port" do
|
|
|
|
@session.visit("http://#{root_uri.host}/")
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(URI.parse(@session.current_url).port).to eq(root_uri.port)
|
|
|
|
expect(@session).to have_content('Hello world!')
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit("http://#{root_uri.host}/foo")
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(URI.parse(@session.current_url).port).to eq(root_uri.port)
|
|
|
|
expect(@session).to have_content('Another World')
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
2017-08-04 19:42:54 -04:00
|
|
|
|
|
|
|
it "should add the server port to a visited url if no port specified", requires: [:server] do
|
|
|
|
expect(@session.driver).to receive(:visit).with("http://www.example.com:#{@session.server.port}")
|
|
|
|
@session.visit("http://www.example.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not override the visit specified port even if default for scheme", requires: [:server] do
|
|
|
|
expect(@session.driver).to receive(:visit).with("http://www.example.com:80")
|
|
|
|
@session.visit('http://www.example.com:80')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should give preference to app_host port if specified", requires: [:server] do
|
|
|
|
Capybara.app_host = "http://www.example.com:6666"
|
|
|
|
expect(@session.driver).to receive(:visit).with("http://www.example.com:6666/random")
|
|
|
|
@session.visit('/random')
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2016-10-04 14:10:29 -04:00
|
|
|
context "without a server", requires: [:server] do
|
2012-11-14 08:29:12 -05:00
|
|
|
it "should respect `app_host`" do
|
|
|
|
serverless_session = Capybara::Session.new(@session.mode, nil)
|
|
|
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
|
|
|
serverless_session.visit("/foo")
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(serverless_session).to have_content("Another World")
|
2012-11-14 08:29:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should visit a fully qualified URL" do
|
|
|
|
serverless_session = Capybara::Session.new(@session.mode, nil)
|
|
|
|
serverless_session.visit("http://#{@session.server.host}:#{@session.server.port}/foo")
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(serverless_session).to have_content("Another World")
|
2012-11-14 08:29:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-30 01:44:33 -04:00
|
|
|
context "with Capybara.app_host set" do
|
|
|
|
it "should override server", requires: [:server] do
|
|
|
|
another_session = Capybara::Session.new(@session.mode, @session.app.dup)
|
|
|
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
|
|
|
another_session.visit('/foo')
|
|
|
|
expect(another_session).to have_content("Another World")
|
|
|
|
expect(another_session.current_url).to start_with(Capybara.app_host)
|
|
|
|
expect(URI.parse(another_session.current_url).port).not_to eq another_session.server.port
|
|
|
|
expect(URI.parse(another_session.current_url).port).to eq @session.server.port
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should append relative path", requires: [:server] do
|
|
|
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}/redirect/0"
|
|
|
|
@session.visit('/times')
|
|
|
|
expect(@session).to have_content('redirection complete')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send no referer when visiting a page" do
|
|
|
|
@session.visit '/get_referer'
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content 'No referer'
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send no referer when visiting a second page" do
|
|
|
|
@session.visit '/get_referer'
|
|
|
|
@session.visit '/get_referer'
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content 'No referer'
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send a referer when following a link" do
|
|
|
|
@session.visit '/referer_base'
|
|
|
|
@session.find('//a[@href="/get_referer"]').click
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content %r{http://.*/referer_base}
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should preserve the original referer URL when following a redirect" do
|
|
|
|
@session.visit('/referer_base')
|
|
|
|
@session.find('//a[@href="/redirect_to_get_referer"]').click
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content %r{http://.*/referer_base}
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send a referer when submitting a form" do
|
|
|
|
@session.visit '/referer_base'
|
|
|
|
@session.find('//input').click
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content %r{http://.*/referer_base}
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
2013-11-10 08:31:08 -05:00
|
|
|
|
2013-05-15 16:12:30 -04:00
|
|
|
it "can set cookie if a blank path is specified" do
|
|
|
|
@session.visit("")
|
|
|
|
@session.visit('/get_cookie')
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_content('root cookie')
|
2013-05-15 16:12:30 -04:00
|
|
|
end
|
2013-11-10 08:31:08 -05:00
|
|
|
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|