Appium Appium Android ——利用 TestNG 并行执行用例

黑水 · 2014年12月01日 · 最后由 黑水 回复于 2019年07月07日 · 6636 次阅读
本帖已被设为精华帖!

一、测试类 * 注 1

package com.testerhome;

import io.appium.java_client.android.AndroidDriver;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

public class Suite1 {
    public String port;
    public String udid;
    private AndroidDriver driver;

  @Test
  public void switches() throws InterruptedException {
      WebElement sound = driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Sound\")");
      sound.click();
      System.out.println("checked");
      Thread.sleep(2000);
      System.out.println(Thread.currentThread());
  }

  @BeforeSuite
  @Parameters({ "port", "udid" })
  public void beforeSuite(String port, String udid) {
      this.port = port;
      this.udid = udid;

  }

  @BeforeClass
  public void beforeClass() throws MalformedURLException{
        System.out.println(port is  + port + , udid is " + udid);

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName","device");
        capabilities.setCapability("automationName","Appium");
        capabilities.setCapability("platformVersion", "4.4");
        capabilities.setCapability("udid", udid);
        capabilities.setCapability("appPackage", "com.android.settings");
        capabilities.setCapability("appActivity", ".Settings");
        driver = new AndroidDriver(new URL("http://127.0.0.1:" + port + "/wd/hub"), capabilities);

  }

  @AfterClass
  public void afterClass() {
      driver.quit();

  }

}

二、连接两个 Android 设备或启动两个虚拟机
使用
adb devices
获取 udid

三、项目路径下新建两个 testng.xml
testng1.xml

<?xml version="1.0" encoding="UTF-8"?>  
<suite name="Suite1">
  <parameter name = "port" value = "4723"/>
  <parameter name = "udid" value = "emulator-5554"/>
  <test name="Test">  
    <classes>  
      <class name="com.testerhome.Suite1"/> 
    </classes>  
  </test>  
</suite>  

testng2.xml

<?xml version="1.0" encoding="UTF-8"?>  
<suite name="Suite2">
  <parameter name = "port" value = "4725"/>
  <parameter name = "udid" value = "emulator-5556"/>
  <test name="Test">  
    <classes>  
      <class name="com.testerhome.Suite1"/> 
    </classes>  
  </test>  
</suite>  

四、开启两个 appium server * 注 2、注 3
如果命令行启动加参数
appium -p 4723 -bp 4724
appium -p 4725 -bp 4726

如果是图形界面,修改:
第一个:
General Settings 里的 Port ,改为 4723
Android Settings 里的 Bootstrap Port ,改为 4724

第二个:
General Settings 里的 Port ,改为 4725
Android Settings 里的 Bootstrap Port ,改为 4726

五、导出依赖 * 注 4
因为是用 maven 工程创建的,所以先导出依赖到项目路径下的 lib 文件夹
mvn dependency:copy-dependencies -DoutputDirectory=lib

六、执行测试
先用 Maven 串行执行一次以编译出 Class 文件
mvn clean test
然后
java -classpath ".\target\test-classes" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml
如果没有配置 TestNG 环境变量
java -classpath ".\target\test-classes;D:\Programs\testng-6.8\testng-6.8.jar" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml

七、查看报告
默认在项目路径下的 test-output 文件夹

注 1:
这个测试类没有指定 app 路径,如果指定,同时 unzip 的时候会冲突。目前是复制了多个 apk 。
File app = new File(appDir, "AppName"+port+".apk");
并在 appium server 指定不同的临时文件路径,比如:
--tmp D:\tem1
--tmp D:\tem2

注 2:
两个端口的介绍可以看这两个链接:
appium 自动化测试教程 ppt(第二版)
Appium Android Bootstrap 源码分析之简介

注 3:
如果使用到 Selendroid 或 Chromium ,还需要指定其他端口(需要修改测试类)
Selendroid port:8080
Selendroid port:8081
Chromium port:9515
Chromium port:9516

注 4:
本来准备直接用 mvn test 并行执行的,但没试出来传 suitethreadpoolsize 参数的办法

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 42 条回复 时间 点赞

这可以成为 appium 并行执行的指导文章。大赞!不过你试过跑 ui 的用例了么?

第一个:
Port:4723
bootstrapPort:4724

第二个:
Port:4725
bootstrapPort:4726

可以解释下 这两个端口的意思

不错, 已经开始用 maven 了, maven 和 gradle 都集成了一些测试约定流程。 目前貌似没多少人熟悉。

@lihuazhang 没记错第一个应该是脚本作为 client 和 appiumserver 通信的端口,后者是 mobile device 和 appium 通信的端口,也是 android 上特有的。

AppiumServer 一共用到大概 5 个端口,4723 默认为 Bootstrap 的 socket 端口。

示例为 suite 级别的并行 run,如果 suite 不平衡不能充分利用 Device 资源,我们现在用 case 级别的并行 run

#2 楼 @lihuazhang
跑过 ui 用例,有什么问题吗?
帖子有更新。

看了一下午了,这篇最给力了!赞!

#7 楼 @sanlengjingvv 我执行 mvn clean test 的时候报错
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
1:testCompile (default-testCompile) on project mytest: Compilation failure: Comp
ilation failure:
[ERROR] /E:/Users/Administrator/workspace/mytest/src/test/java/appiumdemo/mytest
/StuAppTest.java:[13,44] 程序包 org.openqa.selenium.browserlaunchers 不存在
[ERROR] /E:/Users/Administrator/workspace/mytest/src/test/java/appiumdemo/mytest
/TeaAppTest.java:[13,44] 程序包 org.openqa.selenium.browserlaunchers 不存在

这个是为什么

黑水 #10 · 2014年12月11日 Author

#9 楼 @nancy2896
这是 Maven 的问题,去看看 Maven 的书或资料吧。光看错误只能猜咯,maven 配置、pom 写错、依赖没下完等等……
完全按这个帖子来的前提是能正确用命令行执行 Maven 和 TestNG。


为什么我的一直不生效? 但在 target\test-classes 可以找到 class 文件啊 ?

#6 楼 @lihuazhang 首先是 Appium 的 Wrapper 可以重启,有端口分配的功能。然后 case 的并发级别设置为 parallel="methods" 。 然后在每个 case 跑之前去获取一个 Device 和一个可用的 Appium,跑完再把 Device 放回去。这里主要是 Device 的取和放,要做到阻塞,这样就可以控制并行执行

#12 楼 @cosyman Appium 的 Wrapper 是什么?那这样你就写个 afterMethod 了。

#13 楼 @lihuazhang
afterMethod 或 afterClass,Suite 取决于我们对 Appium 稳定性的把控吧。
Appium Server

#10 楼 @sanlengjingvv 传 suitethreadpoolsize 参数

suitethreadpoolsize 参数是什么意思啊?

我试过只能在一个设备跑

19楼 已删除

顶一个。。。

好文章不少啊

@sanlengjingvv 这样跑的话,生成的测试报告只有一份,testng2.xml 会覆盖 testng1.xml.

我用 maven 的 pom.xml 去配置 testng.xml,但是跑下来的结果是,串行跑,一台跑完去跑另外一台,求指教,如何能并行跑。

代码如下:



org.apache.maven.plugins
maven-surefire-plugin
2.18.1

...

testng2.xml
testng1.xml




28楼 已删除
黑水 #24 · 2015年03月22日 Author

#22 楼 @xiaobanli

这个帖子里没有用 maven 去调用 testng,maven 只是用来管理依赖,最后是导出依赖用命令行调用 testng,在命令行里传入 suitethreadpoolsize 参数利用 testng 提供的多线程功能并行执行。

testng 提供了 test、method、suit 等几种并行方式,开始我也是准备用 maven 调用 testng 的,后来发现 test、method 之类都可以,只有 suit 不能做到并行,但我需要的是 suit 级的并行,所以就换成导出依赖命令行执行这种方式了。

按你的执行方法报告会不会覆盖我没试,不过报告是可以指定目录的,outputDirectory
http://testng.org/doc/documentation-main.html#logging-xml-reports

按照说明操作了一遍,为什么只有一个运行成功,另一个运行失败

黑水 #25 · 2015年07月15日 Author

#25 楼 @bdqlwp 成功和失败两个 server 的全部日志都发下,用 markdown ,别发图片。

@sanlengjingvv ,以下是失败的 server 日志

info: Welcome to Appium v1.4.3 (REV a357c7fa73222315dd85c3d2dd8334767cca1b0d)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"automationName":"Appium"
,"platformName":"Android","deviceName":"device","platformVerison":"4.3","appActi
vity":".Settings","udid":"emulator-5554","appPackage":"com.android.settings"}}
info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
info: [debug] The following desired capabilities were provided, but not recogniz
ed by appium. They will be passed on to any other services running on this serve
r. : platformVerison
info: [debug] Didn't get app but did get Android package, will attempt to launch
it on the device
info: [debug] Creating new appium session 8792a326-e593-4e77-8ca4-e815f4563da2
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.7.0_71
info: [debug] Checking whether adb is present
info: [debug] Using adb from D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe
warn: No app capability, can't parse package/activity
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it's alr
eady on the device
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe devices
info: [debug] 2 device(s) connected
info: Found device emulator-5554
info: [debug] Setting device id to emulator-5554
info: [debug] Waiting for device to be ready and to respond to shell commands (t
imeout = 5)
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 wait-for-device
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Getting device API level
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 18
info: Device API level is: 18
info: [debug] Extracting strings for language: default
info: [debug] Apk doesn't exist locally
info: [debug] Could not get strings, but it looks like we had an old strings fil
e anyway, so ignoring
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 shell "rm -rf /data/local/tmp/strings.json"
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Skipping install since we launched with a package instead of an ap
p path
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 push "C:\Users\luowenping\AppData\Roaming\np
m\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/lo
cal/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 install "C:\Users\luowenping\AppData\Roaming\npm\
node_modules\appium\build\settings_apk\settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 install "C:\Users\luowenping\AppData\Roaming\npm\
node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5554 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-tools
\adb.exe -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.ap
pium.android.bootstrap.Bootstrap -e pkg com.android.settings -e disableAndroidWa
tchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRun
ner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.andro
id.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
error: Unhandled error: Error: read ECONNRESET
at exports._errnoException (util.js:746:11)
at TCP.onread (net.js:559:26) context: [POST /wd/hub/session {"desiredCapabi
lities":{"automationName":"Appium","platformName":"Android","deviceName":"device
","platformVerison":"4.3","appActivity":".Settings","udid":"emulator-5554","appP
ackage":"com.android.sett]
info: <-- POST /wd/hub/session - - ms - -
info: --> POST /wd/hub/session {"desiredCapabilities":{"automationName":"Appium"
,"platformName":"Android","deviceName":"device","platformVerison":"4.3","appActi
vity":".Settings","udid":"emulator-5554","appPackage":"com.android.settings"}}
info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
error: Failed to start an Appium session, err was: Error: Requested a new sessio
n but one was in progress
info: [debug] Error: Requested a new session but one was in progress
at [object Object].Appium.start (C:\Users\luowenping\AppData\Roaming\npm\nod
e_modules\appium\lib\appium.js:139:15)
at exports.createSession (C:\Users\luowenping\AppData\Roaming\npm\node_modul
es\appium\lib\server\controller.js:188:16)
at Layer.handle as handle_request
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:110:13)
at Route.dispatch (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appi
um\node_modules\express\lib\router\route.js:91:3)
at Layer.handle as handle_request
at C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_modules\
express\lib\router\index.js:267:22
at Function.proto.process_params (C:\Users\luowenping\AppData\Roaming\npm\no
de_modules\appium\node_modules\express\lib\router\index.js:321:12)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\index.js:261:10)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js💯14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\lib\server\co
ntroller.js:39:7
at Layer.handle as handle_request
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:110:13)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
at next (C:\Users\luowenping\AppData\Roaming\npm\node_modules\appium\node_mo
dules\express\lib\router\route.js:104:14)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"
A new session could not be created. (Original error: Requested a new session but
one was in progress)","origValue":"Requested a new session but one was in progr
ess"},"sessionId":"8792a326-e593-4e77-8ca4-e815f4563da2"}
info: <-- POST /wd/hub/session 500 169.997 ms - 250
undefined

下面是成功的 server 的日志

info: --> POST /wd/hub/session {"desiredCapabilities":{"automationName":"Appium"
,"platformName":"Android","deviceName":"device","platformVerison":"4.3","appActi
vity":".Settings","udid":"emulator-5556","appPackage":"com.android.settings"}}
info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
info: [debug] The following desired capabilities were provided, but not recogniz
ed by appium. They will be passed on to any other services running on this serve
r. : platformVerison
info: [debug] Didn't get app but did get Android package, will attempt to launch
it on the device
info: [debug] Creating new appium session 0f66c23a-6322-4022-9a23-f91655693041
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.7.0_71
info: [debug] Checking whether adb is present
info: [debug] Using adb from D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe
warn: No app capability, can't parse package/activity
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it's alr
eady on the device
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe devices
info: [debug] 2 device(s) connected
info: Found device emulator-5556
info: [debug] Setting device id to emulator-5556
info: [debug] Waiting for device to be ready and to respond to shell commands (t
imeout = 5)
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 wait-for-device
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Getting device API level
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 18
info: Device API level is: 18
info: [debug] Extracting strings for language: default
info: [debug] Apk doesn't exist locally
info: [debug] Could not get strings, but it looks like we had an old strings fil
e anyway, so ignoring
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "rm -rf /data/local/tmp/strings.json"
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Skipping install since we launched with a package instead of an ap
p path
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 push "C:\Users\luowenping\AppData\Roaming\np
m\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/lo
cal/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 install "C:\Users\luowenping\AppData\Roaming\npm\
node_modules\appium\build\settings_apk\settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 install "C:\Users\luowenping\AppData\Roaming\npm\
node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-tools
\adb.exe -s emulator-5556 shell uiautomator runtest AppiumBootstrap.jar -c io.ap
pium.android.bootstrap.Bootstrap -e pkg com.android.settings -e disableAndroidWa
tchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRun
ner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.andro
id.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] [BOOTSTRAP] [debug] Client connected
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "dumpsys window"
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action"
:"wake","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: wake
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Screen already unlocked, continuing.
info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action"
:"getDataDir","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
info: [debug] dataDir set to: /data
info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy"
,{"compressLayout":false}]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"\/data","status":0
}
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action"
:"compressedLayoutHierarchy","params":{"compressLayout":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":false,"status":0}
info: [debug] Getting device API level
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 18
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "am start -S -a android.intent.action.MAIN
-c android.intent.category.LAUNCHER -f 0x10200000 -n com.android.settings/.Setti
ngs"
info: [debug] Waiting for pkg "com.android.settings" and activity ".Settings" to
be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "dumpsys window windows"
info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform-
tools\adb.exe -s emulator-5556 shell "getprop ro.build.version.release"
info: [debug] Device is at release version 4.3
info: [debug] Device launched! Ready for commands
info: [debug] Setting command timeout to the default of 60 secs
info: [debug] Appium session started with sessionId 0f66c23a-6322-4022-9a23-f916
55693041
info: <-- POST /wd/hub/session 303 23281.405 ms - 74
info: --> GET /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041 {}
info: [debug] Responding to client with success: {"status":0,"value":{"platform"
:"LINUX","browserName":"Android","platformVersion":"4.3","webStorageEnabled":fal
se,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"netw
orkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired
":{"automationName":"Appium","platformName":"Android","deviceName":"device","pla
tformVerison":"4.3","appActivity":".Settings","udid":"emulator-5556","appPackage
":"com.android.settings"},"automationName":"Appium","platformName":"Android","de
viceName":"emulator-5556","platformVerison":"4.3","appActivity":".Settings","udi
d":"emulator-5556","appPackage":"com.android.settings"},"sessionId":"0f66c23a-63
22-4022-9a23-f91655693041"}
info: <-- GET /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041 200 2.913 ms

  • 698 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformV ersion":"4.3","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnable d":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContext Enabled":false,"warnings":{},"desired":{"automationName":"Appium","platformName" :"Android","deviceName":"device","platformVerison":"4.3","appActivity":".Setting s","udid":"emulator-5556","appPackage":"com.android.settings"},"automationName": "Appium","platformName":"Android","deviceName":"emulator-5556","platformVerison" :"4.3","appActivity":".Settings","udid":"emulator-5556","appPackage":"com.androi d.settings"},"sessionId":"0f66c23a-6322-4022-9a23-f91655693041"} info: --> POST /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041/element {"us ing":"-android uiautomator","value":"new UiSelector().text(\"Sound\")"} info: [debug] Waiting up to 0ms for condition info: [debug] Pushing command to appium work queue: ["find",{"strategy":"-androi d uiautomator","selector":"new UiSelector().text(\"Sound\")","context":"","multi ple":false}] info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action" :"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector() .text(\"Sound\")","context":"","multiple":false}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: find info: [debug] [BOOTSTRAP] [debug] Finding new UiSelector().text("Sound") using A NDROID_UIAUTOMATOR with the contextId: multiple: false info: [debug] [BOOTSTRAP] [debug] Parsing selector: new UiSelector().text("Sound ") info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: "Sound" info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=Sound] info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"1"},"st atus":0} info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT": "1"},"sessionId":"0f66c23a-6322-4022-9a23-f91655693041"} info: <-- POST /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041/element 200 41005.676 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"0f66c23a-6322 -4022-9a23-f91655693041"} info: --> POST /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041/element/1/cl ick {"id":"1"} info: [debug] Pushing command to appium work queue: ["element:click",{"elementId ":"1"}] info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action" :"element:click","params":{"elementId":"1"}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: click info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0} info: [debug] Responding to client with success: {"status":0,"value":true,"sessi onId":"0f66c23a-6322-4022-9a23-f91655693041"} info: <-- POST /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041/element/1/cl ick 200 3721.447 ms - 76 {"status":0,"value":true,"sessionId":"0f66c23a-6322-402 2-9a23-f91655693041"} info: --> DELETE /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041 {} info: Shutting down appium session info: [debug] Pressing the HOME button info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20130917\sdk\platform- tools\adb.exe -s emulator-5556 shell "input keyevent 3" info: [debug] Stopping logcat capture info: [debug] Logcat terminated with code null, signal SIGTERM info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"} info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down" ,"status":0} info: [debug] Sent shutdown command, waiting for UiAutomator to stop... info: [debug] [BOOTSTRAP] [debug] Closed client connection info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1 info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRun ner info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.andro id.bootstrap.Bootstrap info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1 info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0 info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream= info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=. info: [debug] [UIAUTOMATOR STDOUT] Time: 60.976 info: [debug] [UIAUTOMATOR STDOUT] OK (1 test) info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1 info: [debug] UiAutomator shut down normally info: [debug] Cleaning up android objects info: [debug] Cleaning up appium session info: [debug] Responding to client with success: {"status":0,"value":null,"sessi onId":"0f66c23a-6322-4022-9a23-f91655693041"} info: <-- DELETE /wd/hub/session/0f66c23a-6322-4022-9a23-f91655693041 200 4958.2 77 ms - 76 {"status":0,"value":null,"sessionId":"0f66c23a-6322-4022-9a23-f916556 93041"}
黑水 #28 · 2015年07月15日 Author

#27 楼 @bdqlwp

四、开启两个 appium server * 注 2、注 3
如果命令行启动加参数
appium -p 4723 -bp 4724
appium -p 4725 -bp 4726
如果是图形界面,修改:
第一个:
General Settings 里的 Port ,改为 4723
Android Settings 里的 Bootstrap Port ,改为 4724
第二个:
General Settings 里的 Port ,改为 4725
Android Settings 里的 Bootstrap Port ,改为 4726

1、 没做或者做错了,正确的端口应该不一样。
2、日志改成这样的效果,排版说明

info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724

#28 楼 @sanlengjingvv 感谢楼主热心回复,设置 Bootsrap Port 后,现在两个都可以正常运行了。:plus1:

@sanlengjingvv 楼主 我为什么每次执行都直接 skip 了,

用 mvn clean test 也能正常执行,所有用例都执行完了,端口也都指定了,不知道是哪里出问题了

黑水 #31 · 2015年09月06日 Author

#30 楼 @nancy2896
需要看失败时候的 appium server 日志。

#31 楼 @sanlengjingvv 我重新配置了一遍环境现在好了 谢谢分享的文章

#22 楼 @xiaobanli 我也是串行跑的,最后怎么解决的?

#32 楼 @nancy2896 请问你可以多个设备并行跑吗?我的按着帖子的操作是串行跑的。我是用 maven 调用的 testng

#34 楼 @fengcanfly 我是完全按照楼主的方法弄得 是可以并行的

黑水 #36 · 2015年11月06日 Author

#34 楼 @fengcanfly
主楼的做法,最后不是用 Maven 调用 TestNG。
如果你是指 Maven - Surefire Plugin - TestNG 这样调用,写帖子的时候还做不到 suit 级别的并行。

有其他的并行测试方案吗,机器如果几十台 + 的话不可能建这么多 tesgng 文件吧。

黑水 #38 · 2016年01月18日 Author

#37 楼 @13651969749
如果只知道你说的,第一个想到的就是再写个小程序生成几十个 testNG 文件。
社区里有其他方案的

太赞了,确实可以实现多个模拟器并发控制。之前只在多个 VM 上尝试过,现在可以通过设置端口号在一个 VM 上同时操作多个模拟器,非常感谢。另外可以把两个测试类写到配置到一个 testng.xml 中,在 testng.xml 中配置多线程,实现并发。

学习了,我也试试。

梁慧玲 [该话题已被删除] 中提及了此贴 07月01日 10:01
黑水 [该话题已被删除] 中提及了此贴 07月02日 09:38
pjl 利用 TESTNG 并行用例踩过的坑 中提及了此贴 04月26日 14:05

这是啥问题啊 ,步骤好像有点不明白。
org.testng.TestNGException:
Cannot instantiate class com.AppiumTestTHEARD.NewTest
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:363)
at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:275)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:126)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:191)
at org.testng.TestClass.getInstances(TestClass.java:100)
at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:86)
at org.testng.TestClass.init(TestClass.java:78)
at org.testng.TestClass.(TestClass.java:41)
at org.testng.TestRunner.initMethods(TestRunner.java:425)
at org.testng.TestRunner.init(TestRunner.java:252)
at org.testng.TestRunner.init(TestRunner.java:222)
at org.testng.TestRunner.(TestRunner.java:171)
at org.testng.remote.support.RemoteTestNG6_10$1.newTestRunner(RemoteTestNG6_10.java:28)
at org.testng.remote.support.RemoteTestNG6_10$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_10.java:61)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:623)
at org.testng.SuiteRunner.init(SuiteRunner.java:189)
at org.testng.SuiteRunner.(SuiteRunner.java:136)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1375)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1355)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
... 25 more
Caused by: java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787)
at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:96)
at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:72)
at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:46)
at com.AppiumTestTHEARD.NewTest.(NewTest.java:28)
... 30 more

java -classpath ".\target\test-classes;D:\Programs\testng-6.8\testng-6.8.jar" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml
后面跟 2 个 testng.xml 是会同时执行吗,还是执行完一个再执行另一个

追梦 回复

同时执行

xdlhy Appium 并发和主从远程控制 中提及了此贴 09月18日 18:35
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册