I have made a Windows Forms app to host my GUI for running selenium tests.

When the user presses the "run test" button, it launches an instance of chromedriver and runs the selected selenium test.

However, let's say that while the test is running, the user decides they want to stop the test, or simply not have the entire test run.

I have a button on the form that calls FixtureTearDown() in case this were to happen. FixtureTearDown is simply:

if (_driver != null) _driver.Quit();

However, if you DO press this "stop test" button, the driver closes, but the selenium test keeps executing the script as if the webdriver were still open, which then throws errors (because it can't find elements because the driver is closed, duh) and causes my Windows Forms app to crash.

So, is there a way to gracefully halt the running of a selenium script? Thanks in advance for the help, and i apologize if this is a dumb question, i am still new to selenium and c# in general.

I have never seen the browser remain open after driver.quit(). Which browser are you using? Are you sure your button click event quits the driver?
– LittlePandaMay 7 '15 at 4:27

1

The driver and the test scripts are different things. Yes, with driver.quit() you close the driver. But the test script is still running. So you need to stop the test itself. This can be managed by the testing framework that you are using. It should provide a solution to stop a started test script.
– TwaldigasMay 7 '15 at 6:46