折腾:
【已解决】Mac中初始化搭建appium的Python的运行环境
期间,去运行了appium的server,运行python代码,报错:
发生异常: WebDriverException Message: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device in 20123ms

报错了,找到内部log是:
[info] [35m[Appium][39m Appium REST http interface listener started on 0.0.0.0:4723[debug] [35m[HTTP][39m Request idempotency key: 696ce175-880a-4fa9-90b8-48a204a79f7e [info] [35m[HTTP][39m [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m [info] [35m[HTTP][39m [90m{"capabilities":{"firstMatch":[{"platformName":"Android","appium:deviceName":"DIG-AL00","appium:udid":"DWH9X17226W04404","appium:appPackage":"com.tencent.mm","appium:appActivity":".ui.LauncherUI","appium:noReset":true,"appium:chromeOptions":{"androidProcess":"com.tencent.mm:tools"}}]},"desiredCapabilities":{"platformName":"Android","deviceName":"DIG-AL00","udid":"DWH9X17226W04404","appPackage":"com.tencent.mm","appActivity":".ui.LauncherUI","noReset":true,"chromeOptions":{"androidProcess":"com.tencent.mm:tools"}}}[39m [debug] [35m[W3C][39m Calling AppiumDriver.createSession() with args: [{"platformName":"Android","deviceName":"DIG-AL00","udid":"DWH9X17226W04404","appPackage":"com.tencent.mm","appActivity":".ui.LauncherUI","noReset":true,"chromeOptions":{"androidProcess":"com.tencent.mm:tools"}},null,{"firstMatch":[{"platformName":"Android","appium:deviceName":"DIG-AL00","appium:udid":"DWH9X17226W04404","appium:appPackage":"com.tencent.mm","appium:appActivity":".ui.LauncherUI","appium:noReset":true,"appium:chromeOptions":{"androidProcess":"com.tencent.mm:tools"}}]}] [debug] [35m[BaseDriver][39m Event 'newSessionRequested' logged at 1624585608228 (09:46:48 GMT+0800 (中国标准时间)) [warn] [35m[Appium][39m [warn] [35m[Appium][39m ====================================================================== [warn] [35m[Appium][39m DEPRECATION WARNING: [warn] [35m[Appium][39m [warn] [35m[Appium][39m The 'automationName' capability was not provided in the desired [warn] [35m[Appium][39m capabilities for this Android session [warn] [35m[Appium][39m [warn] [35m[Appium][39m Setting 'automationName=UiAutomator2' by default and using the [warn] [35m[Appium][39m UiAutomator2 Driver [warn] [35m[Appium][39m [warn] [35m[Appium][39m The next major version of Appium (2.x) will **require** the [warn] [35m[Appium][39m 'automationName' capability to be set for all sessions on all [warn] [35m[Appium][39m platforms [warn] [35m[Appium][39m [warn] [35m[Appium][39m In previous versions (Appium <= 1.13.x), the default was [warn] [35m[Appium][39m 'automationName=UiAutomator1' [warn] [35m[Appium][39m [warn] [35m[Appium][39m If you wish to use that automation instead of UiAutomator2, please [warn] [35m[Appium][39m add 'automationName=UiAutomator1' to your desired capabilities [warn] [35m[Appium][39m [warn] [35m[Appium][39m For more information about drivers, please visit [warn] [35m[Appium][39m http://appium.io/docs/en/about-appium/intro/ and explore the [warn] [35m[Appium][39m 'Drivers' menu [warn] [35m[Appium][39m [warn] [35m[Appium][39m ====================================================================== [warn] [35m[Appium][39m [info] [35m[Appium][39m Appium v1.21.0 creating new AndroidUiautomator2Driver (v1.65.0) session [info] [35m[Appium][39m Applying relaxed security to 'AndroidUiautomator2Driver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure [debug] [35m[BaseDriver][39m W3C capabilities and MJSONWP desired capabilities were provided [debug] [35m[BaseDriver][39m Creating session with W3C capabilities: { [debug] [35m[BaseDriver][39m "alwaysMatch": { [debug] [35m[BaseDriver][39m "platformName": "Android", [debug] [35m[BaseDriver][39m "appium:deviceName": "DIG-AL00", [debug] [35m[BaseDriver][39m "appium:udid": "DWH9X17226W04404", [debug] [35m[BaseDriver][39m "appium:appPackage": "com.tencent.mm", [debug] [35m[BaseDriver][39m "appium:appActivity": ".ui.LauncherUI", [debug] [35m[BaseDriver][39m "appium:noReset": true, [debug] [35m[BaseDriver][39m "appium:chromeOptions": { [debug] [35m[BaseDriver][39m "androidProcess": "com.tencent.mm:tools" [debug] [35m[BaseDriver][39m } [debug] [35m[BaseDriver][39m }, [debug] [35m[BaseDriver][39m "firstMatch": [ [debug] [35m[BaseDriver][39m {} [debug] [35m[BaseDriver][39m ] [debug] [35m[BaseDriver][39m } [info] [35m[BaseDriver][39m Session created with session id: e27ab69b-db94-43f6-b749-02e2ec3f000c [info] [35m[UiAutomator2][39m Starting 'com.tencent.mm' directly on the device[info] [35m[ADB][39m Found 3 'build-tools' folders under '/Users/xxx/Library/Android/sdk' (newest first): [info] [35m[ADB][39m /Users/xxx/Library/Android/sdk/build-tools/29.0.2 [info] [35m[ADB][39m /Users/xxx/Library/Android/sdk/build-tools/28.0.3 [info] [35m[ADB][39m /Users/xxx/Library/Android/sdk/build-tools/24.0.0 [info] [35m[ADB][39m Using 'adb' from '/Users/xxx/Library/Android/sdk/platform-tools/adb' [debug] [35m[ADB][39m Running '/Users/xxx/Library/Android/sdk/platform-tools/adb -P 5037 start-server' [info] [35m[AndroidDriver][39m Retrieving device list [debug] [35m[ADB][39m Trying to find a connected android device [debug] [35m[ADB][39m Getting connected devices [debug] [35m[ADB][39m No connected devices have been detected [debug] [35m[ADB][39m Could not find online devices [debug] [35m[ADB][39m Reconnecting adb (target offline)
即:
此处连不上设备。
所以去:更新设备的信息
以及插上安卓手机到Mac中
先确保adb能找到设备:
~ adb devices List of devices attached orga4pmzee4ts47t device
再确保,参数正确:
【已解决】Mac中如何找到Android手机的appium的参数deviceName
【总结】
此处appium启动报错
Original error: Could not find a connected Android device
意思是,连不上,找不到设备。
解决办法:
- 硬件上
- 确保安卓设备正常通过USB数据线连接到了Mac中
- adb devices
- 可以查看到设备(的udid值)
- 软件上
- 参数配置,最核心的是三个
- platformName:Android
- 安卓平台
- udid:安卓设备的序列号,设备唯一编号
- 可以通过 adb devices 找到
- 比如:
- # adb devices
- List of devices attached
- orga4pmzee4ts47t device
- 中的 orga4pmzee4ts47t
- deviceName:随便填个值(当然最好是见名知意用户看得懂的值)
- 比如
- “deviceName”: “crifan Redmi10X”,
此处完整的Capability的设置:
from appium import webdriver server = 'http://localhost:4723/wd/hub’ Android_Redmi10X_DeviceName = "crifan Redmi10X" Android_Redmi10X_UDID = “orga4pmzee4ts47t" desired_caps = { # 如果换手机,需要改 deviceName、udid "platformName": "Android", "deviceName": Android_Redmi10X_DeviceName, "udid": Android_Redmi10X_UDID, "appPackage": "com.tencent.mm", "appActivity": ".ui.LauncherUI", "noReset": True } desired_caps['chromeOptions'] = {'androidProcess': 'com.tencent.mm:tools'} desired_caps['noReset'] = True driver = webdriver.Remote(server, desired_caps)
具体参数解释,详见官网
或:
转载请注明:在路上 » 【已解决】Appium报错:WebDriverException Original error Could not find a connected Android device