Appium 【已解答】appium linux 支持多个模拟器

yunmu · 2014年02月13日 · 最后由 恒温 回复于 2014年02月17日 · 1420 次阅读

办法:
1.首先通过 adb devices 看 adb 已经连接了哪些设备:
我的执行结果:
$adb devices
List of devices attached
emulator-5564 device
emulator-5560 device
emulator-5562 device
emulator-5566 device

2.运行 appium 设置端口和连接的设备
例如:
sudo appium -p 4705 -U emulator-5566

说明:这里的-U 参数的含义是 adb 给设备分配的唯一标示,而不是设备本身的 UUID,我之前这里的理解有误

3.在脚本中连接到对应的端口就会用对应的模拟器执行脚本

driver = webdriver.Remote('http://localhost:4705/wd/hub', desired_caps)

说明:之前我用--avd 参数不行

下面是我之前的提问,感谢 @lihuazhang @seveniruby 等同学在过程中提供的帮助

我在虚拟机上安装了 4 个模拟器,运行 appium 的时候加上了--avd 的参数,但是真正脚本运行的时候没有选择我参数指定的模拟器,而是选择了第一个
我的是在 linux 环境
appium 是通过 npm 安装的

adb devices 显示 4 个

运行命令加上了 avd 的参数
$sudo appium --avd emulator-5566
info: Welcome to Appium v0.15.0 (REV a7b47d73a27074cc928cc5b325e5d4de1b6e5594)
info: Appium REST http interface listener started on 0.0.0.0:4723
info - socket.io started

运行脚本后的日志信息:
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"sessionId":null,"desiredCapabilities":{"app-package":"com.taobao.mtl.hybrid.test","app":"/home/admin/appium/mtl-hybrid-app.apk","browserName":"","version":"4.2","device":"Android","app-activity":".PortalActivity"}}
info: Using local app from desiredCaps: /home/admin/appium/mtl-hybrid-app.apk
info: Creating new appium session 53a3c590-de8f-4c5c-ba3d-a36a4b66ab32
info: Starting android appium
debug: Using fast reset? true
info: Preparing device for session
info: Checking whether app is actually present
info: Checking whether adb is present
info: [ADB] Using adb from /home/admin/android/sdk/platform-tools/adb

info: Getting running AVD name
info: Sending telnet command to device: avd name
info: Getting running emulator port
info: [ADB] Getting connected devices...
debug: executing: /home/admin/android/sdk/platform-tools/adb devices
info: [ADB] 4 device(s) connected
info: Socket connection to device created
info: Socket connection to device ready
info: Telnet command got response: 4.2--320X480
info: Launching Emulator with AVD emulator-5566
info: Checking whether emulator is present
info: [ADB] Using emulator from /home/admin/android/sdk/tools/emulator

info: Trying to find a connected android device
info: [ADB] Getting connected devices...
debug: executing: /home/admin/android/sdk/platform-tools/adb devices
error: Unable to start Emulator: spawn ENOENT
info: [ADB] 4 device(s) connected
info: Trying to find a connected android device
info: [ADB] Getting connected devices...
debug: executing: /home/admin/android/sdk/platform-tools/adb devices
info: [ADB] 4 device(s) connected
info: Setting device id to emulator-5564
info: [ADB] Waiting for device to be ready and to respond to shell commands (timeout = 5)
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 wait-for-device
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "echo 'ready'"
info: Starting logcat capture
info: Getting device API level
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "getprop ro.build.version.sdk"
info: Device is at API Level 17
debug: java -jar "/usr/local/lib/node_modules/appium/lib/devices/android/helpers/strings_from_apk.jar" "/home/admin/appium/mtl-hybrid-app.apk" "/tmp/com.taobao.mtl.hybrid.test"
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 push "/tmp/com.taobao.mtl.hybrid.test/strings.json" /data/local/tmp
debug: Not uninstalling app since server not started with --full-reset
info: MD5 for app is ce5b8c7e689ca958a1ad3c8999925445
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "ls /data/local/tmp/ce5b8c7e689ca958a1ad3c8999925445.apk"
debug: Getting install status for com.taobao.mtl.hybrid.test
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "pm list packages -3 com.taobao.mtl.hybrid.test"
info: [ADB] App is installed
info: Running fastClear
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "am force-stop com.taobao.mtl.hybrid.test"
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "pm clear com.taobao.mtl.hybrid.test"
info: [ADB] Forwarding system:4724 to device:4724
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 forward tcp:4724 tcp:4724
debug: Pushing appium bootstrap to device...
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 push "/usr/local/lib/node_modules/appium/build/android_bootstrap/AppiumBootstrap.jar" /data/local/tmp/
debug: Pushing unlock helper app to device...
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 install /usr/local/lib/node_modules/appium/build/unlock_apk/unlock_apk-debug.apk
info: Attempting to kill all 'uiautomator' processes
info: Getting all processes with 'uiautomator'
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "ps 'uiautomator'"
info: No matching processes found
info: Running bootstrap
debug: spawning: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [BOOTSTRAP] [info] Socket opened on port 4724
info: [BOOTSTRAP] [info] Appium Socket Server Ready
info: [BOOTSTRAP] [info] Loading json...
debug: Waking up device if it's not alive
info: Pushing command to appium work queue: ["wake",{}]
info: [BOOTSTRAP] [info] json loading complete.
info: [BOOTSTRAP] [info] Registered crash watchers.
info: [BOOTSTRAP] [info] Client connected
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"wake","params":{}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: wake
info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "dumpsys window"
info: Writing dumpsys output to /usr/local/lib/node_modules/appium/.dumpsys.log
debug: Screen already unlocked, continuing.
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.taobao.mtl.hybrid.test/.PortalActivity"
info: Waiting for activity to be focused
info: Getting focused package and activity
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "dumpsys window windows"
info: Getting focused package and activity
debug: executing: /home/admin/android/sdk/platform-tools/adb -s emulator-5564 shell "dumpsys window windows"
info: Device launched! Ready for commands (will time out in 60secs)
info: Appium session started with sessionId 53a3c590-de8f-4c5c-ba3d-a36a4b66ab32
POST /wd/hub/session 303 15784ms - 9b
debug: Appium request initiated at /wd/hub/session/53a3c590-de8f-4c5c-ba3d-a36a4b66ab32
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"","version":"4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"app-package":"com.taobao.mtl.hybrid.test","app":"/home/admin/appium/mtl-hybrid-app.apk","device":"Android","app-activity":".PortalActivity"},"sessionId":"53a3c590-de8f-4c5c-ba3d-a36a4b66ab32"}
GET /wd/hub/session/53a3c590-de8f-4c5c-ba3d-a36a4b66ab32 200 3ms - 446b
debug: Appium request initiated at /wd/hub/session/53a3c590-de8f-4c5c-ba3d-a36a4b66ab32/elements
debug: Request received with params: {"using":"tag name","sessionId":"53a3c590-de8f-4c5c-ba3d-a36a4b66ab32","value":"textfield"}
info: Pushing command to appium work queue: ["find",{"strategy":"tag name","selector":"textfield","context":"","multiple":true}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"tag name","selector":"textfield","context":"","multiple":true}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: find
info: [BOOTSTRAP] [debug] Finding textfield using TAG_NAME with the contextId:
info: [BOOTSTRAP] [info] Element[] is null: (0)
info: [BOOTSTRAP] [info] Element[] is null: (1)
info: [BOOTSTRAP] [info] Element[] is null: (2)
info: [BOOTSTRAP] [info] Element[] is null: (3)
info: [BOOTSTRAP] [info] Element[] is null: (4)
info: [BOOTSTRAP] [info] Returning result: {"value":[{"ELEMENT":"1"},{"ELEMENT":"2"},{"ELEMENT":"3"},{"ELEMENT":"4"}],"status":0}
info: Responding to client with success: {"status":0,"value":[{"ELEMENT":"1"},{"ELEMENT":"2"},{"ELEMENT":"3"},{"ELEMENT":"4"}],"sessionId":"53a3c590-de8f-4c5c-ba3d-a36a4b66ab32"}
POST /wd/hub/session/53a3c590-de8f-4c5c-ba3d-a36a4b66ab32/elements 200 2428ms - 225b
debug: Appium request initiated at /wd/hub/session/53a3c590-de8f-4c5c-ba3d-a36a4b66ab32/element/1/value
debug: Request received with params: {"sessionId":"53a3c590-de8f-4c5c-ba3d-a36a4b66ab32","id":"1","value":["h","t","t","p",":","/","/","m",".","t","a","o","b","a","o",".","c","o","m"]}
info: Pushing command to appium work queue: ["element:setText",{"elementId":"1","text":"http://m.taobao.com"}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"1","text":"http://m.taobao.com"}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: setTex

根据日志的分析在连接的时候没有链接到指定的 avd 哈
请问哪位大神知道?

另外之前看到有帖子讨论说增加-U 参数和 grid 模式,不太清楚如何操作,知道的同学请指教一下

共收到 4 条回复 时间 点赞

自己顶下哈

Started two Appium servers with different ports defining -U flags

Okay this is my current setup

1) One Nexus 4 and one emulator running on Mac
2) two appium instances running on different ports
3) Parallel execution two threads to run same test

This is the error I am getting

" A session is either terminated or not started (WARNING: The server did not provide any stacktrace information)"

Appium log

First one runs but other one says this ADB Error:

info: [ADB] Forwarding system:4724 to device:4724
info: [ANDROID] [debug] Could not start socket server listening on 4724

For both threads it says this - any insights if I need to change something?

These are my capabilities:

capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.2");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("device", Device);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("app-package", "blah");
capabilities.setCapability("app-activity", "blah");
try {
driver = new RemoteWebDriver(
new URL("http://localhost:" + Port + "/wd/hub"), capabilities);

    } catch (Exception e) {
        e.printStackTrace();
    }

只是看到这种选项了, 但是并没真正用过 @lihuazhang 默认监听 4723 和 4724 其中 4724 貌似是硬编码进去的, 同时开可能会有问题. 应该需要修改代码. node-config 参数只是说作为节点, 并不代表可以同时开多个, 还是得自己 hack 下吧

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册