How can I close opened drivers during Selenium tests with TestNG
I have a Selenium project which runs fine on my local machine but has a problem when run by Hudson. The problem is that it doesn't close opened drivers at the end of each test.
Prerequisites: This project is run by Hudson on a Selenium grid server. (I have also run it on my local machine on a Selenium grid server and the problem doesn't occur)
So, I have a BeforeAndAfter class which is implemented by each test class.
Inside BeforeAndAfter I have a @BeforeClass method which starts a new driver: driver = new RemoteWebDriver(new URL(url), capability); and a @AfterClass method which does the driver.quit();
Everytime i run the testNG.xml file on the remote Selenium Grid server, it opens a driver for each test class but it leaves it open until the end of the last test when it closes all drivers (all browser windows)
My testNG file looks like this:
<parameter name="browser" value="firefox"/>
<parameter name="url" value="http://10.32.999.99:999/wd/hub"/>
<test name="Regression on test grid">
<classes>
<class name="tests.PageTests.ArticlesPageTest"/>
<class name="tests.PageTests.CuratorsPageTest"/>
<class name="tests.FlowTests.NavigateThroughFindings"/>
<class name="tests.PageTests.DiffToolTest"/>
<class name="tests.PageTests.ReportsAdminTest"/>
</classes>
</test>
Any thoughts on the problem ?
PS: In fact, the problem is that the @AfterClass method is not closing the driver after each test class releasing the memory.
in case of testNG you can use @AfterClass (alwaysRun=true).
Also, in our project we have created batch file to kill the processes after any test class complition. like if any IEdriver.exe or firefox.exe is running you force kill it using windows commads.Make sure you do it before next test class begins by calling batch in Setup fixture method.
链接地址: http://www.djcxy.com/p/50688.html上一篇: Selenium服务器不打开浏览器