如何关闭失去客户端的 selenium RC 服务器上的浏览器
假设客户端在 RC 服务器上启动 selenium 会话,但在会话中间客户端“离开”。浏览器将保持打开状态,最终,在足够多的此类丢弃会话之后,将有足够的“孤立”浏览器来减慢计算机的速度。
suppose a client starts a selenium session on an RC server, but at the middle of the session the client "went away". The browser will remain open, and eventually, after enough such dropped sessions, there will be enough "orphan" browsers to slow down the computer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
任何浏览器实例都有一个可以存储的 session_id。 Python 示例:
因此,如果您在测试开始时将这些 sessionId 存储在文件中,然后在测试结束时将其删除,那么您将获得一个日志文件,其中包含未正确结束的测试的会话。
现在使用 cron 或任何常规执行,您可以读取该文件,迭代存储在其中的 sessionId 并打开以下 url(使用浏览器甚至适合您的编程语言的 http 库):
http://localhost:4444/selenium-server/driver/?sessionId=THE-SESSION -ID&cmd=testComplete
这应该可以解决问题。
编辑:我发现这个问题非常有趣,因此在我的博客中创建了一篇关于该解决方案的帖子。如果你是一个 Python 爱好者,你会发现它很有趣:
http:// /www.santiycr.com.ar/djangosite/blog/posts/2009/aug/25/close-remaining-browsers-from-selenium-rc
Any browser instance has a session_id you can store. Python example:
So, if you store these sessionId in a file when your test starts and then remove it when your tests ends, you'll have a log file with sessions for tests that didn't end up properly.
Now using cron, or any regular execution, you can read that file, iterate over the sessionIds stored in it and open the following url (using a browser or even an http library for your programing language):
http://localhost:4444/selenium-server/driver/?sessionId=THE-SESSION-ID&cmd=testComplete
That should do the trick.
Edit: I found this question so interesting that created a post in my blog about the solution. If you're a python guy you'll find it interesting:
http://www.santiycr.com.ar/djangosite/blog/posts/2009/aug/25/close-remaining-browsers-from-selenium-rc
与 Santi 上面解释的相同。
Does the same as Santi explains above.
您也可以直接终止进程:
Windows:
taskkill /f /im iexplore.exe
taskkill /f /im firefox.exe
*nix:
You can also just kill the process:
Windows:
taskkill /f /im iexplore.exe
taskkill /f /im firefox.exe
*nix: