Winappdriver: Test fails with "Failed to locate opened application window with appId"

Created on 19 Feb 2018  Â·  15Comments  Â·  Source: microsoft/WinAppDriver

Hi all,
I started having this problem when the driver fails to locate the app around a month ago. I am getting it approximately 3/4 times I am trying to run tests. Right now it makes it impossible to have a stable automation running.

Here is the full log:
(I replaced app path with xxx..)

C:\Users\xxx>appium
[Appium] Welcome to Appium v1.7.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"app":"Z:\xxx\xxx\xxxx\xx.exe","deviceName":"WindowsPC","platformName":"Windows","platormName":"Windows"},"capabilities":{"desiredCapabilities":{"app":"Z:\xxx\xxx\xxxx\xx.exe","deviceName":"WindowsPC","platformName":"Windows","platormName":"Windows"},"firstMatch":[{"platformName":"windows"}]}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"Z:\xxx\xxx\xxxx\xx.exe","deviceName":"WindowsPC","platformName":"Windows","platormName":"Windows"},null,{"desiredCapabilities":{"app":"Z:\xxx\xxx\xxx\xx.exe","deviceName":"WindowsPC","platformName":"Windows","platormName":"Windows"},"firstMatch":[{"platformName":"windows"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1519059770835 (17:02:50 GMT+0000 (GMT Standard Time))
[Appium] Merged W3C capabilities {"desiredCapabilities":{"app":"Z:\xxx\xx... into desiredCapabilities object {"app":"Z:\xxx\xxx\xxxx\xxx…

[Appium] Creating new WindowsDriver (v1.0.0) session
[Appium] Capabilities:
[Appium] app: Z:\xxx\xxx\xxx\xxx.exe
[Appium] deviceName: WindowsPC
[Appium] platformName: windows
[Appium] platormName: Windows

[BaseDriver] The following capabilities were provided, but are not recognized by appium: app, platormName.
[BaseDriver] Session created with session id: 34080115-3191-4b3b-933d-9d7b403b05f6

[WinAppDriver] You must use WinAppDriver version 1.0
[WinAppDriver] Verifying WinAppDriver version 1.0 is installed via comparing the checksum.

[debug] [WinAppDriver] WinAppDriver changed state to 'starting'
[WinAppDriver] Killing any old WinAppDrivers on same port, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"4724 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I winappdriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a))
[WinAppDriver] No old WinAppDrivers seemed to exist
[WinAppDriver] Spawning winappdriver with: 4724/wd/hub
[WinAppDriver] [STDOUT] Windows Application Driver listening for requests at: http://127.0.0.1:4724/wd/hub
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:4724/wd/hub/status] with no body
[WinAppDriver] [STDOUT] Press ENTER to exit.
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] ==========================================
[WinAppDriver] [STDOUT] GET /wd/hub/status HTTP/1.1
[WinAppDriver] [STDOUT] Accept: /
[WinAppDriver] [STDOUT] Connection: keep-alive
[WinAppDriver] [STDOUT] Content-Type: application/json
[WinAppDriver] [STDOUT] Host: 127.0.0.1:4724
[WinAppDriver] [STDOUT] User-Agent: appium
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] HTTP/1.1 200 OK
[WinAppDriver] [STDOUT] Content-Length: 139
[WinAppDriver] [STDOUT] Content-Type: application/json
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] {"build":{"revision":"17001","time":"Tue Oct 17 18:04:03 2017","version":"1.0.1710"},"os":{"arch":"amd64","name":"windows","version":"10"}}
[debug] [JSONWP Proxy] Got response with status 200: "{\"build\":{\"revision\":\"17001\",\"time\":\"Tue Oct 17 18:04:03 2017\",\"version\":\"1.0.1710\"},\"os\":{\"arch\":\"amd64\",\"name\":\"windows\",\"version\":\"10\"}}"
[WinAppDriver] Status call returned 200. we're online and ready to run tests
[debug] [WinAppDriver] WinAppDriver changed state to 'online'
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4724/wd/hub/session] with body: {"desiredCapabilities":{"app":"Z:\xxx\xxx\xxxx\xx.exe","deviceName":"WindowsPC","platformName":"windows","platormName":"Windows"}}
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] ==========================================
[WinAppDriver] [STDOUT] POST /wd/hub/session HTTP/1.1
[WinAppDriver] [STDOUT] Accept: /
[WinAppDriver] [STDOUT] Connection: keep-alive
[WinAppDriver] [STDOUT] Content-Length: 186
[WinAppDriver] [STDOUT] Content-Type: application/json
[WinAppDriver] [STDOUT] Host: 127.0.0.1:4724
[WinAppDriver] [STDOUT] User-Agent: appium
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] {"desiredCapabilities":{"app":"Z:\xxx\xxx\xxxx\xx.exe","deviceName":"WindowsPC","platformName":"windows","platormName":"Windows"}}
[WinAppDriver] [STDOUT] HTTP/1.1 500 Internal Error
[WinAppDriver] [STDOUT] Content-Length: 214
[WinAppDriver] [STDOUT] Content-Type: application/json
[WinAppDriver] [STDOUT]
[WinAppDriver] [STDOUT] {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId:Z:\xxx\xxx\xxxx\xx.exe, and processId: 7000"}}
[debug] [WinAppDriver] Deleting WinAppDriver session
[MJSONWP] Encountered internal error running command: {"w3cStatus":400,"jsonwp":{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: Z:\xxx\xxx\xxxx\xx.exe, and processId: 7000"}}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: Z:\xxx\xxx\xxxx\xx.exe, and processId: 7000"}}
at JWProxy.proxy$ (C:\Users\xxx\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:152:13)
at tryCatch (C:\Users\xxx\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\xxx\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\xxx\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (C:\Users\xxx\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
at
[HTTP] <-- POST /wd/hub/session 500 7023 ms - 152

The test obviously fails but the app is actually launched. So location is not an issue.
Is there something I am doing wrong? It used to work fine..?

I am using Appium from node version 1.7.2
WindowsDriver (v1.0.0)

Many thanks,
Ewa

Most helpful comment

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");

All 15 comments

Hi @ellnika.

Can you provide additional information on what kind of application you are running (e.g. what type of application Win32, UWP, XAML, if there are any splash screens)?

Are you able to see the application being opened by WinAppDriver? If so, you can confirm the processID.

Hi @hassanuz
Thanks for getting back to me.
it's WPF app. Yes, there is a splash screen.

Yes, I can see the application is actually launched (auto-logged in and lands on the home page). But by this time the driver throws an exception.
The App PID is 9544, whereas the log says
[MJSONWP] Encountered internal error running command: {"w3cStatus":400,"jsonwp":{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: Z:\xx\xx\xx\xx\xx.exe, and processId: 5968"}}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: Z:\xx\xx\xx\xx\xx.exe, and processId: 5968"}}

So process ID's are indeed different?

Where is the processId:5968 coming from?

@ellnika you are hitting WAD Splash screen issue.....WAD has difficulty handing apps with splash screen. Some apps can suppress splash screen using extra flags. For example you can suppress windows word splash screen using flags "/q /w". If your app can suppress splashscreen then its the currently known best workaround....till Microsoft gives some permanent fix for this.....

@shankarkc thanks for your response. Yes, i am also hitting splash screen issue which I logged separately in https://github.com/Microsoft/WinAppDriver/issues/368. I made my own workaround which works fixing both issues here is the code:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platormName", "Windows");
capabilities.setCapability("deviceName", "WindowsPC");
capabilities.setCapability("app", "Z:\xx\xx\xx\xx.exe");
capabilities.setCapability("appArguments", xx);

try {
    driver = new WindowsDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    Assert.assertNotNull(driver);
} catch (Exception e) {}

//1. Creating a Desktop session
DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
desktopCapabilities.setCapability("platormName", "Windows");
desktopCapabilities.setCapability("app", "Root");
desktopCapabilities.setCapability("deviceName", "WindowsPC");
AppiumDriver DesktopSession = new WindowsDriver(new URL("http://127.0.0.1:4723/wd/hub"), desktopCapabilities);

//Thread.sleep(3000);
WebElement XXXWindow = DesktopSession.findElementByName("XXX XXX");

//2. Attaching to existing XXX XXX Window
String XXXTopLevelWindowHandle = XXXWindow.getAttribute("NativeWindowHandle");
XXXTopLevelWindowHandle = Integer.toHexString(Integer.parseInt(XXXTopLevelWindowHandle));

DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.setCapability("deviceName", "WindowsPC");
appCapabilities.setCapability("appTopLevelWindow", XXXTopLevelWindowHandle);
driver = new WindowsDriver(new URL("http://127.0.0.1:4723/wd/hub"), appCapabilities);

Adding Thread.sleep() mitigates the splash screen issue.

Thanks @ellnika In my scenario I am running test on remote machine. I have a different issue. It works locally fine as in your case. It fails when i run it on remote machine. I have logged a bug. Awaiting some updates from Microsoft
https://github.com/Microsoft/WinAppDriver/issues/361

Hi @ellnika,

Can you try setting the desktop as the default session, and use that to locate your main application Window once it is launched the same way you've been currently launching it.

This may also help you start a new session with any given top level window located from the desktop session.

I am testing a WPF application which displays a splash screen while performing necessary application startup logic. After the splash screen closes then the Login Window is displayed. When running my tests on a different (and slower) work PC, I am starting to run into this same "Failed to locate opened application window with appId" issue. We cannot bypass the splash screen because we unfortunately have a heavy startup time and that time frame can vary depending on the PC's performance where the application is running.

I feel like there is too short of a timeout perhaps when WAD sends the HTTP response back to the appium webdriver?? Or is this a selenium issue? Is there anyway to provide this timeout value when setting up the session? I'm sure that would require changes on Appium APIs and WAD.

I've tried adding a thread sleep but that doesn't help because the sleep happens after the webdriver instance is created and the app is started.

==========================================
POST /session HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: close
Content-Length: 290
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: Python http auth

{"capabilities": {"alwaysMatch": {"platformName": "Windows"}, "firstMatch": [{}]}, "desiredCapabilities": {"deviceName": "WindowsPC", "app": "C:\XXXXXXXX\Source\Repos\Frontend\5x\bin\XXXXXXXX.exe", "platformName": "Windows", "appArguments": "Trader noupgrade automation"}}
HTTP/1.1 500 Internal Error
Content-Length: 208
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\XXXXXXXX\Source\Repos\Frontend\5x\bin\XXXXXXXX.exe, and processId: 38296"}}

==========================================

Traceback (most recent call last):
File "C:\Python27\lib\unittest\case.py", line 320, in run
self.setUp()
File "C:\XXXXXXXX\Source\Repos\Sandbox\bburkhart\Coastline\Python\tests\LoginWindow.py", line 8, in setUp
self.trader = Trader()
File "C:\XXXXXXXX\Source\Repos\Sandbox\bburkhart\Coastline\Python\coastline\ln5.py", line 79, in __init__
desired_capabilities=desired_caps)
File "C:\Python27\lib\site-packages\appium\webdriver\webdriver.py", line 36, in __init__
super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: Failed to locate opened application window with appId: C:\XXXXXXXX\Source\Repos\Frontend\5x\bin\XXXXXXXX.exe, and processId: 38296

The program '[40876] python.exe @ tcp://localhost:58068/' has exited with code -1 (0xffffffff).

Ok, so after reading https://github.com/Microsoft/WinAppDriver/issues/368 and the comment by @timotiusmargo

What essentially happened in the scenario you described was Windows Application Driver successfully launched the application and captured the first UI window as the main application window. Unfortunately, the splash screen was identified as the first UI windows as it appeared before the home screen as you described.

...I updated our GUI to essentially not create the splash Window, continue to do the startup logic, and then show the Login Window. This seems to have bypassed the above issue.

Thanks for the update @brett-burkhart,

Splash screen, dialog, and slow loading UI on the application startup are common scenarios for many of the Classic Windows Applications. We have made a few features such as Creating Desktop Session and Attaching to Existing Window to help enabling these scenarios.

We are continuing to look for ways to make these scenarios more seamless. But for now, please have a look on how you can handle the Splash Screen wihtout altering your application UI code or launching sequence below:
https://github.com/Microsoft/WinAppDriver/issues/213#issuecomment-322960439

Closing ticket as original issue is resolved.

Thanks for the update @brett-burkhart,

Splash screen, dialog, and slow loading UI on the application startup are common scenarios for many of the Classic Windows Applications. We have made a few features such as Creating Desktop Session and Attaching to Existing Window to help enabling these scenarios.

We are continuing to look for ways to make these scenarios more seamless. But for now, please have a look on how you can handle the Splash Screen wihtout altering your application UI code or launching sequence below:
#213 (comment)

Could you please explain this solution a little better? I'm not understanding how starting the desktop session fixes the issue with being unable to locate the app window. You would still have to launch the app in question, right? How would you then use the desktop session to locate the launched application?

By attach existing window, does that mean that the application has to already be running for this work-around to work?

Thanks for the update @brett-burkhart,

Splash screen, dialog, and slow loading UI on the application startup are common scenarios for many of the Classic Windows Applications. We have made a few features such as Creating Desktop Session and Attaching to Existing Window to help enabling these scenarios.

We are continuing to look for ways to make these scenarios more seamless. But for now, please have a look on how you can handle the Splash Screen wihtout altering your application UI code or launching sequence below:
#213 (comment)

@timotiusmargo This is not working in WinAppDriver v1.0.1-Preview. The tests are failing when you are instantiating new WindowsDriver. To be more specific, on this line:

Session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);

Your suggestions do not have any impact on the whole execution. The only impact have completely disable splash screen (in our case it is a blocker as we might do DB upgrade at that time) or pre-launch the app somehow so it is running before instantiating WindowsDriver.

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 How did that work, I thought that SetCapability was depreciated.

@shankarkc Are you still facing the issue or if it is resolved then let me know the resolution I am also facing the same issue on the Remote machine using Pipeline?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Blank517 picture Blank517  Â·  4Comments

sky205 picture sky205  Â·  3Comments

SimonKirkhamCL4U picture SimonKirkhamCL4U  Â·  3Comments

hassanuz picture hassanuz  Â·  4Comments

AmitVerma4HP picture AmitVerma4HP  Â·  3Comments