【发布时间】:2021-10-11 01:14:54
【问题描述】:
我目前正在运行 WSL2。我在系统中安装了google-chrome-stable和chromedriver。
google-chrome-stable:谷歌浏览器 92.0.4515.131
chromedriver: ChromeDriver 92.0.4515.43
# Gemfile
group :test do
gem "capybara", ">= 3.26"
gem "selenium-webdriver"
gem "webdrivers"
end
# test/application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome do |option|
option.add_argument "no-sandbox"
end
end
# test/system/users_test.rb
class UsersTest < ApplicationSystemTestCase
def setup
Capybara.app_host = "http://app.example.com/"
end
test "user sign up" do
visit new_user_path
fill_in "user[name]", with: "Jane Hemmingway"
fill_in "user[email]", with: "jane@example.com"
fill_in "user[password]", with: "secret_password"
click_button "get started"
assert_redirected_to accounts_path
end
end
但是当我运行这个测试时,它会抛出一个错误。
Error:
UsersTest#test_user_sign_up:
Selenium::WebDriver::Error::UnknownError: unknown error: net::ERR_NAME_NOT_RESOLVED
(Session info: headless chrome=92.0.4515.131)
test/system/users_test.rb:9:in `block in <class:UsersTest>'
我对这个错误的含义感到困惑。有什么办法可以解决吗?
【问题讨论】:
-
你可以试试
option.add_argument "no-sandbox"而不是option.add_argument "--no-sandbox" -
好的,我想我知道问题出在哪里了。
Capybara.app_host = "http://app.example.com/"是这里的罪魁祸首。当我删除它并更改我的路线时,测试会成功运行。 -
但是,路由有子域约束。那么如何使用
app子域制作水豚访问路线?有什么线索吗?如果我覆盖Capybara.app_host测试将失败并出现问题中提到的错误。
标签: ruby-on-rails ruby selenium selenium-webdriver capybara