desiredCapabilities相关配置信息:
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "test");
desiredCapabilities.setCapability(MobileCapabilityType.UDID, deviceId);
desiredCapabilities.setCapability(MobileCapabilityType.APP, app);
desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, appPackage);
desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, getActivity(deviceId, appPackage));
desiredCapabilities.setCapability(AndroidMobileCapabilityType.NO_SIGN, true);
desiredCapabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
// Appium在没有收到下一个命令时,默认超时时间是60s,超时后应用将会自动关闭
desiredCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 3600);
desiredCapabilities.setCapability(AndroidMobileCapabilityType.RECREATE_CHROME_DRIVER_SESSIONS, true);
desiredCapabilities.setCapability(AndroidMobileCapabilityType.DONT_STOP_APP_ON_RESET, true);
desiredCapabilities.setCapability(MobileCapabilityType.NO_RESET, true);
desiredCapabilities.setCapability("chromedriverExecutableDir", CHROMEDRIVER_EXECUTABLE_DIT_PATH);
desiredCapabilities.setCapability("showChromedriverLog", true);
desiredCapabilities.setCapability("relaxedSecurityEnabled", true);
本地已开启chromedriver:
➜ ~ ps -ef | grep chromedriver
501 13324 13170 0 9:19上午 ttys001 0:00.04 /Users/apple/Data/appium/Touchtv/chromeDriver/chromedriver_2.29 --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
端口也重定向了:
➜ ~ adb forward --list
605dcd5b tcp:8200 tcp:6790
605dcd5b tcp:8201 tcp:6790
605dcd5b tcp:8202 tcp:6790
605dcd5b tcp:12541 localabstract:webview_devtools_remote_12178
➜ ~ adb -P 5037 -s 605dcd5b shell cat /proc/net/unix | grep webview
00000000: 00000002 00000000 00010000 0001 01 107458 @webview_devtools_remote_m5x_12178
➜ ~ adb -P 5037 -s 605dcd5b shell ps 12178
USER PID PPID VSIZE RSS WCHAN PC NAME
u0_a126 12178 315 1636520 289692 sys_epoll_ 00000000 S com.cgbchina.xpt
chrome://inspect/#devices已经加装出了webview的画面和数据:
错误日志
[debug] [ADB] Getting package info for 'com.google.android.webview'
[debug] [ADB] Running '/Users/apple/Library/Android/sdk/platform-tools/adb -P 5037 -s 605dcd5b shell dumpsys package com.google.android.webview'
[debug] [Chromedriver] Found Chrome bundle 'com.google.android.webview' version '57.0.2987'
[debug] [Chromedriver] Found 1 Chromedriver executable capable of automating Chrome '57.0.2987'.
[debug] [Chromedriver] Choosing the most recent, '/Users/apple/Data/appium/Touchtv/chromeDriver/chromedriver_2.29'.
[debug] [Chromedriver] If a specific version is required, specify it with the `chromedriverExecutable`desired capability.
[Chromedriver] Set chromedriver binary as: /Users/apple/Data/appium/Touchtv/chromeDriver/chromedriver_2.29
[debug] [Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/Users/apple/Data/appium/Touchtv/chromeDriver/chromedriver_2.29.*--port=8000"
[Chromedriver] No old chromedrivers seem to exist
[debug] [Chromedriver] Cleaning any old adb forwarded port socket connections
[debug] [ADB] List forwarding ports
[debug] [ADB] Running '/Users/apple/Library/Android/sdk/platform-tools/adb -P 5037 -s 605dcd5b forward --list'
[debug] [ADB] Removing forwarded port socket connection: 12292
[debug] [ADB] Running '/Users/apple/Library/Android/sdk/platform-tools/adb -P 5037 -s 605dcd5b forward --remove tcp\:12292'
[Chromedriver] Spawning chromedriver with: /Users/apple/Data/appium/Touchtv/chromeDriver/chromedriver_2.29 --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
[debug] [Chromedriver] Chromedriver version: '2.29.461585'
[debug] [Chromedriver] Chromedriver v. 2.29.461585 does not fully support W3C protocol. Defaulting to MJSONWP
[debug] [Chromedriver] [STDOUT] Starting ChromeDriver 2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b) on port 8000
[debug] [Chromedriver] [STDOUT] Only local connections are allowed.
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [WD Proxy] Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Mac OS X","version":"10.14.6"}}}
[Chromedriver] Starting MJSONWP Chromedriver session with capabilities: {
[Chromedriver] "desiredCapabilities": {
[Chromedriver] "chromeOptions": {
[Chromedriver] "androidPackage": "com.cgbchina.xpt",
[Chromedriver] "androidUseRunningApp": true,
[Chromedriver] "androidDeviceSerial": "605dcd5b"
[Chromedriver] },
[Chromedriver] "loggingPrefs": {
[Chromedriver] "browser": "ALL"
[Chromedriver] }
[Chromedriver] }
[Chromedriver] }
[debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.cgbchina.xpt","androidUseRunningApp":true,"androidDeviceSerial":"605dcd5b"},"loggingPrefs":{"browser":"ALL"}}}
[Chromedriver] [STDERR] [0.017][INFO]: COMMAND InitSession {
[Chromedriver] [STDERR] "desiredCapabilities": {
[Chromedriver] [STDERR] "chromeOptions": {
[Chromedriver] [STDERR] "androidDeviceSerial": "605dcd5b",
[Chromedriver] [STDERR] "androidPackage": "com.cgbchina.xpt",
[Chromedriver] [STDERR] "androidUseRunningApp": true
[Chromedriver] [STDERR] },
[Chromedriver] [STDERR] "loggingPrefs": {
[Chromedriver] [STDERR] "browser": "ALL"
[Chromedriver] [STDERR] }
[Chromedriver] [STDERR] }
[Chromedriver] [STDERR] }
[Chromedriver] [STDERR] [0.017][DEBUG]: Sending adb command: host:devices
[Chromedriver] [STDERR] [0.018][DEBUG]: Received adb response: 605dcd5b device
[Chromedriver] [STDERR] [0.018][DEBUG]: Sending adb command: host:transport:605dcd5b|shell:pm path com.cgbchina.xpt
[Chromedriver] [STDERR] [1.323][DEBUG]: Received adb response: package:/data/app/com.cgbchina.xpt-1/base.apk
[Chromedriver] [STDERR] [1.323][DEBUG]: Sending adb command: host:transport:605dcd5b|shell:ps
[Chromedriver] [STDERR] [1.445][DEBUG]: Received adb response: USER PID PPID VSIZE RSS WCHAN PC NAME
[Chromedriver] [STDERR] root 1 0 5560 1256 sys_epoll_ 00000000 S /init
[Chromedriver] [STDERR] root 2 0 0 0 kthreadd 00000000 S kthreadd
[Chromedriver] [STDERR] root 3 2 0 0 run_ksofti 00000000 S ksoftirqd/0
[Chromedriver] [STDERR] root 5 2 0 0 worker_thr 00000000 S kworker/0:0H
[Chromedriver] [STDERR] root 6 2 0 0 msm_mpm_wo 00000000 D kworker/u:0
[Chromedriver] [STDERR] root 7 2 0 0 msm_rpm_sm 00000000 D kworker/u:0H
[Chromedriver] [STDERR] root 8 2 0 0 cpu_stoppe 00000000 S migration/0
....太长了,只打印部分
[Chromedriver] [STDERR] [1.470][DEBUG]: Sending adb command: host-serial:605dcd5b:forward:tcp:12541;localabstract:webview_devtools_remote_12178
[Chromedriver] [STDERR] [1.471][DEBUG]: DevTools request: http://localhost:12541/json/version
[Chromedriver] [STDERR] [1.472][DEBUG]: DevTools request failed
[Chromedriver] [STDERR] [1.523][DEBUG]: DevTools request: http://localhost:12541/json/version
[Chromedriver] [STDERR] [1.525][DEBUG]: DevTools request failed
[Chromedriver] [STDERR] [1.576][DEBUG]: DevTools request: http://localhost:12541/json/version
[Chromedriver] [STDERR] [1.578][DEBUG]: DevTools request failed