多个设备同时执行多个不同的用例,研究了大半天终于搞定了,也不难,给大家分享一下
测试类 1:

package com.fenfa;
。。。。。
import com.jayway.jsonpath.JsonPath;

public class XiaoMi {
    private AndroidDriver driver;
    File classpathRoot = new File(System.getProperty("user.dir"));
    File res = new File(classpathRoot, "resource");
    String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
    String timeJson = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    String timeS = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
    Tools tool=new Tools();
    String port;
    String udid;

    // 生成json

    public static int lastPage = 0;
    public static int pageIndex = 1;
    public static String number = "";
    // 屏幕宽高
    public static int width = 0;
    public static int height = 0;


    @BeforeMethod
    @Parameters({"port","udid"})
    public void setUp(String port,String udid) throws Exception {
        System.out.println(port+" "+udid);
        // set up appium
        File app = new File(res, "com.xiaomi.market_R.1.4.5.apk");
        System.out.println(app.getAbsolutePath());
        DesiredCapabilities capabilities = new DesiredCapabilities();
        //capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("deviceName", udid);
        capabilities.setCapability("udid", udid);
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("platformVersion", "4.4.4");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("app-package", "com.xiaomi.market");
        capabilities.setCapability("app-activity", ".ui.MainTabActivity");
        driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),
                capabilities);
    }

    @Test(groups = { "SDK" })
    public void testXiaomi() throws InterruptedException{
        tool.screenShot("小米", "分类", 1, driver);
        System.out.println("小米-------");
              。。。。。
    }

    @AfterMethod
    public void tearDown() throws Exception {
        driver.quit();
    }
}

测试类 2

package com.fenfa;
。。。。。
import com.jayway.jsonpath.JsonPath;

public class WanDouJia {
    private AndroidDriver driver;
    File classpathRoot = new File(System.getProperty("user.dir"));
    File res = new File(classpathRoot, "resource");
    String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
    String timeJson = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
            .format(new Date());
    String timeS = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
    Tools tool=new Tools();
    String port;
    String udid;

    // 生成json

    public static int lastPage = 0;
    public static int pageIndex = 1;
    public static String number = "";
    // 屏幕宽高
    public static int width = 0;
    public static int height = 0;

    @BeforeMethod
    @Parameters({"port","udid"})
    public void setUp(String port,String udid) throws Exception {
        System.err.println(port+" "+udid);
        // set up appium
        File app = new File(res, "com.xiaomi.market_R.1.4.5.apk");
        System.out.println(app.getAbsolutePath());
        DesiredCapabilities capabilities = new DesiredCapabilities();
        // capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("deviceName", udid);
        capabilities.setCapability("udid", udid);
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("platformVersion", "4.4.4");
        capabilities.setCapability("platformName", "Android");
        // capabilities.setCapability("unicodeKeyboard", "True");
        // capabilities.setCapability("resetKeyboard", "True");
        capabilities.setCapability("app", app.getAbsolutePath());
        // capabilities.setCapability("app-package", "com.xiaomi.market");
        // capabilities.setCapability("app-activity", ".ui.MainTabActivity");
        driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),
                capabilities);
    }
    @Test(groups = { "SDK" })
    public void testWanDou() throws InterruptedException{
        tool.screenShot("豌豆荚", "分类", 1, driver);
        System.out.println("豌豆荚----------");
               。。。。。
    }

    @AfterMethod
    public void tearDown() throws Exception {
        driver.quit();
    }
}
配置中一定要用udid,andorid也就是deviceName当作udid使用

testng.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<suite name='Suite1' parallel="tests" thread-count="5">

 <test name="demo1">
   <parameter name = "port" value = "4723"/>
   <parameter name = "udid" value = "331f188d"/>
   <classes>
     <class name="com.fenfa.XiaoMi"/> 
    </classes>
  </test>

   <test name="demo2">
       <parameter name = "port" value = "4725"/>
       <parameter name = "udid" value = "CB5A21SXVP"/>
       <classes>
     <class name="com.fenfa.WanDouJia"/>
     </classes>
  </test>
</suite>
testng.xml中配置参数,多线程个数thread-count="5"

pom.xml 的一部分

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
      <configuration>
            <suiteXmlFiles>
                 <suiteXmlFile>testng.xml</suiteXmlFile>
            </suiteXmlFiles>                
    </configuration>
</plugin>

启动多个 appium server
第一个 server


第二个 server

最后执行
mvn test


↙↙↙阅读原文可查看相关链接,并与作者交流