How to Close Application after test.
I'm trying to test an application which has a splash screen, followed by a settings dialog, followed by the main application window. After creating the WindowsDriver, the splash screen appears then shortly after the settings dialog. If i call windowsDriver.Quit() at this point, the application exits. However, if I click the ok button on the settings dialog then call quit, the main window of the application appears then stays open. I've tried using a PopUpWindowFinder and switching to the new window (which makes finding elements easier), but the application still stays open. I've also tried finding it with a desktop session, but it doesn't close then either. How do I get my application to close properly when the test is done?
I think WinAppDriver should implement the driver.quit() protocol as clean the related process complete, you can not repeat plant of test if the clean process is not reliable. may be start the new process in a job and clean it complete when needed. something like https://github.com/mback2k/group-job/blob/master/group-job/group-job.cpp or https://github.com/gnomeonwin/superpythonprocess
At user side, you may try to clean the application by handle by yourself, as you known the window hwnd, you can get related process and kill it, really bad, but a temp work around! like: https://github.com/congzhangzh/winuitestbypy/blob/master/notepad.py
If you do a Session.dispose() using the Appium .Net driver it will close the app. You can also look for you close button and send it a click, but the dispose should work.
Hi @sproatba,
Each Windows Application Driver session is associated with one application window that could be your main window, settings dialog, or even splash screen as long as they share the same process id. Once the session is established, you can switch between these windows as follows.
// Return all window handles associated with this process/application.
var allWindowHandles = session.WindowHandles;
// Switch to any window handle returned in the list
session.SwitchTo().Window(allWindowHandles[0]);
In the scenario you described above, you click the ok button that dismisses your settings dialog and the application session is still pointing to the dialog you just closed. Issuing Close, CloseApp or Quit simply attempt to close the dialog you already closed. Instead you would need to switch to the main window before issuing Quit command.
One way to verify that you have your session pointing at the right window is to perform window operations such as Maximize, CurrentWindowHandle, etc. More example on Window specific operation can be found on https://github.com/Microsoft/WinAppDriver/blob/v1.0-RC/Tests/WebDriverAPI/Window.cs#L154
In conclusion, windowsDriver.Quit() is indeed the correct way to terminate the application and delete the session. You just need to ensure that the session is in the right state when you invoke it to insure all the application window is closed properly.
As a side note,
WinAppDriver.exein the v1.0-RC release now takes a/forcequitparameter that you can specify to force kill the given application process when the window refuse to close. E.g.WinAppDriver.exe 127.0.0.1 4723 /forcequit