每当我试图通过chromedriver创建会话时,它都失败了,我所做的是...
- 运行chromedriver.exe在本地
- adb连接到设备(我检查了与
adb devices
的连接。) - 打开应用程序并导航到webview页面
- 请求POST方法创建chromedriver会话,如下所示
请求
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
答复
{
"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"
}
}
错误原因?
我检查了chromedriver和远程浏览器(在webview)版本是兼容的。
但是,奇怪的是chromedriver发送killforward
命令到adb。在该命令之后,chromedriver收到“adb初始化会话请求失败”。
在正常的日志中,chromedriver不发送killforward命令。为什么这个chromedriver这样做?🥲
[1646997877.126][DEBUG]: Sending adb command: host-serial:<MY_DEVICE_SERIAL>:killforward:tcp:64017
Chrome驱动程序日志
{
"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
请帮帮我...自动化大师...
2条答案
按热度按时间qfe3c7zg1#
我在chromedriver code中找到了原因。如果devtools客户端的browser_info的android软件包名称与capabilities选项的android软件包名称不匹配,那么它会抛出会话未创建错误。但是,我不知道为什么devtools会将android软件包解析为空字符串。
oknrviil2#
根据@roseline的调查,我发现了Android驱动程序的一个功能: