How to close a browser on a selenium RC server which lost it's client

穿精又带淫゛_ 提交于 2019-12-18 11:34:57

问题


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.

  • How can I make sure those browsers are closed?
  • Why isn't there a "keep-alive" part in the protocol to make sure the client is still responsive and if not kill the session?

  • 回答1:


    Any browser instance has a session_id you can store. Python example:

    >>> import selenium
    >>> browser = selenium.selenium("localhost",4444, "*firefox", "http://www.santiycr.com.ar")
    >>> browser.start()
    >>> browser.sessionId
    u'b4ad1f1d624e44d9af4200b26d7375cc'
    

    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




    回答2:


    >>> browser.stop()
    

    Does the same as Santi explains above.




    回答3:


    You can also just kill the process:

    Windows:

    taskkill /f /im iexplore.exe
    taskkill /f /im firefox.exe

    *nix:

    for i in `ps -A | grep firefox | awk '{print $1}'`; do kill -9 $i; done
    


    来源:https://stackoverflow.com/questions/1317844/how-to-close-a-browser-on-a-selenium-rc-server-which-lost-its-client

    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!