【问题标题】:Issue with identifying genymotion emulators from appium command从 appium 命令识别 genymotion 模拟器的问题
【发布时间】:2016-03-23 16:22:42
【问题描述】:

我正在使用 Appium 使用 Genymotion 模拟器进行 Android 测试。我有几个模拟器,我想做的是构建一个脚本,在每个模拟器上一个接一个地测试我的应用程序(并且并行)。该脚本启动一个模拟器,在其上测试应用程序,然后将其关闭。

为此,我需要在每次迭代时为appium 命令提供特定的设备标识符(这很关键,因为在任何给定时间都有多个模拟器在运行):

appium --udid XXXXXXXX

Appium 然后使用 -s XXXXXXXX 参数运行 adb。

问题是 Genymotion 模拟器不显示 udid 序列号,而是在运行 adb 时,我看到了在启动时分配给设备的地址:端口,这些不能用于自动化,因为它们是不可预测的。

我发现 adb 可以通过指定要使用的属性来使用 udid 以外的参数调用特定设备。这样,我需要做的就是使用模拟器的模型,一切都应该工作:

adb -s model:Google_Nexus_4___4_4_4___API_19___768x1280

但是,当我尝试像这样将其合并到 Appium 中时:

appium --udid model:Google_Nexus_4___4_4_4___API_19___768x1280

我收到以下错误:

[36minfo[39m: Retrieving device
[36minfo[39m: [debug] Trying to find a connected android device
[36minfo[39m: [debug] Getting connected devices...
[36minfo[39m: [debug] executing cmd: /Users/mor/Library/Android/sdk/platform-tools/adb devices
[36minfo[39m: [debug] 2 device(s) connected
[36minfo[39m: [debug] Sent shutdown command, waiting for UiAutomator to stop...
[33mwarn[39m: UiAutomator did not shut down fast enough, calling it gone
[36minfo[39m: [debug] Cleaning up android objects
[36minfo[39m: [debug] Cleaning up appium session
[36minfo[39m: [debug] Error: Device model:Google_Nexus_4___4_4_4___API_19___768x1280 was not in the list of connected devices

这显然意味着 Appium 首先运行 adb devices,然后才尝试将 udid 与参数中给出的匹配,所以没有运气。

有人对此问题有解决方案/解决方法吗?

【问题讨论】:

    标签: android testing adb appium genymotion


    【解决方案1】:

    您应该能够使用 adb 获取 udid

    adb -s model:Google_Nexus_4___4_4_4___API_19___768x1280 shell settings get secure android_id
    

    然后把这个交给appium。

    如果您需要将其传递到命令行(并且您有一个 bash shell),您可以使用 xargs

    adb -s model:Google_Nexus_4___4_4_4___API_19___768x1280 shell settings get secure android_id | xargs -I myudid appium --udid myudid
    

    编辑问题中的更多细节:

    adb devices | grep `adb -s model:Google_Nexus_4___4_4_4___API_19___768x1280 shell ip route | cut -d" " -f1 | cut -d"/" -f1` | sed "1 d" | cut -f 1 | xargs -I ip appium --udid ip 
    

    由问题作者编辑:

    在 Genymotion 设备上使用 adb -s model:Google_Nexus_4___4_4_4___API_19___768x1280 shell ip route 时,结果如下所示:

    default via 10.0.3.2 dev eth1
    default via 10.0.3.2 dev eth1  metric 205
    10.0.3.0/24 dev eth1  scope link
    10.0.3.0/24 dev eth1  proto kernel  scope link  src 10.0.3.15  metric 205
    10.0.3.2 dev eth1  scope link
    192.168.56.0/24 dev eth0  proto kernel  scope link  src 192.168.56.101
    

    我的工作命令:

    adb -s model:Google_Nexus_4___4_4_4___API_19___768x1280 shell ip route | grep "eth0" | rev | cut -d" " -f2 | rev | cut -d" " -f1
    

    据我所知,端口总是默认为5555,所以这样我就可以得到地址并可以为appium命令构建自己的“udid”。

    【讨论】:

    • 问题是 adb 不显示 udid 而是显示 genymotion 设备的地址:端口:192.168.56.101:5555 device。我试过你的答案,但没有用。
    • 澄清一下:如果我使用以下命令启动 appium:appium --udid 192.168.56.101:5555 那么它可以正常工作。
    • 好吧,我想我理解你了。我没有 genymotion 可以尝试,但我已经发布了一个新命令来尝试我的答案(需要代码格式化)
    • 如果您将最后一个管道后的位更改为“| xargs -I ip echo ip”,它应该只是吐出设备的 ip 和端口。请注意,如果设备只有一个由“adb -s model:Google_Nexus_4___4_4_4___API_19___768x1280 shell ip route”返回的数据连接,则上述命令应该有效
    • 谢谢!你已经给了我足够的信息来让它工作。我正在编辑你的答案,让其他人看看我做了什么。
    猜你喜欢
    • 2016-06-22
    • 2015-04-27
    • 2014-12-27
    • 2013-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    相关资源
    最近更新 更多