创建我的第一个 Selenium 测试,我得到以下结果
Error:
LoginsTest#test_login:
Errno::ENOENT: No such file or directory - /root/.webdrivers/chromedriver
test/system/logins_test.rb:6:in `block in <class:LoginsTest>'
Error:
LoginsTest#test_login:
Errno::ENOENT: No such file or directory - /root/.webdrivers/chromedriver
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/child_process.rb:58:in `spawn'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/child_process.rb:58:in `start'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/service_manager.rb:104:in `start_process'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/service_manager.rb:57:in `block in start'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/socket_lock.rb:42:in `locked'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/service_manager.rb:55:in `start'
<internal:kernel>:90:in `tap'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/service.rb:92:in `launch'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/driver.rb:328:in `service_url'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/local_driver.rb:28:in `initialize_local_driver'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/chrome/driver.rb:34:in `initialize'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/driver.rb:47:in `new'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/driver.rb:47:in `for'
/usr/local/bundle/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver.rb:89:in `for'
/usr/local/bundle/gems/capybara-3.40.0/lib/capybara/selenium/driver.rb:75:in `browser'
/usr/local/bundle/gems/actionpack-7.2.1.2/lib/action_dispatch/system_testing/driver.rb:57:in `block in register_selenium'
<internal:kernel>:90:in `tap'
/usr/local/bundle/gems/actionpack-7.2.1.2/lib/action_dispatch/system_testing/driver.rb:56:in `register_selenium'
/usr/local/bundle/gems/actionpack-7.2.1.2/lib/action_dispatch/system_testing/driver.rb:43:in `block in register'
/usr/local/bundle/gems/capybara-3.40.0/lib/capybara/session.rb:106:in `driver'
/usr/local/bundle/gems/capybara-3.40.0/lib/capybara/session.rb:92:in `initialize'
/usr/local/bundle/gems/capybara-3.40.0/lib/capybara.rb:422:in `new'
/usr/local/bundle/gems/capybara-3.40.0/lib/capybara.rb:422:in `block in session_pool'
/usr/local/bundle/gems/capybara-3.40.0/lib/capybara.rb:317:in `current_session'
/usr/local/bundle/gems/capybara-3.40.0/lib/capybara/dsl.rb:46:in `page'
/usr/local/bundle/gems/actionpack-7.2.1.2/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:116:in `save_image'
/usr/local/bundle/gems/actionpack-7.2.1.2/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:46:in `take_screenshot'
/usr/local/bundle/gems/actionpack-7.2.1.2/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:56:in `take_failed_screenshot'
/usr/local/bundle/gems/actionpack-7.2.1.2/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb:10:in `before_teardown'
如果我在
child_process.rb
中放入调试器调用:
@pid = Process.spawn(*@command, options)
WebDriver.logger.debug(" -> pid: #{@pid}", id: :process)
Process.detach(@pid) if detach
rescue => e
debugger if Rails.env.test?
nil
raise e
end
@command
中的文件显然存在:
(ruby) @command
["/root/.webdrivers/chromedriver", "--port=9515"]
(rdbg) options
{[:out, :err]=>"/dev/null", :pgroup=>true}
(ruby) `ls -l /root/.webdrivers/chromedriver`
"-rwxr-xr-x 1 root root 15039112 Oct 30 00:35 /root/.webdrivers/chromedriver\n"
我正在以正确的用户身份运行:
(ruby) `whoami`
"root\n"
我错过了什么?
按照 Ryan Bigg 博客文章中的建议,安装一些缺失的 apk 包修复了这个问题
~/.webdrivers # apk add gcompat glib nss libxcb libgcc
(1/3) Installing musl-obstack (1.2.3-r2)
(2/3) Installing libucontext (1.2-r3)
(3/3) Installing gcompat (1.1.0-r4)
OK: 1294 MiB in 258 packages
~/.webdrivers # ./chromedriver
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1730321023.240][SEVERE]: bind() failed: Address not available (99)
ChromeDriver was started successfully.
现在在系统测试中出现不同的错误,但这确实解决了“找不到文件”错误。