首页 文章

如何指示Appium更喜欢模拟设备而不是物理设备

提问于
浏览
0

我正在使用Appium在Android上自动执行我的UI测试 .

我有一个连接到我的计算机的物理设备,以及从Android Studio启动的模拟器:

$ adb devices
List of devices attached
0831bd3b21320609    no permissions (My phiscal Nexus 5)
emulator-5554   device (My Emulated device)

当我启动Appium并运行我的测试时,它会拿起我的物理设备 . Appium日志:

[debug] [ADB] Running '/home/babken/android-sdk/platform-tools/adb' with args: ["-P",5037,"-s","0831bd3b21320609","wait-for-device"]
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
...

测试挂起,我收到错误,因为它连接到错误的设备 .

我的appium功能中有这个:

desired_caps = {
    'platformName': 'Android',
    'deviceName': 'Android Device',
    'autoGrantPermissions': True,
    'app': apk_location,
    'newCommandTimeout': 36000,
}

我知道我可以将 udid 功能设置为 emulator-5554 ,但模拟器的名称可以更改 .

作为一种解决方法,我也可以插上我的Nexus或关闭USB调试,但这不是我的解决方案 .

1 回答

  • 0

    你尝试过“avd”功能吗?

    就像是

    desired_caps = {
        'platformName': 'Android',
        'deviceName': 'Android Emulator',
        'avd': 'emulator',
        'autoGrantPermissions': True,
        'app': apk_location,
        'newCommandTimeout': 36000,
    }
    

    在网站上,他们举了一个例子:api19,所以也许你可以指定你的模拟器API版本而不是名字 . (我没有尝试,但它可能会工作)而且你应该放入deviceName'Android Emulator'

    https://appium.io/docs/en/writing-running-appium/caps/

相关问题