Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Close Application after test. #159

Closed
sproatba opened this issue Mar 3, 2017 · 3 comments
Closed

How to Close Application after test. #159

sproatba opened this issue Mar 3, 2017 · 3 comments

Comments

@sproatba
Copy link

sproatba commented Mar 3, 2017

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?

@congzhangzh
Copy link

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

@yodurr
Copy link
Contributor

yodurr commented May 7, 2017

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.

@timotiusmargo
Copy link
Contributor

timotiusmargo commented Aug 18, 2017

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.exe in the v1.0-RC release now takes a /forcequit parameter 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants