水豚 'visit' 没有考虑 URL 中的“#”字符?
Capybara 'visit' is not considering '#' character in URL?
我 运行 遇到了一个奇怪的问题,我将我的应用程序主机设置为远程站点,如下所示:
Capybara.configure do |config|
config.default_max_wait_time = 10 # seconds
config.default_driver = :selenium_chrome
config.app_host = 'https://dev.stagingsite.com/widget-web/#/'
end
所有相对路径都在/#/
之后,所以在我的访问方法中(比如session.visit('login')
会带我到URL:
https://dev.stagingsite.com/widget-web/login#/
我试过在不同的地方添加'/',转义 #
但它似乎无法将相对 url 放在 #
之后,而是总是试图把它放在 widget-web/
之后
知道这里发生了什么吗?
来自 MDN 的 URL 文档:
It is worth noting that the part after the #, also known as the fragment identifier, is never sent to the server with the request.
检查你的服务器日志;您会看到任何对 /widget-web/#/
的请求都会作为对 /widget-web/
的请求发送。 #
阻止将其后的任何内容发送到服务器。
UPDATE 实际上,考虑了一会儿之后,如果您这样做,它可能会做您想做的事情 visit '#login'
因为访问中传递的片段会合并到 app_host片段
Capybara visit
不只是附加到 app_host
- 它解析 app_host
和传递给 visit
的内容并合并它们。 visit
接受完整的 url 或相对路径,您要设置的是 URL 片段 - visit
无法识别您想要的内容要做 - https://en.wikipedia.org/wiki/Fragment_identifier。如果你想在浏览器中设置片段,你需要将完整的 URL 传递给 visit
(可能通过使用你自己的辅助函数来构建你想要的 URL )
我 运行 遇到了一个奇怪的问题,我将我的应用程序主机设置为远程站点,如下所示:
Capybara.configure do |config|
config.default_max_wait_time = 10 # seconds
config.default_driver = :selenium_chrome
config.app_host = 'https://dev.stagingsite.com/widget-web/#/'
end
所有相对路径都在/#/
之后,所以在我的访问方法中(比如session.visit('login')
会带我到URL:
https://dev.stagingsite.com/widget-web/login#/
我试过在不同的地方添加'/',转义 #
但它似乎无法将相对 url 放在 #
之后,而是总是试图把它放在 widget-web/
知道这里发生了什么吗?
来自 MDN 的 URL 文档:
It is worth noting that the part after the #, also known as the fragment identifier, is never sent to the server with the request.
检查你的服务器日志;您会看到任何对 /widget-web/#/
的请求都会作为对 /widget-web/
的请求发送。 #
阻止将其后的任何内容发送到服务器。
UPDATE 实际上,考虑了一会儿之后,如果您这样做,它可能会做您想做的事情 visit '#login'
因为访问中传递的片段会合并到 app_host片段
Capybara visit
不只是附加到 app_host
- 它解析 app_host
和传递给 visit
的内容并合并它们。 visit
接受完整的 url 或相对路径,您要设置的是 URL 片段 - visit
无法识别您想要的内容要做 - https://en.wikipedia.org/wiki/Fragment_identifier。如果你想在浏览器中设置片段,你需要将完整的 URL 传递给 visit
(可能通过使用你自己的辅助函数来构建你想要的 URL )