question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Windows Application Testing: WinAppDriver::CommandHandler::Session::HandleCommandAsMidPoint - Command contexts is not recognized

See original GitHub issue

Hi,

I am successfully opened a Sample Windows App using Appium+Selenium Webdriver. But the Webview / Html Elements are not recognising by the Appium. I am getting an Exception. Please find the details below. Appium 1.6.3 Selenium WebDriver Java Java Client: 5.0.0-BETA3 App : MS Visual Studio, C#

I am using the following code to Switch the Webview context with NATIVE-APP. But the ContextHandler is giving the following error. Please help to Switch to the Webview context from Native-App. Any help is most appreciated.

Issue:

I am getting an Exception like this. WinAppDriver::CommandHandler::Session::HandleCommandAsMidPoint - Command contexts is not recognized. Adding Appium Log Result below.

Microsoft Windows [Version 10.0.14393] © 2016 Microsoft Corporation. All rights reserved.

C:\Users\dgeorge>appium [Appium] Welcome to Appium v1.6.3 [Appium] Appium REST http interface listener started on 0.0.0.0:4723 [HTTP] --> POST /wd/hub/session {“capabilities”:{“desiredCapabilities”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”,“deviceName”:“WindowsPC”,“newCommandTimeout”:“100”},“requiredCapabilities”:{}},“desiredCapabilities”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”,“deviceName”:“WindowsPC”,“newCommandTimeout”:“100”},“requiredCapabilities”:{}} [debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”,“deviceName”:“WindowsPC”,“newCommandTimeout”:“100”},{},{“desiredCapabilities”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”,“deviceName”:“WindowsPC”,“newCommandTimeout”:“100”},“requiredCapabilities”:{}},null,null] [Appium] Creating new WindowsDriver session [Appium] Capabilities: [Appium] app: ‘bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App’ [Appium] platformName: ‘Windows’ [Appium] deviceName: ‘WindowsPC’ [Appium] newCommandTimeout: ‘100’ [BaseDriver] Capability ‘newCommandTimeout’ changed from string (‘100’) to integer (100). This may cause unexpected behavior [BaseDriver] The following capabilities were provided, but are not recognized by appium: app. [BaseDriver] Session created with session id: e0a7b137-9b07-40c0-aedc-18f2a6823a21 [WinAppDriver] Verifying WinAppDriver is installed with correct checksum [debug] [WinAppDriver] WinAppDriver changed state to ‘starting’ [WinAppDriver] Killing any old WinAppDrivers, running: FOR /F “usebackq tokens=5” %a in (netstat -nao ^| findstr /R /C:"4823 ") 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: undefined 4823/wd/hub [WinAppDriver] [STDOUT] Windows Application Driver Beta listening for requests at: http://127.0.0.1:4823/wd/hub [debug] [WinAppDriver] WinAppDriver changed state to ‘online’ [debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4823/wd/hub/session] with body: {“desiredCapabilities”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”,“deviceName”:“WindowsPC”,“newCommandTimeout”:100}} [WinAppDriver] [STDOUT] Press ENTER to exit. [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: 162 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4823 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“desiredCapabilities”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”,“deviceName”:“WindowsPC”,“newCommandTimeout”:100}} [WinAppDriver] [STDOUT] SessionManager - Creating session [WinAppDriver] [STDOUT] SessionManager - WinAppDriver succeeded loading MitaBroker [WinAppDriver] [STDOUT] SessionManager - Application launched [WinAppDriver] [STDOUT] SessionManager - Session successfully created: 6AE322D1-E789-4708-B97C-A5FA665CC8C2 [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 161 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0,“value”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”}} [debug] [JSONWP Proxy] Got response with status 200: {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0,“value”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”}} [Appium] New WindowsDriver session created successfully, session e0a7b137-9b07-40c0-aedc-18f2a6823a21 added to master session list [debug] [MJSONWP] Responding to client with driver.createSession() result: {“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”,“deviceName”:“WindowsPC”,“newCommandTimeout”:“100”} [HTTP] <-- POST /wd/hub/session 200 2844 ms - 212 [HTTP] --> GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21 {} [MJSONWP] Driver proxy active, passing request on via HTTP proxy [debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21] to [GET http://127.0.0.1:4823/wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2] with body: {} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] GET /wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2 HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4823 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 161 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0,“value”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”}} [debug] [JSONWP Proxy] Got response with status 200: “{"sessionId":"6AE322D1-E789-4708-B97C-A5FA665CC8C2","status":0,"value":{"app":"bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App","platformName":"Windows"}}” [JSONWP Proxy] Replacing sessionId 6AE322D1-E789-4708-B97C-A5FA665CC8C2 with e0a7b137-9b07-40c0-aedc-18f2a6823a21 [HTTP] <-- GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21 200 30 ms - 161 [HTTP] --> GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21 {} [MJSONWP] Driver proxy active, passing request on via HTTP proxy [debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21] to [GET http://127.0.0.1:4823/wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2] with body: {} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] GET /wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2 HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4823 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 161 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0,“value”:{“app”:“bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”,“platformName”:“Windows”}} [debug] [JSONWP Proxy] Got response with status 200: “{"sessionId":"6AE322D1-E789-4708-B97C-A5FA665CC8C2","status":0,"value":{"app":"bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App","platformName":"Windows"}}” [JSONWP Proxy] Replacing sessionId 6AE322D1-E789-4708-B97C-A5FA665CC8C2 with e0a7b137-9b07-40c0-aedc-18f2a6823a21 [HTTP] <-- GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21 200 14 ms - 161 [HTTP] --> POST /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21/timeouts {“type”:“implicit”,“ms”:250000} [MJSONWP] Driver proxy active, passing request on via HTTP proxy [debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21/timeouts] to [POST http://127.0.0.1:4823/wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2/timeouts] with body: {“type”:“implicit”,“ms”:250000} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] POST /wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2/timeouts HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Length: 31 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4823 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“type”:“implicit”,“ms”:250000} [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 63 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0} [debug] [JSONWP Proxy] Got response with status 200: {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0} [JSONWP Proxy] Replacing sessionId 6AE322D1-E789-4708-B97C-A5FA665CC8C2 with e0a7b137-9b07-40c0-aedc-18f2a6823a21 [HTTP] <-- POST /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21/timeouts 200 12 ms - 63 [HTTP] --> GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21/contexts {} [MJSONWP] Driver proxy active, passing request on via HTTP proxy [debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21/contexts] to [GET http://127.0.0.1:4823/wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2/contexts] with body: {} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] GET /wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2/contexts HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4823 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ### WinAppDriver::CommandHandler::Session::HandleCommandAsMidPoint - Command contexts is not recognized [WinAppDriver] [STDOUT] HTTP/1.1 404 Not Found [WinAppDriver] [STDOUT] Content-Length: 144 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“status”:9,“value”:{“error”:“unknown command”,“message”:“Command not recognized: GET: /session/6AE322D1-E789-4708-B97C-A5FA665CC8C2/contexts”}} [MJSONWP] Encountered internal error running command: {“jsonwp”:{“status”:9,“value”:{“error”:“unknown command”,“message”:“Command not recognized: GET: /session/6AE322D1-E789-4708-B97C-A5FA665CC8C2/contexts”}}} ProxyRequestError: Could not proxy command to remote server. Original error: 404 - “{"status":9,"value":{"error":"unknown command","message":"Command not recognized: GET: /session/6AE322D1-E789-4708-B97C-A5FA665CC8C2/contexts"}}” at JWProxy.proxy$ (…/…/…/lib/jsonwp-proxy/proxy.js:126:13) at tryCatch (C:\Users\dgeorge\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40) at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\dgeorge\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22) at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\dgeorge\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js💯21) at GeneratorFunctionPrototype.invoke (C:\Users\dgeorge\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37) [HTTP] <-- GET /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21/contexts 500 48 ms - 207 [HTTP] --> DELETE /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21 {} [debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: [“e0a7b137-9b07-40c0-aedc-18f2a6823a21”] [debug] [WinAppDriver] Deleting WinAppDriver session [debug] [WinAppDriver] Deleting WinAppDriver server session [debug] [JSONWP Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:4823/wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2] with no body [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] DELETE /wd/hub/session/6AE322D1-E789-4708-B97C-A5FA665CC8C2 HTTP/1.1 [WinAppDriver] [STDOUT] Accept: / [WinAppDriver] [STDOUT] Connection: keep-alive [WinAppDriver] [STDOUT] Content-Length: 0 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] Host: 127.0.0.1:4823 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 63 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0} [debug] [JSONWP Proxy] Got response with status 200: “{"sessionId":"6AE322D1-E789-4708-B97C-A5FA665CC8C2","status":0}” [WinAppDriver] Did not get confirmation WinAppDriver deleteSession worked; Error was: Error: Did not get a valid response object. Object was: {“sessionId”:“6AE322D1-E789-4708-B97C-A5FA665CC8C2”,“status”:0} [debug] [WinAppDriver] WinAppDriver changed state to ‘stopping’ [debug] [WinAppDriver] WinAppDriver changed state to ‘stopped’ [Appium] Removing session e0a7b137-9b07-40c0-aedc-18f2a6823a21 from our master session list [debug] [MJSONWP] Received response: null [debug] [MJSONWP] But deleting session, so not returning [debug] [MJSONWP] Responding to client with driver.deleteSession() result: null [HTTP] <-- DELETE /wd/hub/session/e0a7b137-9b07-40c0-aedc-18f2a6823a21 200 109 ms - 76

Code Used: Capabilities:

DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(“app”, “bccb6174-9004-40e4-b26e-7f1859c4b4e1_r6mxmex0vgwxj!App”); capabilities.setCapability(“newCommandTimeout”, “100”); capabilities.setCapability(“platformName”, “Windows”); capabilities.setCapability(“deviceName”, “WindowsPC”); driver = new WindowsDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities); driver.manage().timeouts().implicitlyWait(250, TimeUnit.SECONDS);

public static void switchToWebViewContext(WindowsDriver driver) {

	Set<String> contextNames = driver.getContextHandles();

	  for (String contextName : contextNames) {
	   System.out.println("Context " + contextName);
	   if (!contextName.equals("NATIVE_APP")) {
	    System.out.println("Switch to " + contextName + " Context");
	    driver.context(contextName);
	    break;
	   }
	  }

Used UI Inspect Tools:

Inspect.exe Chrome Inspect

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rossknudsencommented, Jul 9, 2020

Hi, we ran across this issue recently in running tests in a hybrid app situation. The application is a UWP desktop application with webview components. We’re wanting to drop down into the web layer and interact with components but when we call Driver.Context or Driver.Contexts we get a InvalidOperationException thrown.

The user voice page does not exist anymore and so was wondering what the status of this backlog item is?

0reactions
andreas-schochcommented, May 3, 2021

Looking at the source code of appium-dotnet-driver, it seems that switching contexts still isn’t expected to work:
https://github.com/appium/appium-dotnet-driver/blob/master/src/Appium.Net/Appium/Windows/WindowsDriver.cs#L119

Is there any update to this item in your backlog?

Read more comments on GitHub >

github_iconTop Results From Across the Web

iOS support for appium on windows
3 Answers. It is possible to run the tests from a windows machine but not the way you are probably thinking. You will...
Read more >
How To Automate Desktops Apps Using WinAppDriver
It goes without saying that manual testing of desktop applications is not a scalable and reliable approach to verifying their features ...
Read more >
9 Desktop Test Automation Tools That Won't Cost a Penny
WinAppDriver (short for Windows Application Driver) is a free test automation tool for Windows desktop apps developed by Microsoft.
Read more >
Interacting With Non-Compatible Application Objects
TestComplete may fail to recognize your custom windowed control if it cannot match the control with any of the supported object classes. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found