microsoft / WinAppDriver

Windows Application Driver
MIT License
3.66k stars 1.4k forks source link

Using WinAppDriver launches two instances of the app #1881

Open sparticus1701 opened 1 year ago

sparticus1701 commented 1 year ago

I posted this topic to StackOverflow but there has not been any response:

https://stackoverflow.com/questions/75688172/problems-launching-automated-tests-with-appium-webdriver-winappdriver-on-wpf

In my test (posted there), it appears to launch two instances of the app. Others who use the same app do not see that behavior, so there must be something different about my computer but I have no idea where to look.

anunay1 commented 1 year ago

Can you post any code?

sparticus1701 commented 1 year ago

The code is on the Stack Overflow post, but here it is as well.

AutomationTest.zip

anunay1 commented 1 year ago

Why are you creating two sessions? _appSessionWindowsDriver = new WindowsDriver(new Uri(AppiumDriverURI), appSessionAppiumOptions); Assert.IsNotNull(_appSessionWindowsDriver); Assert.IsNotNull(_appSessionWindowsDriver.SessionId); _appSessionWindowsDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

        AppiumOptions desktopSessionAppiumOptions = new AppiumOptions();
        desktopSessionAppiumOptions.AddAdditionalCapability("app", "Root");
        desktopSessionAppiumOptions.AddAdditionalCapability("deviceName", DeviceName);
        _desktopSessionWindowsDriver = new WindowsDriver<WindowsElement>(new Uri(AppiumDriverURI), desktopSessionAppiumOptions);
sparticus1701 commented 1 year ago

All this is detailed in the Stack Overflow post. I'm trying to set up automated testing on my net48 WPF app following the methods found in this article: https://www.telerik.com/blogs/get-your-wpf-apps-automated-appium.

anunay1 commented 1 year ago

Does you application require interactions with other opened apps? Because the above link that you shared it uses the desktop session to interact with other apps.

sparticus1701 commented 1 year ago

No, it does not.

anunay1 commented 1 year ago

No, it does not.

Then why do you require two sessions.

sparticus1701 commented 1 year ago

I was simply following the article trying to get something to work. However, taking the other session out does not fix the problem.

anunay1 commented 1 year ago

the error says:

OpenQA.Selenium.WebDriverException HResult=0x80131500 Message=Object reference not set to an instance of an object. Source=WebDriver StackTrace: at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Appium.AppiumDriver1.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at OpenQA.Selenium.Appium.AppiumDriver1..ctor(Uri remoteAddress, ICapabilities appiumOptions) at OpenQA.Selenium.Appium.Windows.WindowsDriver`1..ctor(Uri remoteAddress, AppiumOptions AppiumOptions) at Automation.Tests.TestInitialize()

it's in initialize function, try to put up a breakpoint and check which line throws the error.

anunay1 commented 1 year ago

if you need any support send a teams invite.

sparticus1701 commented 1 year ago

You're not understanding the problem. The problem I'm seeing is that on my computer, WinAppDriver is launching my application to be tested twice, and it doesn't happen on other computers. Even when I rip out the desktop session from the article (attached), it still occurs.

When the test finishes, one of the two launched instances remains. AutomationTest.zip

Astorec commented 1 year ago

I had issues recently with this whilst trying to test stuff. I've found adding the Capability "ms:waitForAppLaunch", 10 stops it from happening most of the time, may need to adjust but 10 seems to be the sweet spot for mine. I think the WinAppDriver/Selenium thinks it's not loaded so it retries it. Though when I had the issue it would still test the application as long as the splash screen wasn't over the actualy window.

Not sure if you are still having the issue but thought I'd at least throw this here if anyone else is potentially having issues like this and is looking for some kind of solution.