'chromedriver session not created about webview in hybrid app

Whenever I try to create session through chromedriver, it failed. What I did is...

  • run chromedriver.exe in local
  • adb connect to device (I checked the connection with adb devices.)
  • open app and navigate to webview page
  • request POST method to create chromedriver session like below

request

POST http://localhost:9515/session
Body
{
   "capabilities": {
      "alwaysMatch": {
         "goog:chromeOptions": {
            "androidActivity": "<MY_ACTIVITY_NAME>",
            "androidDeviceSerial": "<MY_DEVICE_SERIAL>",
            "androidPackage": "<MY_APP_NAME>",
            "androidProcess": "<MY_APP_NAME>",
            "androidUseRunningApp": true,
            "w3c": true
         },
         "goog:loggingPrefs": {
            "browser": "ALL"
         }
      }
   }
}
HEADER
Content-Type: application/json

response

{
    "value": {
        "error": "session not created",
        "message": "session not created: please close 'com.android.chrome' and try again",
        "stacktrace": "0   chromedriver_99                     0x000000010a106d49 chromedriver_99 + 5111113\n1   chromedriver_99                     0x000000010a094d13 chromedriver_99 + 4644115\n2   chromedriver_99                     0x0000000109c86bb8 chromedriver_99 + 392120\n3   chromedriver_99                     0x0000000109cac7dd chromedriver_99 + 546781\n4   chromedriver_99                     0x0000000109ca59c9 chromedriver_99 + 518601\n5   chromedriver_99                     0x0000000109cdef4a chromedriver_99 + 753482\n6   chromedriver_99                     0x0000000109cd9103 chromedriver_99 + 729347\n7   chromedriver_99                     0x0000000109caf05d chromedriver_99 + 557149\n8   chromedriver_99                     0x0000000109cb0035 chromedriver_99 + 561205\n9   chromedriver_99                     0x000000010a0c411d chromedriver_99 + 4837661\n10  chromedriver_99                     0x000000010a0ddb4c chromedriver_99 + 4942668\n11  chromedriver_99                     0x000000010a0e3312 chromedriver_99 + 4965138\n12  chromedriver_99                     0x000000010a0de47a chromedriver_99 + 4945018\n13  chromedriver_99                     0x000000010a0b9310 chromedriver_99 + 4793104\n14  chromedriver_99                     0x000000010a0f8ae8 chromedriver_99 + 5053160\n15  chromedriver_99                     0x000000010a0f8c6f chromedriver_99 + 5053551\n16  chromedriver_99                     0x000000010a10df25 chromedriver_99 + 5140261\n17  libsystem_pthread.dylib             0x00007fff2033b8fc _pthread_start + 224\n18  libsystem_pthread.dylib             0x00007fff20337443 thread_start + 15\n"
    }
}

Error Reason?

I checked that chromedriver and remote browser (in webview) version is compatitable.

But, weird thing is chromedriver sends killforward command to adb. after that command, chromedriver received 'the adb init session request failed'.

In normal log, chromedriver doesn't send killforward command. why this chromedriver do this? 🥲

[1646997877.126][DEBUG]: Sending adb command: host-serial:<MY_DEVICE_SERIAL>:killforward:tcp:64017

chromedriver.log

{
   "capabilities": {
      "alwaysMatch": {
         "goog:chromeOptions": {
            "androidActivity": "<MY_ACTIVITY_NAME>",
            "androidDeviceSerial": "<MY_DEVICE_SERIAL>",
            "androidPackage": "<MY_APP_NAME>",
            "androidProcess": "<MY_APP_NAME>",
            "androidUseRunningApp": true,
            "w3c": true
         },
         "goog:loggingPrefs": {
            "browser": "ALL"
         }
      }
   }
}
[1646997876.636][DEBUG]: Sending adb command: host:devices
[1646997876.637][DEBUG]: Received adb response: <MY_DEVICE_SERIAL>  device

[1646997876.637][DEBUG]: Sending adb command: host:transport:<MY_DEVICE_SERIAL>|shell:pm path <MY_APP_NAME>
[1646997876.761][DEBUG]: Received adb response: package:/data/app/<MY_APP_NAME>-bYL5XjEmW2ih1Q6WgnQ6Tw==/base.apk

[1646997876.761][DEBUG]: Sending adb command: host:transport:<MY_DEVICE_SERIAL>|shell:ps && ps -A
[1646997877.063][DEBUG]: Received adb response: USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME                       
shell        30857  9646   33996   2268 sigsuspend 78274e6168 S sh
shell        30859 30857   36772   3052 0          738140ee48 R ps
USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME                       
...            ...  ...      ...    ... ...               ... ... ...
u0_a248      25771  3843 2425944 352008 0                   0 S <MY_APP_NAME>


[1646997877.064][DEBUG]: Sending adb command: host:transport:<MY_DEVICE_SERIAL>|shell:grep -a '@webview_devtools_remote_.*25771' /proc/net/unix
[1646997877.114][DEBUG]: Received adb response: 0000000000000000: 00000002 00000000 00010000 0001 01 13057474 @webview_devtools_remote_25771
0000000000000000: 00000003 00000000 00000000 0001 03 13101870 @webview_devtools_remote_25771
0000000000000000: 00000003 00000000 00000000 0001 03 13072544 @webview_devtools_remote_25771

[1646997877.114][DEBUG]: Sending adb command: host-serial:<MY_DEVICE_SERIAL>:forward:tcp:0;localabstract:webview_devtools_remote_25771
[1646997877.115][DEBUG]: ADB server responded with "OKAYOKAY" instead of "OKAY".
[1646997877.115][DEBUG]: Received adb response: 64017
[1646997877.115][DEBUG]: DevTools HTTP Request: http://localhost:64017/json/version
[1646997877.126][DEBUG]: DevTools HTTP Response: {
   "Android-Package": "com.android.chrome",
   "Browser": "Chrome/99.0.4844.58",
   "Protocol-Version": "1.3",
   "User-Agent": "Mozilla/5.0 (Linux; Android 10; SM-A305N Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/99.0.4844.58 Mobile Safari/537.36",
   "V8-Version": "9.9.115.8",
   "WebKit-Version": "537.36 (@15ccad7c5507e806397e06a31ab918e52bb47b22)",
   "webSocketDebuggerUrl": "ws://localhost:64017/devtools/browser"
}

[1646997877.126][DEBUG]: Sending adb command: host-serial:<MY_DEVICE_SERIAL>:killforward:tcp:64017
[1646997877.126][DEBUG]: ADB server responded with "OKAYOKAY" instead of "OKAY".
[1646997877.126][DEBUG]: Received adb response: 
[1646997877.126][INFO]: [f0ef9b7bde72b0cc8e5a4729ffee085f] RESPONSE InitSession ERROR session not created: please close 'com.android.chrome' and try again
[1646997877.126][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1646997877.126][DEBUG]: Log type 'browser' lost 0 entries on destruction

please help me... automation masters...



Solution 1:[1]

I found the cause in chromedriver code. If the android pakcage name of the devtools client's browser_info doesn't match with android package name of capabilities option, then it throws session not created error. But, I don't know why the devtools parse the android package as empty string.

  const BrowserInfo* browser_info = client->browser_info();
  std::cout("%s", browser_info->android_package.c_str())
  if (browser_info->is_android &&
    browser_info->android_package != capabilities->android_package) {
    return Status(
      kSessionNotCreated,
      base::StringPrintf("please close '%s' and try again",
                          browser_info->android_package.c_str()));
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 roseline