javaseleniumselenium-webdriverselenium-gridselenium-grid2

How to determine a test has finished on a Selenium Grid


I am looking for a way I can ensure certain things happen after each test on a Selenium Grid node. (E.g. controlling certain processes on the node)

What is the best way to do on Selenium Grid? Perhaps I don't need to reinvent the wheel and there is some way I can use Selenium Grid infrastructure to determine when a test has finished on a node programatically?


Solution

  • You can do this in two ways

    1. If you want the cleanup to happen irrespective of what test finishes i.e., lets say you don’t care about the test, you merely want to know when the user calls driver.quit() which signals a terminate session message to the hub, so that you can run some sort of clean-up at the node.

    For achieving this you should be building your own custom proxy (by extending org.openqa.grid.selenium.proxy.DefaultRemoteProxy) and embed your logic of clean-up as part of afterSession() so that it gets executed after driver.quit() is executed but before the session is released by the Grid. You need to ensure that you don’t trigger any exceptions here. Please refer to this article that I wrote up on grid to help you understand how to work with custom proxies.

    (or)

    1. If you want to the cleanup to happen with respect to only certain specific tests i.e., lets say you may have been running some particular tests, for which you would like the screen-recording to be done and would like to stop it only for those tests that requested it.

    If this is what you want, then

    Now after you call driver.quit(), trigger a http operation (GET/POST) to the servlet that you added to the node, by making use of the IP and port address that you obtained from above.