Issue with Context Switching in Appium

I’ve encountered an issue while trying to switch contexts in my Appium automation script. The scenario involves switching to the ‘WEBVIEW_com.kakao.talk.sandbox’ context, but I’m encountering errors related to port forwarding.

Summary of the Problem:

  1. Context Switch Attempt: The script attempts to switch to the ‘WEBVIEW_com.kakao.talk.sandbox’ context.
  2. Webview Identification: Two webview contexts are identified: “WEBVIEW_com.kakao.talk.sandbox” and “WEBVIEW_stetho_com.kakao.talk.sandbox”.
  3. Port Forwarding: The AndroidDriver initiates port forwarding for the identified webview contexts.
  4. Chromedriver Connection: Chromedriver initialization proceeds with the provided capabilities.
  5. Chromedriver Version: Chromedriver version ‘123.0.6312.105’ is utilized.
  6. Chromedriver Session Creation: A new Chromedriver session is started based on the provided capabilities.
  7. Error Occurrence: The error arises during the port forwarding process for the ‘WEBVIEW_com.kakao.talk.sandbox’ context, leading to a 404 status code.

Any insights or suggestions on resolving this issue would be greatly appreciated. Thank you in advance for your help!

Appium Server log
[W3C (2d06681e)] Responding to client with driver.getCurrentContext() result: “NATIVE_APP”
[HTTP] ← GET /wd/hub/session/2d06681e-a78b-4015-b2dd-77da189eaf39/context 200 1 ms - 22
[HTTP]
[HTTP] → POST /wd/hub/session/2d06681e-a78b-4015-b2dd-77da189eaf39/context
[HTTP] {“name”:“WEBVIEW_com.kakao.talk.sandbox”}
[W3C (2d06681e)] Calling AppiumDriver.setContext() with args: [“WEBVIEW_com.kakao.talk.sandbox”,“2d06681e-a78b-4015-b2dd-77da189eaf39”]
[AndroidDriver] Getting a list of available webviews
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} shell cat /proc/net/unix’
[AndroidDriver] Parsed 2 active devtools sockets: [“@webview_devtools_remote_19065”,“@stetho_com.kakao.talk.sandbox_devtools_remote”]
[AndroidDriver] Collecting CDP data of 2 webviews
[AndroidDriver] Forwarding remote port webview_devtools_remote_19065 to a local port in range 10900…11000
[AndroidDriver] You could use the ‘webviewDevtoolsPort’ capability to customize the starting port number
[AndroidDriver] Forwarding remote port stetho_com.kakao.talk.sandbox_devtools_remote to a local port in range 10900…11000
[AndroidDriver] You could use the ‘webviewDevtoolsPort’ capability to customize the starting port number
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} forward tcp:10900 localabstract:webview_devtools_remote_19065’
[ADB] Removing forwarded port socket connection: 10900
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} forward --remove tcp:10900’
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} forward tcp:10901 localabstract:stetho_com.kakao.talk.sandbox_devtools_remote’
[AndroidDriver] Error: Request failed with status code 404
[AndroidDriver] at createError (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/axios/lib/core/createError.js:16:15)
[AndroidDriver] at settle (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/axios/lib/core/settle.js:17:12)
[AndroidDriver] at IncomingMessage.handleStreamEnd (/Applications/Appium Server GUI.app/Contents/Resources/app/node_modules/appium/node_modules/axios/lib/adapters/http.js:260:11)
[AndroidDriver] at IncomingMessage.emit (events.js:322:22)
[AndroidDriver] at endReadableNT (_stream_readable.js:1187:12)
[AndroidDriver] at processTicksAndRejections (internal/process/task_queues.js:84:21)
[ADB] Removing forwarded port socket connection: 10901
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} forward --remove tcp:10901’
[AndroidDriver] CDP data collection completed
[AndroidDriver] WEBVIEW_19065 mapped to pid 19065
[AndroidDriver] Getting process name for webview ‘WEBVIEW_19065’
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} shell ps -A’
[AndroidDriver] Got process name: ‘com.kakao.talk.sandbox’
[AndroidDriver] Found 2 webviews: [“WEBVIEW_com.kakao.talk.sandbox”,“WEBVIEW_stetho_com.kakao.talk.sandbox”]
[AndroidDriver] Available contexts: [“NATIVE_APP”,“WEBVIEW_com.kakao.talk.sandbox”,“WEBVIEW_stetho_com.kakao.talk.sandbox”]
[AndroidDriver] Connecting to chrome-backed webview context ‘WEBVIEW_com.kakao.talk.sandbox’
[AndroidDriver] A port was not given, using random free port: 8000
[AndroidDriver] Passing web view details to the Chromedriver constructor: {
[AndroidDriver] “info”: {
[AndroidDriver] “Android-Package”: “com.kakao.talk.sandbox”,
[AndroidDriver] “Browser”: “Chrome/123.0.6312.99”,
[AndroidDriver] “Protocol-Version”: “1.3”,
[AndroidDriver] “User-Agent”: “Mozilla/5.0 (Linux; Android 13; SM-A325N Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/123.0.6312.99 Mobile Safari/537.36”,
[AndroidDriver] “V8-Version”: “12.3.219.15”,
[AndroidDriver] “WebKit-Version”: “537.36 (@03fbddf498224f2bcca36d06c44df0d5f625067e)”,
[AndroidDriver] “webSocketDebuggerUrl”: “ws://127.0.0.1:10900/devtools/browser”
[AndroidDriver] },
[AndroidDriver] “process”: {
[AndroidDriver] “name”: “com.kakao.talk.sandbox”,
[AndroidDriver] “id”: “19065”
[AndroidDriver] }
[AndroidDriver] }
[AndroidDriver] Precalculated Chromedriver capabilities: {
[AndroidDriver] “androidPackage”: “com.kakao.talk.sandbox”,
[AndroidDriver] “androidUseRunningApp”: true,
[AndroidDriver] “androidProcess”: “com.kakao.talk.sandbox”,
[AndroidDriver] “androidDeviceSerial”: “{androidDeviceSerial}”
[AndroidDriver] }
[AndroidDriver] Before starting chromedriver, androidPackage is ‘com.kakao.talk.sandbox’
[Chromedriver] Changed state to ‘starting’
[Chromedriver] Set chromedriver binary as: /Users/kuma/PycharmProjects/qe_appium/qeproject/common/chromedriver/chromedriver123_64
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f “/Users/kuma/PycharmProjects/qe_appium/qeproject/common/chromedriver/chromedriver123_64.*–port=8000”
[Chromedriver] No old chromedrivers seem to exist
[Chromedriver] Cleaning this device’s adb forwarded port socket connections: {androidDeviceSerial}
[ADB] List forwarding ports
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} forward --list’
[ADB] Removing forwarded port socket connection: 62807
[ADB] Running ‘/Users/kuma/Library/Android/sdk/platform-tools/adb -P 5037 -s {androidDeviceSerial} forward --remove tcp:62807’
[Chromedriver] Spawning chromedriver with: /Users/kuma/PycharmProjects/qe_appium/qeproject/common/chromedriver/chromedriver123_64 --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
[Chromedriver] Chromedriver version: ‘123.0.6312.105’
[Chromedriver] Chromedriver v. 123.0.6312.105 supports W3C protocol, but MJSONWP one has been explicitly requested
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8000
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[WD Proxy] Got response with status 200: {“value”:{“build”:{“version”:“123.0.6312.105 (399174dbe6eff0f59de9a6096129c0c827002b3a-refs/branch-heads/6312@{#761})”},“message”:“ChromeDriver ready for new sessions.”,“os”:{“arch”:“arm64”,“name”:“Mac OS X”,“version”:“13.4.0”},“ready”:true}}
[Chromedriver] Starting MJSONWP Chromedriver session with capabilities: {
[Chromedriver] “desiredCapabilities”: {
[Chromedriver] “chromeOptions”: {
[Chromedriver] “androidPackage”: “com.kakao.talk.sandbox”,
[Chromedriver] “androidUseRunningApp”: true,
[Chromedriver] “androidProcess”: “com.kakao.talk.sandbox”,
[Chromedriver] “androidDeviceSerial”: “{androidDeviceSerial}”,
[Chromedriver] “w3c”: false
[Chromedriver] },
[Chromedriver] “loggingPrefs”: {
[Chromedriver] “browser”: “ALL”
[Chromedriver] }
[Chromedriver] }
[Chromedriver] }
[WD Proxy] Matched ‘/session’ to command name ‘createSession’
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {“desiredCapabilities”:{“chromeOptions”:{“androidPackage”:“com.kakao.talk.sandbox”,“androidUseRunningApp”:true,“androidProcess”:“com.kakao.talk.sandbox”,“androidDeviceSerial”:“androidDeviceSerial”,“w3c”:false},“loggingPrefs”:{“browser”:“ALL”}}}
[Chromedriver] Webview version: ‘Chrome/123.0.6312.99’

I found the cause. It seems that the Webview version is not working because it is the latest version. I lowered the Webview version and it worked normally.

I had to set chrome to be the default browser on the device, what device is it that has that browser by default? I am curious to know which browser it is and why.