How to get the full URL with the current path in Capybara
29,792
Solution 1
Try this:
url = URI.parse(current_url)
Solution 2
from capybara session doc:
Fully qualified URL of the current page
def current_url
driver.current_url
end
Path of the current page, without any domain information
def current_path
URI.parse(current_url).path
end
I think that what you are doing is not right
Solution 3
you could use have_current_path
:
expect(page).to have_current_path(new_user_path)
before seeing that I was doing something like:
def current_path
current_uri = URI.parse(page.current_url)
current_path = current_uri.path
current_path += "?#{current_uri.query}" if current_uri.query.present?
current_path
end
Author by
cloudrunner
Updated on April 28, 2020Comments
-
cloudrunner about 4 years
I'm new to writing tests in capybara and I'm having trouble getting the current URL of a page. I wrote it like this:
url = page.current_url + page.current_path
Somehow its just returning the base URL. Help is much appreciated.