Windows Application Testing: WinAppDriver::CommandHandler::Session::HandleCommandAsMidPoint - Command contexts is not recognized
See original GitHub issueHi,
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:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
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?
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?