如果在Jenkins上终止测试,则Selenium驱动程序实例仍然存在 [英] Selenium driver instance persists if test is aborted on Jenkins

查看:55
本文介绍了如果在Jenkins上终止测试,则Selenium驱动程序实例仍然存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我想知道如果通过jenkins中止测试,如何使我的驱动程序/浏览器会话正确退出.在本地,如果我运行测试并中止测试,浏览器将正确退出.但是,通过詹金斯(Jenkins)不会发生这种情况.如果我在硒网格上运行测试的测试阶段中止该作业,则浏览器保持打开状态-导致该节点仍显示为正在使用,因为它没有意识到该中止的作业本应杀死其浏览器会话

Ok, so I am wondering how I can get my driver/browser sessions to properly exit if a test is aborted via jenkins. Locally, if I run my tests and abort them, the browser will quit properly. Via jenkins however, this does not happen. If I abort the job during the test phase where my tests are running on the selenium grid, the browser stays open - causing the node to still show up as being used because it did not pick up that the aborted job should have killed its browser session.

我一直在搞黄瓜钩子,但是我想得更多,所以我不确定是否可以用钩子来解决这个问题,因为在本地运行时不会发生这种情况.我现在认为这应该是硒网格或詹金斯的设置.

I have been messing around with cucumber hooks, but the more I think about it I am not sure if I can handle this with a hook since when ran locally this behavior does not happen. I am now thinking this needs to be either a setting on the selenium grid or jenkins.

我最理想的解决方案是使用一个类似于下面的钩子,该钩子可以判断它是否正在远程运行,并在中止/通过/失败时终止会话.但是,如果通过詹金斯或硒网格设置有任何解决方案,那也将非常棒!谢谢!

My most optimal solution would be to use a hook like the one below that could tell if it was being run remotely and kill the session if aborted/passed/failed. But if there is any solution via jenkins or the selenium grid settings that would be great too! Thank you!

this.registerHandler('After', function (event, done) {
     // Some code to clear browser session 
    done();
});

推荐答案

我认为您无需在客户端代码上做任何额外的事情.

I dont think you need to do anything extra here at your client code.

Selenium Grid专门具有用于进行此类清理的三个参数.

The selenium Grid specifically has three parameters that are meant for these sort of cleanups.

  • -browserTimeout (以秒为单位):运行WebDriver命令时允许浏览器会话挂起的秒数(示例:driver.get(url)).如果仍在处理WebDriver命令时达到超时,则会话将退出.最小值为60.未指定,零或负值表示无限期等待. Default: 0

  • -browserTimeout in seconds : number of seconds a browser session is allowed to hang while a WebDriver command is running (example: driver.get(url)). If the timeout is reached while a WebDriver command is still processing, the session will quit. Minimum value is 60. An unspecified, zero, or negative value means wait indefinitely. Default: 0

-cleanUpCycle (以毫秒为单位):指定集线器多久轮询一次正在运行的代理,以了解是否存在超时(即挂起)线程.还必须指定 timeout 选项. Default: 5000 (5秒)

-cleanUpCycle in milliseconds : specifies how often the hub will poll running proxies for timed-out (i.e. hung) threads. Must also specify timeout option.Default: 5000 (5 seconds)

-timeout -sessionTimeout (以秒为单位):指定在服务器自动终止最近一次没有任何活动的会话之前的超时X秒.然后将释放测试插槽,以供其他测试使用.这通常用于照顾客户端崩溃.对于网格中心/节点角色,还必须设置cleanUpCycle. Default: 1800

-timeout, -sessionTimeout in seconds : Specifies the timeout before the server automatically kills a session that hasn't had any activity in the last X seconds. The test slot will then be released for another test to use. This is typically used to take care of client crashes. For grid hub/node roles, cleanUpCycle must also be set. Default: 1800

结合使用以上三个参数,可以将节点配置为自动关闭孤立的浏览器实例和会话.

Using a combination of all the above 3 parameters, you can configure your node to automatically close orphaned browser instances and sessions.

此文档可作为命令行文档在selenium uber jar中使用.您可以参考 SO答案,以了解如何获取它以及查看其他可用选项.

This documentation is available within the selenium uber jar itself as command line documentation. You can refer to this SO answer to learn how to get it and see what other options are available.

在Grid'2 Wiki页面timeouts相关的其他文档" rel ="nofollow noreferrer">此处.

There's some additional documentation related to timeouts on the Grid'2 wiki page here.

希望有帮助!

这篇关于如果在Jenkins上终止测试,则Selenium驱动程序实例仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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