I am using testNG with selenium to write my test cases, I observed a strange problem that is When I run my test cases, and if any test case fails or any other exception occur in between the test case execution, the AfterTest method doesn't run but the driver.quit() method is written only inside the AfterTest method, so in this case it doesn't actually quits the driver and it keeps running even after test case execution is finished.
The other problem is that during the execution my application opens the new windows of browser but when the execution is successfully completed only single window is closed on which I am working and the other browser windows remained open. Kindly advice some good approach t o handle this situation.