简体   繁体   English

黄瓜在After hook中使@ browser = nil

[英]Cucumber makes @browser=nil in After hook

I want to keep browser open for several scenarios, but from After hook method rb_language.rb/end_scenario where @current_world=nil and @browser is a part on @current_world object. 我想保持浏览器打开几个场景,但是来自After hook方法rb_language.rb/end_scenario ,其中@current_world=nil@browser@current_world对象的一部分。

So even if I don't call @browser.close in After hook, @browser object is nil and I can't use it anymore while browser window is still open. 所以,即使我没有在After hook中调用@browser.close@browser.close @browser对象也是nil ,当浏览器窗口仍然打开时我不能再使用它了。

Is there any way to use opened browser window for several scenarios? 有没有办法在几种情况下使用打开的浏览器窗口?

If I remember correctly I defined a variable called browser (not @browser) in my hooks file, outside of any cucumber hooks, that created my browser instance and then assigned the instance variable @browser to point to it in my before hook, ie @browser = browser. 如果我没记错的话,我在我的钩子文件中定义了一个名为browser(不是@browser)的变量,在任何黄瓜钩子之外,创建了我的浏览器实例,然后在我之前的钩子中分配了实例变量@browser指向它,即@浏览器=浏览器。 I then handled the teardown of both in my at_exit hook. 然后我在at_exit钩子中处理了两者的拆解。

If that doesn't make sense or doesn't work, could you please post your hooks file (or an edited version of it)? 如果这没有意义或不起作用,你能否发布你的钩子文件(或它的编辑版本)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM