WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Failed to locate opened application window with appId: C:\Users\User\Desktop\xxx\xxx\xxx.exe, and processId: 14776

Open brandonwc5 opened this issue 7 years ago • 16 comments

I have a Windows Application with one single window (no splash screen, pop-ups or the like) which was working until recently. I've made no changes to the setup method, and cannot track down the cause of the issue. Both Task Manager and inspect.exe see the same process id as in the error message.

WinApp protocol:

POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 185
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723


HTTP/1.1 500 Internal Error
Content-Length: 263
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Users\\user\\Desktop\\xxx\\xxx\\xxx\\xxx.exe, and processId: 14776"}}

My code:

public WindowsDriver<WindowsElement> CreateNewSession(string appId, string argument = null)
        {
            // Create a new session
            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", appId);
            return new WindowsDriver<WindowsElement>(new Uri(TestConfig.WindowsApplicationDriverUrl), appCapabilities);
        }

...where AppID is the path to my executable.

The app seems to hang up and refuse to launch until the test has failed, then is released and launches. It's as if some process is hanging on to it. I have tried adding an implicit wait using TimeSpan when I create the new session, but the same problem still occurs (it just takes longer to happen).

As I said, this worked for weeks previously, and I've pored over any changes and cannot find any possible cause of the issue.

NOTE: my coworker pulled from the same branch, ran the same test, and it passes. Which just made me more frustrated.

brandonwc5 avatar May 09 '19 21:05 brandonwc5

Try to create another desktop session and find the window of your application in that session instead of the one which you've used to launch the application.

naeemakram avatar May 10 '19 11:05 naeemakram

Thank you for the quick response!

I have created a desktop session, and if I manually launch the application before I run, I do see my application window. However, because I have an entire suite of tests that was written by making a session for my actual app, I now have to update everything to use a child of the desktop session.

This seems a bit hacky, especially since I would be changing my coworker's tests, and my coworker does not have the same issue as me. If I could figure out what started causing this issue out of the blue it would be a much better solution.

My coworker and I have the same versions of WinAppDriver, VS, and everything else seems to be the same. And as I said, it was working as expected on my machine for months before it all of the sudden didn't.

brandonwc5 avatar May 10 '19 16:05 brandonwc5

For anyone reading in the future, I've created what I hope is a temporary branch with a workaround using a desktop session, which looks like this:

DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
            desktopCapabilities.SetCapability("platformName", "Windows");
            desktopCapabilities.SetCapability("app", "Root");
            desktopCapabilities.SetCapability("deviceName", "WindowsPC");
            WindowsDriver<WindowsElement> session = new WindowsDriver<WindowsElement>(new Uri(TestConfig.WindowsApplicationDriverUrl), desktopCapabilities);

            //  Grab the application window, which is a child of the Desktop window
            var ApplicationWindow = session.FindElementByName("ApplicationName");
            ApplicationWindow.Click();
            var ApplicationSessionHandle = ApplicationWindow.GetAttribute("NativeWindowHandle");
            ApplicationSessionHandle = (int.Parse(ApplicationSessionHandle)).ToString("x"); //Convert to hex

            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("appTopLevelWindow", ApplicationSessionHandle);
            var ApplicationSession = new WindowsDriver<WindowsElement>(new Uri(TestConfig.WindowsApplicationDriverUrl), appCapabilities);

            return ApplicationSession;

This does not launch my app, which I have to do manually before running the tests now.

brandonwc5 avatar May 13 '19 19:05 brandonwc5

Strange it's an error for you and not your co-worker. What else may have changed on your machine - did Windows recently update?

yodurr avatar May 21 '19 08:05 yodurr

Very strange! Not only that, but on old branches it still works on my machine. Yet like I say, it works all the time for my coworker, no matter the branch. The only code difference is in the application, nothing involving WAD or test setup has changed.

So the issue seems to be localized the new branch, on my machine only. We have identical versioning on every piece of relevant software.

Windows has not updated, but now that you mention it, I did do a BIOS update recently. I wonder if that had some unforeseen effect. I wouldn't see how that would be possible though, seeing as it still runs on old branches.

This may be something I'm going to have to find out on my own, seeing as it is so localized. Thank you for your help! If I can figure out the issue I will update.

brandonwc5 avatar May 21 '19 16:05 brandonwc5

Glad that my answer helped somehow. Maybe your coworker updated his Appium. Try updating your Appium from npm.

naeemakram avatar May 23 '19 10:05 naeemakram

Updating Appium fixed the issue! @naeemakram you were a great help.

brandonwc5 avatar Jun 05 '19 15:06 brandonwc5

You're welcome Brandon :)

naeemakram avatar Jun 15 '19 07:06 naeemakram

更新Appium解决了该问题!@naeemakram,您的帮助很大。 Appium What version, I also have this problem, updated or this error

zo-sansen avatar Apr 28 '20 23:04 zo-sansen

I'm not entirely sure which version we were working with at that time. Just run the npm update package.

naeemakram avatar Apr 29 '20 12:04 naeemakram

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

balaji-githubstore avatar Oct 12 '20 09:10 balaji-githubstore

Interesting insight Balaji... Will keep it in mind for future projects...

naeemakram avatar Oct 15 '20 11:10 naeemakram

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

Balaji's approach solved my issue!

gcalvoCR avatar Oct 29 '20 22:10 gcalvoCR

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

This helped me.. !! Thank you !!

RK0703 avatar Apr 06 '21 05:04 RK0703

Only this worked for me: appCapabilities.SetCapability("ms:waitForAppLaunch", "25"), from here

Other solutions, worked, but duplicated launched apps.

Thansk to all! Not an easy to solve problem.

PyNitid avatar Nov 25 '21 12:11 PyNitid

Failed to locate opened application window with appId: C:\Windows\System32\calc.exe, and processId: 8852

{ "appium:app": "C:\Windows\System32\calc.exe", "appium:driverClass": "io.appium.java_client.windows.WindowsDriver", "platformName": "Windows" }

Appl opened several times how to stop first time opened appl

Kalaivendhan123 avatar Mar 05 '24 13:03 Kalaivendhan123