While automating 2 apps using a single session I see 3 contexts available.
NATIVE_APP
WEBVIEW_app1
WEBVIEW_app2:auth (launches as a separate process per colon).
The way my test works is that I start app1 that launches app2 which in turn starts a webview. Switching context takes forever (60 seconds) and the code does not throw any exception, but attempt to use the driver to find element fails.
Relevant logs are below.
[ debug] [AndroidDriver] Found webviews: [“WEBVIEW_app2:auth”,“WEBVIEW_app1”]
[debug] [AndroidDriver] Available contexts: [“NATIVE_APP”,“WEBVIEW_app2:auth”,“WEBVIEW_app1”]
[debug] [AndroidDriver] Connecting to chrome-backed webview context ‘WEBVIEW_app2:auth’
[debug] [Chromedriver] Changed state to ‘starting’
[Chromedriver] Set chromedriver binary as: /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f “/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver.*–port=9515”
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=9515 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 9515
Only local connections are allowed.
[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
[Chromedriver] [STDERR] [warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
[JSONWP Proxy] Got response with status 200: “{“sessionId”:”",“stat…
[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {“desiredCapabilities”:{“ch…
[JSONWP Proxy] Got response with status 200: {“sessionId”:“964316be4ec2c…
[debug] [Chromedriver] Changed state to ‘online’
[MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/4e434b8a-707a-4ca2-bf72-06a46d261c5f/context 200 60790 ms - 76
[HTTP] --> POST /wd/hub/session/4e434b8a-707a-4ca2-bf72-06a46d261c5f/element {“using”:“id”,“value”:“cred_userid_inputtext”}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [POST /wd/hub/session/4e434b8a-707a-4ca2-bf72-06a46d261c5f/element] to [POST http://127.0.0.1:9515/wd/hub/session/964316be4ec2c0d8119c68d3437db474/element] with body: {“using”:“id”,“value”:“cred…
[JSONWP Proxy] Got response with status 200: {“sessionId”:“964316be4ec2c…
[JSONWP Proxy] Replacing sessionId 964316be4ec2c0d8119c68d3437db474 with 4e434b8a-707a-4ca2-bf72-06a46d261c5f
[HTTP] <-- POST /wd/hub/session/4e434b8a-707a-4ca2-bf72-06a46d261c5f/element 200 7 ms - 220
[HTTP] --> DELETE /wd/hub/session/4e434b8a-707a-4ca2-bf72-06a46d261c5f {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: [“4e434b8a-707a-4ca2-bf72-0…
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Stopping chromedriver for context WEBVIEW_app2:auth
[debug] [Chromedriver] Changed state to ‘stopping’
[JSONWP Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/964316be4ec2c0d8119c68d3437db474] with no body
[JSONWP Proxy] Got response with status 200: “{“sessionId”:“964316be4…
[debug] [Chromedriver] Changed state to ‘stopped’
[debug] [ADB] Getting connected devices…
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/me/software/android-sdk/platform-tools/adb with args: [”-P”,5037,”-s”,“6666b2ca”,“shell”,“am”,“force-stop”,“app1”]
[debug] [ADB] Getting connected devices…
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/me/software/android-sdk/platform-tools/adb with args: [”-P”,5037,”-s”,“6666b2ca”,“shell”,“am”,“force-stop”,“io.appium.unlock”]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices…
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/me/software/android-sdk/platform-tools/adb with args: ["-P",5037,"-s",“6666b2ca”,“shell”,“input”,“keyevent”,3]
[debug] [Logcat] Stopping logcat capture
[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“shutdown”}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“shutdown”}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:“OK, shutting down”}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state ‘stopping’
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state ‘stopped’
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices…
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/me/software/android-sdk/platform-tools/adb with args: ["-P",5037,"-s",“6666b2ca”,“shell”,“ps”,“uiautomator”]
[ADB] No uiautomator process found to kill, continuing…
[debug] [UiAutomator] Moving to state ‘stopped’
[Appium] Removing session 4e434b8a-707a-4ca2-bf72-06a46d261c5f from our master session list
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning
[MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/4e434b8a-707a-4ca2-bf72-06a46d261c5f 200 2895 ms - 76