Capybara ..启动浏览器失败说提供nodename或servname,或者不知道

时间:2018-02-17 11:17:15

标签: selenium capybara

我用ruby 2.4.1运行capybara2.10。浏览器启动失败了投掷错误..

/Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/common/platform.rb:178:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/common/platform.rb:178:in `localhost'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/common/service.rb:48:in `initialize'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/firefox/marionette/driver.rb:41:in `new'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/firefox/marionette/driver.rb:41:in `initialize'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/firefox/driver.rb:31:in `new'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/firefox/driver.rb:31:in `new'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver/common/driver.rb:52:in `for'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/selenium-webdriver-3.9.0/lib/selenium/webdriver.rb:84:in `for'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/capybara-2.18.0/lib/capybara/selenium/driver.rb:23:in `browser'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/capybara-2.18.0/lib/capybara/selenium/driver.rb:49:in `visit'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/capybara-2.18.0/lib/capybara/session.rb:274:in `visit'
    from /Users/<user>/Documents/<project>/vendor/bundle/gems/capybara-2.18.0/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
    from /Users/<user>/Documents/<project>/features/step_definitions/test1.rb:23:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

请帮我解决这个问题。谢谢。

2 个答案:

答案 0 :(得分:1)

127.0.0.1 localhost中添加此/etc/hosts可以解决此问题

答案 1 :(得分:0)

在那里运行的代码行是

info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM

对于您看到的错误,这意味着&#39; localhost&#39;并不是在你正在运行它的任何机器上解析。您是否碰巧将其从/etc/hosts文件中删除了?