2

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.

S.Orioli
  • 443
  • 6
  • 21
schrdori
  • 51
  • 3
  • If it runs as expected in debug mode but not in release mode, it would assume its a bug. You're probably better of asking your question [here](https://github.com/Microsoft/WinAppDriver/issues). – PixelPlex Apr 29 '19 at 09:48
  • thanks for your fast response, i'm gonna try. I wasn't sure if it's a WinAppDriver or a VS Test Explorer Issue... – schrdori Apr 29 '19 at 12:40
  • No problem at all! I'm not sure either though, but since winappdriver starts the program, I would make sense to think its winappdriver's responsibility to bring the program to the foreground. – PixelPlex Apr 29 '19 at 13:19
  • 1
    @ds.nikolai Hi, did you find a solution to this? I'm having the same issue. – jira Jan 09 '20 at 07:49

0 Answers0