Reputation: 108
I open a page and at the end of the test attempt to close it by calling my CelanUp() in a finally block but sometimes IEDriverServer and the browser are left open. There are no open popups when this happens.
public void CelanUp ()
{
string dialogResponse = string.Empty;
if (m_Driver != null)
{
//Dismiss all dialogs:
dialogResponse = CloseLogonDialog();
dialogResponse = CloseConfirmDialog();
m_Driver.Quit();
m_Driver = null;
}
if (dialogResponse != string.Empty)
{
throw new ApplicationException(dialogResponse);
}
}
What else can I do the close the browser and IEDriverServer?
Edit:
because Selenium's Quit is letting me down by leaving windows open i have looked at other solutions:
try
{
foreach (Process proc in Process.GetProcessesByName("IEDriverServer.exe"))
{
proc.Kill();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
Upvotes: 1
Views: 444
Reputation: 29032
Depending on what unit testing software you're using, instead of doing the logic like this, i'd recommend delegating the browser to the unit testing framework.
Put the cleanup method in an After
method. as in, After each test... do this
.
In java, using jUnit, it'd be written like this.
@After
public void cleanUp() {
driver.quit();
}
This means, after each test, call driver.quit()
Upvotes: 1