WinAppDriver do not kill program process? - winforms

I am running UITest from my local Visual Studio 2022 against a remote server that have MyApp and WinAppDriver.exe installed.
By running these lines on the UITest MyApp starts up and the closes :
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", OrbitAppPath);
appCapabilities.SetCapability("deviceName", "WindowsPC");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
session.CloseApp();
session.Close();
session.Quit();
The problem is that after test MyApp will end up in the background process list, in this case it means that I can’t start MyApp again until I manually killed the process.
I have tried to add actions to trigger a normal MyApp close and this works, but the process is still hanging around.
If I manually start MyApp and then close it the process will also end up in the background process list but just a couple of seconds, then its gone.
Why do MyApp stay in the background process list while running UITest against WinAppDriver remote?
If the test is executed locally there is code that kills the process if it remains, it looks like this is not really possible on a remote server?
Regards
EDIT : MyApp will start up with a main form that is not shown on startup, instead a login form will be shown. I suspect that WinAppDriver close the login form and then the hidden main form keeps the process running. I have tried to find the hidden main form with session.WindowHandles but it does only hold the login form.

Related

WPF application is still running in background even after uninstall

I have a WPF app and an installer created using Setup Project in Visual Studio. The APP is having a tray icon and works based on that.
When I tried to uninstall the application folder gets uninstalled but the instance of the app is still running.
Is there a way I can close my app when it's uninstalled?.. Please help
When the program is uninstalled,you can use System.Diagnostics.Process.GetProcessesByName static method to check if the process exists.if exist,close it.
such as
var notepad = System.Diagnostics.Process.GetProcessesByName("notepad");
if (notepad.Length > 0)
notepad[0].Kill();

stop() method will be called when App crashes in CN1

I would like to close the threads or clear cache if the App crashes or Phone switch off or some other abrupt actions. Please advise if this method only gets called when the user kill the App or Signout from the App.
I'm pretty sure stop() gets called when you force kill the app, switch apps, lock the screen, phone auto locks, or anything really where the app is no longer visible.
You can also check edge cases by connecting your Android (in dev mode) to your laptop, downloading platform-tools (logcat), adding a print statement inside the stop() function and using the following command "./adb logcat -s "System.out" inside the platform-tools directory. Not sure how to do it on iOS.

Run tests without focus on newly created session

While I'm running protractor tests, each scenario creates new session, opens new Chrome window and changes focus on that window.
I'm looking for solution which either won't focus on newly created session, or will run all tests in background.
The tricky part is:
I'm using directConnect: true flag
in hooks in AfterScenario browser.restart() is invoked
Thanks for any advices.

Selenium IE webdriver - how to cope when the application closes the browser window and launches a new one?

I have an instance where user try to log-in application (simple webpage). After successful log in, the application closes the current page and open a new webpage. Rest of the business operations start from there.
Till the point API clicks log-in button, everything goes fine. After log in (once the log in webpage closes and a new session gets opened), the API throws "Unable to find browser". This is true as the original driver instance has been closed by the application.
Is there a way to achieve these kind of scenarios using selenium, as they are very common now-a days in a typical business application.
Thanks.
If you need to driver a different browser window or iframe, you need to use switchto. From the WebDriver faq:
Q: How do I handle pop up windows?
A: WebDriver offers the ability to cope with multiple windows. This is done by using the "WebDriver.switchTo().window()" method to switch to a window with a known name. If the name is not known, you can use "WebDriver.getWindowHandles()" to obtain a list of known windows. You may pass the handle to "switchTo().window()".
Thanks for the Answer.
I did the below to achieve my query.
Execute a javascript to open a new window.
IJavaScriptExecutor jScript = driver as IJavaScriptExecutor;
jScript.ExecuteScript("window.open()");
Switch to the newly opened window.
List<string> handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.Last());
Start the Navigate and Login operation on the new window
driver.Navigate().GoToUrl("Your website");
After login, the application will close the new window but the main driver window will still be alive.
Implement a simple SwitchTo() for the new window to start new business operations
List<string> handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.Last());

Restart WPF Application

My application has many views and I am using an AutoLogoffHelper class which maintains the timer for the application. Due to inactivity if the timer is 0, it call the log off event (which is also in the AutoLogoffhelper class).
As of now I am using Application.shutdown to completely shutdown the Application.
But Is there a way to restart the application or delete navigation history and session information and navigate to login screen?
Thanks.
To restart you can use Process.Start and the command line args (which automatically contain the application's path):
Process.Start(Environment.GetCommandLineArgs()[0]);

Resources