Watir +黄瓜连接被拒绝 [英] Watir+Cucumber Connection refused

查看:105
本文介绍了Watir +黄瓜连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我在测试中使用的是watir + cucumber,对于每个功能,我都在重用浏览器的实例,即我创建 @@ browser = Watir :: Browser.new ,然后在整个测试中重复使用,我使用的是 watir-webdriver ,到目前为止,我的测试运行良好,我只是添加了另一种方案,我始终收到以下错误消息:

Folks, I am using watir+cucumber in my tests and for each feature I am reusing the instance of the browser, that is I create the instance of @@browser = Watir::Browser.new and then reuse this through out my tests, I am using watir-webdriver, my tests where running fine till now, I just added another scenario and I consistently get the below error message:

Connection refused - connect(2) (Errno::ECONNREFUSED)
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `open'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `connect'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:542:in `start'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1035:in `request'


推荐答案

我今天遇到同一问题,并且花了 lot 的时间进行分析。

I run today in to the same issue, and I spent lot of time analysing it.

只有在 Explorer和Chrome

最后,我的结论如下:


  • 要在Cucumber测试后关闭浏览器,我使用了at_exit全局挂钩(如 http:// cukes中的建议。信息)。

  • 我还看到了Watir-webdriver(还有问题精通Selenium)链接相同的钩子以关闭chomedriver.exe进程(或与IE类似)。

  • 经过一番试验(也许是因为我对Ruby没有丰富的经验),链接到at_exit的订单非常关键。

  • To close the browser after Cucumber tests, I used the at_exit global hook (as recommended in http://cukes.info ).
  • I saw that the also Watir-webdriver (and probably Selenium) chain the same hook to close the chomedriver.exe process (or similar for IE).
  • after some trial (maybe because I have no deep experience in Ruby) I found that the order you use to chain to at_exit is critical.

当退出事件被通知给webdriver时,其进程已关闭,但是您的关闭例程被执行,试图这样做但它发现webdriver已关闭,因此返回一个错误,并使软件界面仍处于打开状态。
因此,您必须按以下方式放置代码:

As Exit event is signalled to webdriver, its processes are closed, but your closing routine is excuted, that tries to do the same but it finds webdriver closed so it returns an exeception and it leaves the software interface still open. So, you have to put the code this way:

    AfterConfiguration do |config|
       yourCodeStartUp()                    # Put your SETUP code here including the launch of webdriver
       at_exit 
           yourCodeTearDown()               # Put your CLOSING routine here
           puts 'stopped'
       end
    end

这样,您的常规at_exit代码在之前执行Webdriver之一,它可以有序地关闭系统。

This way your routine at_exit code is executed before the one of Webdriver and it can orderly shutdown the system.

这篇关于Watir +黄瓜连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆