I am using Visual Studio 2019
, and the WinAppDriver
to run Unit Tests on a simple WPF Application
.
For that i use the Test Explorer integrated in VS.
Problem: When i run my test via Test Explorer
it opens my desired window in the background (behind Visual Studio); then it performs the clicks` on the correct locations but the mouse is clicking in my Visual Studio and not on my desired application window because it wasn't brought to the front.
When i start the Test in Debug
mode everything works fine. Window opens focused and in front. Clicks hit right buttons etc. So my Code can't be the issue?!
I tried waiting for it to be ready (Clickable) before clicking like that:
private void WaitFindClick(string id, string wpf_type)
{
var wait = new DefaultWait<WindowsDriver<WindowsElement>>(session);
wait.Timeout = TimeSpan.FromSeconds(5);
wait.PollingInterval = TimeSpan.FromMilliseconds(100);
wait.IgnoreExceptionTypes(typeof(InvalidOperationException));
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath($"//{wpf_type}[@AutomationId=\"{id}\"]")));
session.FindElementByAccessibilityId(id).Click();
}
Summarising, Test Explorer
works fine in Debug
mode, but not in normal
mode it opens the App correctly but doesn't bring it to front, so the Click will hit Visual Studio and not the desired App.
What is going wrong? How to fix Test Explorer
to automatically bring the Test App to the front?
I hope i'm right here. This is my first question ever so if i missed sth please tell me. Have a good day and thanks in advance!
EDIT:
I found a Workaround by setting the Window.Topmost = true;
property in my MainWindow()
-Constructor but its not really what i am looking for.