从 appium 命令识别 genymotion 模拟器的问题
Issue with identifying genymotion emulators from appium command
我正在使用 Appium Android 通过 Genymotion 模拟器进行测试。我有几个模拟器,我想做的是构建一个脚本,一个接一个地(并行地)在每个模拟器上测试我的应用程序。该脚本启动一个模拟器,在其上测试应用程序,然后将其关闭。
为此,我需要在每次迭代时为 appium
命令提供一个特定的设备标识符(这很重要,因为在任何给定时间都有多个模拟器 运行) :
appium --udid XXXXXXXX
Appium 然后使用 -s XXXXXXXX
参数运行 adb。
问题是 Genymotion 模拟器不显示 udid 序列,而是当 运行 adb 我看到在启动时分配给设备的 address:port,这些不能用于自动化因为它们是不可预测的。
我发现 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 与参数中给定的匹配,所以运气不好。
有人 solution/workaround 这个问题吗?
您应该可以使用 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"。
我正在使用 Appium Android 通过 Genymotion 模拟器进行测试。我有几个模拟器,我想做的是构建一个脚本,一个接一个地(并行地)在每个模拟器上测试我的应用程序。该脚本启动一个模拟器,在其上测试应用程序,然后将其关闭。
为此,我需要在每次迭代时为 appium
命令提供一个特定的设备标识符(这很重要,因为在任何给定时间都有多个模拟器 运行) :
appium --udid XXXXXXXX
Appium 然后使用 -s XXXXXXXX
参数运行 adb。
问题是 Genymotion 模拟器不显示 udid 序列,而是当 运行 adb 我看到在启动时分配给设备的 address:port,这些不能用于自动化因为它们是不可预测的。
我发现 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 与参数中给定的匹配,所以运气不好。
有人 solution/workaround 这个问题吗?
您应该可以使用 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"。