1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Driver#visit no longer resolves relative URLs

This commit is contained in:
Matthew Horan 2012-11-18 10:23:53 -05:00
parent ea2f785ba8
commit 73948fc576
2 changed files with 87 additions and 83 deletions

View file

@ -20,7 +20,7 @@ describe Capybara::Webkit::Driver, "rendering an image" do
tmp_dir = File.join(PROJECT_ROOT, 'tmp')
FileUtils.mkdir_p tmp_dir
@file_name = File.join(tmp_dir, 'render-test.png')
driver.visit '/'
driver.visit("#{AppRunner.app_host}/")
end
def render(options)

View file

@ -5,6 +5,10 @@ require 'base64'
describe Capybara::Webkit::Driver do
include AppRunner
def visit(url, driver=driver)
driver.visit("#{AppRunner.app_host}#{url}")
end
context "iframe app" do
let(:driver) do
driver_for_app do
@ -51,7 +55,7 @@ describe Capybara::Webkit::Driver do
end
before do
driver.visit("/")
visit("/")
end
it "finds frames by index" do
@ -158,7 +162,7 @@ describe Capybara::Webkit::Driver do
end
it "raises error whose message references the actual missing url" do
expect { driver.visit("/") }.to raise_error(Capybara::Webkit::InvalidResponseError, /inner-not-found/)
expect { visit("/") }.to raise_error(Capybara::Webkit::InvalidResponseError, /inner-not-found/)
end
end
@ -200,36 +204,36 @@ describe Capybara::Webkit::Driver do
end
it "should redirect without content type" do
driver.visit("/form")
visit("/form")
driver.find("//input").first.click
driver.find("//p").first.text.should == ""
end
it "returns the current URL when changed by pushState after a redirect" do
driver.visit("/redirect-me")
visit("/redirect-me")
driver.current_url.should == driver_url(driver, "/target")
driver.execute_script("window.history.pushState({}, '', '/pushed-after-redirect')")
driver.current_url.should == driver_url(driver, "/pushed-after-redirect")
end
it "returns the current URL when changed by replaceState after a redirect" do
driver.visit("/redirect-me")
visit("/redirect-me")
driver.current_url.should == driver_url(driver, "/target")
driver.execute_script("window.history.replaceState({}, '', '/replaced-after-redirect')")
driver.current_url.should == driver_url(driver, "/replaced-after-redirect")
end
it "should make headers available through response_headers" do
driver.visit('/redirect-me')
visit('/redirect-me')
driver.response_headers['X-Redirected'].should == "true"
driver.visit('/target')
visit('/target')
driver.response_headers['X-Redirected'].should == "false"
end
it "should make the status code available through status_code" do
driver.visit('/redirect-me')
visit('/redirect-me')
driver.status_code.should == 200
driver.visit('/target')
visit('/target')
driver.status_code.should == 200
end
end
@ -244,7 +248,7 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
it "renders unsupported content types gracefully" do
driver.html.should =~ /css/
@ -283,12 +287,12 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "handles anchor tags" do
driver.visit("#test")
visit("#test")
driver.find("//*[contains(., 'hello')]").should_not be_empty
driver.visit("#test")
visit("#test")
driver.find("//*[contains(., 'hello')]").should_not be_empty
end
@ -328,7 +332,7 @@ describe Capybara::Webkit::Driver do
end
it "returns the current URL" do
driver.visit "/hello/world?success=true"
visit "/hello/world?success=true"
driver.current_url.should == driver_url(driver, "/hello/world?success=true")
end
@ -343,12 +347,12 @@ describe Capybara::Webkit::Driver do
end
it "does not double-encode URLs" do
driver.visit("/hello/world?success=%25true")
visit("/hello/world?success=%25true")
driver.current_url.should =~ /success=\%25true/
end
it "visits a page with an anchor" do
driver.visit("/hello#display_none")
visit("/hello#display_none")
driver.current_url.should =~ /hello#display_none/
end
@ -458,7 +462,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "collects messages logged to the console" do
url = driver_url(driver, "/")
@ -507,7 +511,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "should let me read my alert messages" do
driver.alert_messages.first.should == "Alert Text Goes Here"
@ -540,7 +544,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "should default to accept the confirm" do
driver.find("//input").first.click
@ -574,7 +578,7 @@ describe Capybara::Webkit::Driver do
it "resets to the default of accepting confirms" do
driver.dismiss_js_confirms!
driver.reset!
driver.visit("/")
visit("/")
driver.find("//input").first.click
driver.console_messages.first[:message].should == "hello"
end
@ -602,7 +606,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "should default to dismiss the prompt" do
driver.find("//input").first.click
@ -653,7 +657,7 @@ describe Capybara::Webkit::Driver do
it "returns the prompt action to dismiss on reset" do
driver.accept_js_prompts!
driver.reset!
driver.visit("/")
visit("/")
driver.find("//input").first.click
driver.console_messages.first[:message].should == "goodbye"
end
@ -695,7 +699,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "returns a textarea's value" do
driver.find("//textarea").first.value.should == "what a wonderful area for text"
@ -904,7 +908,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "triggers mouse events" do
driver.find("//a").first.click
@ -956,7 +960,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
let(:newtext) { 'newvalue' }
@ -1025,7 +1029,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "clicks an element" do
driver.find("//a").first.click
@ -1073,7 +1077,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "evaluates nested xpath expressions" do
parent = driver.find("//*[@id='parent']").first
@ -1095,7 +1099,7 @@ describe Capybara::Webkit::Driver do
%{<html><body><a href="/result">Go</a></body></html>}
end
end
driver.visit("/")
visit("/", driver)
driver.find("//a").first.click
result.should == "finished"
end
@ -1118,7 +1122,7 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
it "raises a webkit error for the requested url" do
expect {
@ -1153,12 +1157,12 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
it "raises a webkit error and then continues" do
driver.find("//input").first.click
expect { driver.find("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError)
driver.visit("/")
visit("/")
driver.find("//p").first.text.should == "hello"
end
end
@ -1182,7 +1186,7 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
it "doesn't crash from alerts" do
driver.find("//p").first.text.should == "success"
@ -1205,13 +1209,13 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
before do
driver.header('user-agent', 'capybara-webkit/custom-user-agent')
driver.header('x-capybara-webkit-header', 'x-capybara-webkit-header')
driver.header('accept', 'text/html')
driver.visit('/')
visit('/')
end
it "can set user_agent" do
@ -1235,7 +1239,7 @@ describe Capybara::Webkit::Driver do
it "can reset all custom header" do
driver.reset!
driver.visit('/')
visit('/')
driver.find('id("user-agent")').first.text.should_not == 'capybara-webkit/custom-user-agent'
driver.evaluate_script('navigator.userAgent').should_not == 'capybara-webkit/custom-user-agent'
driver.find('id("x-capybara-webkit-header")').first.text.should be_empty
@ -1252,7 +1256,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "raises a webkit error for the requested url" do
make_the_server_go_away
@ -1292,7 +1296,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "ignores custom fonts" do
font_family = driver.evaluate_script(<<-SCRIPT)
@ -1317,7 +1321,7 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
def echoed_cookie
driver.find('id("cookie")').first.text
@ -1325,19 +1329,19 @@ describe Capybara::Webkit::Driver do
it "remembers the cookie on second visit" do
echoed_cookie.should == ""
driver.visit "/"
visit "/"
echoed_cookie.should == "abc"
end
it "uses a custom cookie" do
driver.browser.set_cookie 'cookie=abc; domain=127.0.0.1; path=/'
driver.visit "/"
visit "/"
echoed_cookie.should == "abc"
end
it "clears cookies" do
driver.browser.clear_cookies
driver.visit "/"
visit "/"
echoed_cookie.should == ""
end
@ -1368,7 +1372,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
before { set_automatic_reload false }
after { set_automatic_reload true }
@ -1427,7 +1431,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "builds up node paths correctly" do
cases = {
@ -1465,7 +1469,7 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "handles overflow hidden" do
driver.find("//div[@id='overflow']").first.text.should == "Overflow"
@ -1493,7 +1497,7 @@ describe Capybara::Webkit::Driver do
it "loads a page without error" do
10.times do
driver.visit("/redirect")
visit("/redirect")
driver.find("//p").first.text.should == "finished"
end
end
@ -1520,11 +1524,11 @@ describe Capybara::Webkit::Driver do
HTML
end
before { driver.visit("/") }
before { visit("/") }
it "displays the message on subsequent page loads" do
driver.find("//span[contains(.,'localStorage is enabled')]").should be_empty
driver.visit "/"
visit "/"
driver.find("//span[contains(.,'localStorage is enabled')]").should_not be_empty
end
end
@ -1552,7 +1556,7 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
it "submits a form without clicking" do
driver.find("//form")[0].submit
@ -1608,7 +1612,7 @@ describe Capybara::Webkit::Driver do
context "keypress app" do
let(:driver) { driver_for_key_body "keypress" }
before { driver.visit("/") }
before { visit("/") }
it "returns the charCode for the keypressed" do
charCode_for("a").should == "97"
@ -1669,13 +1673,13 @@ describe Capybara::Webkit::Driver do
context "keydown app" do
let(:driver) { driver_for_key_body "keydown" }
before { driver.visit("/") }
before { visit("/") }
it_behaves_like "a keyupdown app"
end
context "keyup app" do
let(:driver) { driver_for_key_body "keyup" }
before { driver.visit("/") }
before { visit("/") }
it_behaves_like "a keyupdown app"
end
@ -1684,7 +1688,7 @@ describe Capybara::Webkit::Driver do
driver_for_html("Hello\0World")
end
before { driver.visit("/") }
before { visit("/") }
it "should include all the bytes in the source" do
driver.source.should == "Hello\0World"
@ -1712,24 +1716,24 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
it "has the expected text in the new window" do
driver.visit("/new_window")
visit("/new_window")
driver.within_window(driver.window_handles.last) do
driver.find("//p").first.text.should == "finished"
end
end
it "waits for the new window to load" do
driver.visit("/new_window?sleep=1")
visit("/new_window?sleep=1")
driver.within_window(driver.window_handles.last) do
driver.find("//p").first.text.should == "finished"
end
end
it "waits for the new window to load when the window location has changed" do
driver.visit("/new_window?sleep=2")
visit("/new_window?sleep=2")
driver.execute_script("setTimeout(function() { window.location = 'about:blank' }, 1000)")
driver.within_window(driver.window_handles.last) do
driver.find("//p").first.text.should == "finished"
@ -1737,27 +1741,27 @@ describe Capybara::Webkit::Driver do
end
it "switches back to the original window" do
driver.visit("/new_window")
visit("/new_window")
driver.within_window(driver.window_handles.last) { }
driver.find("//p").first.text.should == "bananas"
end
it "supports finding a window by name" do
driver.visit("/new_window")
visit("/new_window")
driver.within_window('myWindow') do
driver.find("//p").first.text.should == "finished"
end
end
it "supports finding a window by title" do
driver.visit("/new_window?sleep=5")
visit("/new_window?sleep=5")
driver.within_window('My New Window') do
driver.find("//p").first.text.should == "finished"
end
end
it "supports finding a window by url" do
driver.visit("/new_window?test")
visit("/new_window?test")
driver.within_window(driver_url(driver, "/?test")) do
driver.find("//p").first.text.should == "finished"
end
@ -1770,12 +1774,12 @@ describe Capybara::Webkit::Driver do
it "has a number of window handles equal to the number of open windows" do
driver.window_handles.size.should == 1
driver.visit("/new_window")
visit("/new_window")
driver.window_handles.size.should == 2
end
it "closes new windows on reset" do
driver.visit("/new_window")
visit("/new_window")
last_handle = driver.window_handles.last
driver.reset!
driver.window_handles.should_not include(last_handle)
@ -1800,7 +1804,7 @@ describe Capybara::Webkit::Driver do
end
end
driver.visit("/new_window")
visit("/new_window", driver)
driver.cookies['session_id'].should == session_id
end
@ -1837,11 +1841,11 @@ describe Capybara::Webkit::Driver do
end
end
before { driver.visit("/") }
before { visit("/") }
it "raises error for any loadFinished failure" do
expect do
driver.visit("/outer")
visit("/outer")
sleep 1
driver.find("//body")
end.to raise_error(Capybara::Webkit::InvalidResponseError)
@ -1865,7 +1869,7 @@ describe Capybara::Webkit::Driver do
it "can authenticate a request" do
driver.browser.authenticate('user', 'password')
driver.visit("/")
visit("/")
driver.html.should include("Basic "+Base64.encode64("user:password").strip)
end
end
@ -1907,37 +1911,37 @@ describe Capybara::Webkit::Driver do
before do
driver.browser.url_blacklist = ["http://example.org/path/to/file",
"http://example.com",
"#{Capybara.app_host}/script"]
"#{AppRunner.app_host}/script"]
end
it "should not fetch urls blocked by host" do
driver.visit("/")
visit("/")
driver.within_frame('frame1') do
driver.find("//body").first.text.should be_empty
end
end
it "should not fetch urls blocked by path" do
driver.visit('/')
visit('/')
driver.within_frame('frame2') do
driver.find("//body").first.text.should be_empty
end
end
it "should not fetch blocked scripts" do
driver.visit("/")
visit("/")
driver.html.should_not include("Script Run")
end
it "should fetch unblocked urls" do
driver.visit('/')
visit('/')
driver.within_frame('frame3') do
driver.find("//p").first.text.should == "Inner"
end
end
it "returns a status code for blocked urls" do
driver.visit("/")
visit("/")
driver.within_frame('frame1') do
driver.status_code.should == 200
end
@ -1971,37 +1975,37 @@ describe Capybara::Webkit::Driver do
it "should not raise a timeout error when zero" do
driver.browser.timeout = 0
lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
lambda { visit("/") }.should_not raise_error(Capybara::TimeoutError)
end
it "should raise a timeout error" do
driver.browser.timeout = 1
lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError, "Request timed out after 1 second")
lambda { visit("/") }.should raise_error(Capybara::TimeoutError, "Request timed out after 1 second")
end
it "should not raise an error when the timeout is high enough" do
driver.browser.timeout = 10
lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
lambda { visit("/") }.should_not raise_error(Capybara::TimeoutError)
end
it "should set the timeout for each request" do
driver.browser.timeout = 10
lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
lambda { visit("/") }.should_not raise_error(Capybara::TimeoutError)
driver.browser.timeout = 1
lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError)
lambda { visit("/") }.should raise_error(Capybara::TimeoutError)
end
it "should set the timeout for each request" do
driver.browser.timeout = 1
lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError)
lambda { visit("/") }.should raise_error(Capybara::TimeoutError)
driver.reset!
driver.browser.timeout = 10
lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError)
lambda { visit("/") }.should_not raise_error(Capybara::TimeoutError)
end
it "should raise a timeout on a slow form" do
driver.browser.timeout = 3
driver.visit("/")
visit("/")
driver.status_code.should == 200
driver.browser.timeout = 1
driver.find("//input").first.click
@ -2018,13 +2022,13 @@ describe Capybara::Webkit::Driver do
describe "logger app" do
it "logs nothing before turning on the logger" do
driver.visit("/")
visit("/")
log.should == ""
end
it "logs its commands after turning on the logger" do
driver.enable_logging
driver.visit("/")
visit("/")
log.should_not == ""
end