JRuby:Watir在启动浏览器时挂起

时间:2012-06-11 15:39:04

标签: java ruby jruby watir

我有Windows 7企业版,我正在尝试运行JRuby。我为Ruby(1.9.3),Java(jdk - 1.6.7)和JRuby(1.7preview)设置了我的环境变量。我有一个网络驱动器,但我创建了一个HOME系统变量,它似乎正在工作,因为我可以下载Ruby和& JRuby成功并将它们保存到我的本地驱动器中。

当我尝试启动浏览器(即firefox,chrome)时,它似乎挂起了JRuby,但不是Ruby。以下是 JRuby 在尝试执行10分钟后的跟踪:

irb(main):003:0> require 'rubygems'
=> false
irb(main):004:0> require 'watir-webdriver'
=> true
irb(main):005:0> b = Watir::Browser.new :ie
IRB::Abort: abort then interrupt! *<--Note I killed the process after 10 minutes*
    from c:/Ruby/jruby-bin-1.7.0.preview1/jruby-1.7.0.preview1/lib/ruby/gems
    /shared/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/common 
    /port_prober.rb:24:in `free?'       
    from c:/Ruby/jruby-bin-1.7.0.preview1/jruby-1.7.0.preview1/lib/ruby/gems
    /shared/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/common  
    /port_prober.rb:5:in `above'        
    from c:/Ruby/jruby-bin-1.7.0.preview1/jruby-1.7.0.preview1/lib/ruby/gems
    /shared/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/ie/bridge.rb:17:in
   `initialize'
    from org/jruby/RubyHash.java:1429:in `delete'
    from c:/Ruby/jruby-bin-1.7.0.preview1/jruby-1.7.0.preview1/lib/ruby/gems
    /shared/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/ie/bridge.rb:17:in
    `initialize'
    from c:/Ruby/jruby-bin-1.7.0.preview1/jruby-1.7.0.preview1/lib/ruby/gems
    /shared/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/common/driver.rb:3
    5:in `for'
    from c:/Ruby/jruby-bin-1.7.0.preview1/jruby-1.7.0.preview1/lib/ruby/gems
    /shared/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver.rb:65:in `for'
    from c:/Ruby/jruby-bin-1.7.0.preview1/jruby-1.7.0.preview1/lib/ruby/gems
    /shared/gems/watir-webdriver-0.6.1/lib/watir-webdriver/browser.rb:35:in   
    `initialize'
    from (irb):5:in `evaluate'
    from org/jruby/RubyKernel.java:1037:in `eval'
    from org/jruby/RubyKernel.java:1353:in `loop'
    from org/jruby/RubyKernel.java:1146:in `catch'
    from org/jruby/RubyKernel.java:1146:in `catch'
    from c:\Ruby\jruby-bin-1.7.0.preview1\jruby-1.7.0.preview1\bin\irb:13:in
    `(root)'

JRuby似乎挂了,因为它正在寻找一个开放的端口。我们必须为我们的网络使用HTTP代理,我也为此设置了一个系统变量。我真的不知道为什么Watir会为Ruby而不是JRuby工作。

1 个答案:

答案 0 :(得分:6)

我有类似的问题 - selenium-webdriver在使用JRuby和Java 6时没有打开浏览器,但是它适用于Java 7。

我发现Java 6似乎有一些IPv6问题,并且在IPv6接口上找不到自由端口。

解决方案是将-Djava.net.preferIPv4Stack=true添加到JAVA_OPTS,告诉Java在可能的情况下优先选择IPv4 over IPv6。