android - 从 appium 命令识别 genymotion 模拟器的问题

标签 android testing adb appium genymotion

我正在使用 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 与参数中给定的匹配,所以没有运气。

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

最佳答案

您应该能够使用 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”。

关于android - 从 appium 命令识别 genymotion 模拟器的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34330540/

相关文章:

android - Geofences 不触发(pendingintents 和 broadcastreceiver)

android - 特定项目使用哪个 MBaaS 平台 : Parse or Google Cloud

unit-testing - angularjs Controller 测试 : unsatistifed post request

testing - 当 WebTestCase 用于功能测试包时指定配置?

android - 使用 cheezy/ADB 的独立 ruby​​ 脚本

android - 适用于 Android 的 HTML5 中的视频和音频标签

Android ffmpeg 应用视频效果需要时间

Java 解析器测试

android-studio - 安卓工作室 : "Unable to obtain result of ' adb version'"

android - 如何在 Android 设备上运行 Linux 命令?