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

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

问题描述

好的,所以我想知道如果测试通过 jenkins 中止,如何让我的驱动程序/浏览器会话正确退出.在本地,如果我运行我的测试并中止它们,浏览器将正确退出.然而,通过詹金斯,这不会发生.如果我在我的测试在 selenium 网格上运行的测试阶段中止作业,浏览器保持打开状态 - 导致节点仍然显示为正在使用,因为它没有发现中止的作业应该终止其浏览器会话.

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.

我最理想的解决方案是使用如下所示的钩子,它可以判断它是否正在远程运行,并在中止/通过/失败时终止会话.但是,如果通过 jenkins 或 selenium 网格设置有任何解决方案,那也太好了!谢谢!

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 in seconds : 在 WebDriver 命令运行时允许浏览器会话挂起的秒数(例如:driver.get(url)).如果在 WebDriver 命令仍在处理时达到超时,会话将退出.最小值为 60.未指定、零或负值表示无限期等待.默认值:0

-cleanUpCycle(以毫秒为单位):指定集线器轮询正在运行的代理以查找超时(即挂起)线程的频率.还必须指定 timeout 选项.默认值: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 in seconds : 指定服务器自动终止前的超时时间在过去 X 秒内没有任何活动的会话.然后将释放测试槽以供另一个测试使用.这通常用于处理客户端崩溃.对于网格集线器/节点角色,还必须设置 cleanUpCycle.默认值:1800

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

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 本身中作为命令行文档提供.您可以参考this SO answer了解如何获取它并查看其他可用选项.

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 页面 这里.

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

希望有帮助!

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

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