3

我使用 watir-webdriver / MiniTest 框架已经不到一个月了,而且进展非常顺利。但是,每次启动新版本时我都需要运行的包包含不到 100 个单独的测试,这需要一个多小时才能完成所有测试。

这就是为什么我在 Centos-6-x86_64 上使用 Ruby、RVM、Watir、Rails 和 Firefox 设置 VPS 的原因。这样我就不必在我的笔记本电脑上运行脚本并等待它们完成,然后我才能做任何其他事情。

但是,当我尝试使用 irb 测试 watir 是否正常工作时,出现以下错误:

 Errno::EAFNOSUPPORT: Address family not supported by protocol - socket(2)

测试:

[root@V-9876 ~]# irb
1.9.3p448 :001 > require 'watir-webdriver'
 => true
1.9.3p448 :002 > b = Watir::Browser.start 'www.google.com'
Errno::EAFNOSUPPORT: Address family not supported by protocol - socket(2)
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/port_prober.rb:28:in `initialize'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/port_prober.rb:28:in `new'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/port_prober.rb:28:in `block in free?'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/port_prober.rb:26:in `each'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/port_prober.rb:26:in `free?'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/port_prober.rb:5:in `above'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/firefox/launcher.rb:49:in `find_free_port'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/firefox/launcher.rb:33:in `block in launch'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/    lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/driver.rb:31:in `new'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/     lib/selenium/webdriver/common/driver.rb:31:in `for'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/      lib/selenium/webdriver.rb:67:in `for'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/ watir-     webdriver/browser.rb:46:in `initialize'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/ watir-    webdriver/browser.rb:29:in `new'
        from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/ watir-     webdriver/browser.rb:29:in `start'
        from (irb):2
         from /usr/local/rvm/rubies/ruby-1.9.3-p448/bin/irb:13:in `<main>'1.9.3p4     1.9.3p448 :003 >

我一直在研究这个错误,我发现许多网站声称它是通过禁用 ipv6 来修复的,但我仍然收到这个错误。

不确定这是否会有所不同,但我还在此 VPS 上安装了 NGinX / PHP / MySQL

编辑 - 红宝石文件发布在下面

require "watir-webdriver"
require 'watir-webdriver'
require 'headless'
headless = Headless.new
headless.start

browser = Watir::Browser.new :ff
browser.goto "http://remove-url-for-this-post.com" 
puts ("Starting SearchValSelectFields")
browser.select_list(:id, "edit-select-sector").select("Finance and Accounting")
sleep (5)
browser.select_list(:id, "edit-select-subsector--3").select("All Sub-sector")
browser.select_list(:id, "edit-select-location").select("Singapore")
browser.button(:value,"Search").click
assert(browser.text.include?("Salary and employment forecast"))
browser.screenshots ('..\screenshots\SearchValSelectFields.png')
browser.select_list(:id, "edit-select-sector").select("Select Sector")
sleep(3)
browser.select_list(:id, "edit-select-subsector--2").select("Select Sub-sector")
sleep(3)
browser.select_list(:id, "edit-select-location").select("Select Location")
sleep(3)
browser.button(:value,"Search").click
assert(browser.text.include?("This field is required"))
browser.close
headless.destroy

有任何想法吗?

4

1 回答 1

7

有人在工作中设法解决了这个问题。他说:

They try to connect twice
first to 127.0.0.1 port 7055
then too ::1 port 7055
second one fails
::1 is localhost of IPv6
so you seem to be connecting localhost
and in your server look at /etc/hosts
localhost resolves to the ::1

因此,您所要做的就是编辑您的 /etc/hosts 文件并注释掉 ::1 或根据需要将其删除

于 2013-11-11T16:39:24.817 回答