我写了 2 个测试类 , 测试连接 2 个设备
adb devices 里面能查到两个设备,但是每次运行的时候总是只运行一个设备

 info: [debug] 2 device(s) connected
> info: Found device 2b7a4e3f
> info: [debug] Setting device id to 2b7a4e3f
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: D:\sdk\platform-tools\adb.exe -s 2b7a4e3f wait-for-device

appium 启动了 2 个,端口分别设置为了 4723 4725,

在测试类中也分别指定了设备和端口,还需要设置什么么?怎么才能分别运行两个设备

测试类如下:

第一个测试类如下:

protected void setUp() throws Exception {
        // TODO Auto-generated method stub
        super.setUp();

         File classpathRoot = new File(System.getProperty("user.dir"));
            File appDir = new File(classpathRoot, "/apps/teacher");
            File app = new File(appDir, "teacher-3.1.3-callnames--ceshi-2014-12-08-1457.apk");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("deviceName","2b7a4e3f");
            capabilities.setCapability("platformVersion", "4.4");
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability("appPackage", "air.com.xueersi.ICSClient3");
            capabilities.setCapability("appActivity", "air.com.xueersi.ICSClient3.LoginActivity");
            //设置中文输入的属性
            capabilities.setCapability("unicodeKeyboard", "True");
            capabilities.setCapability("resetKeyboard", "True");
            driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    }

    @Override
    protected void tearDown() throws Exception {
        // TODO Auto-generated method stub
        driver.quit();
    }

    /**
     * Rigourous Test :-)
     * @throws InterruptedException 
     */
    public void testLogin() throws InterruptedException
    {
         List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");


         textFieldsList.get(0).sendKeys("滕俊龙");
         Thread.sleep(2000);

         textFieldsList.get(1).sendKeys("020639");
         Thread.sleep(2000);


         driver.findElementByName("登录").click();
         Thread.sleep(2000);
    }

第二个测试类如下:

protected void setUp() throws Exception {
        // TODO Auto-generated method stub
        super.setUp();

         File classpathRoot = new File(System.getProperty("user.dir"));
            File appDir = new File(classpathRoot, "/apps/student");
            File app = new File(appDir, "test_stu.apk");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("deviceName","430072fe470da099");
            capabilities.setCapability("platformVersion", "4.3");
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability("appPackage", "air.ICS.StudentClient");
            capabilities.setCapability("appActivity", "air.ICS.StudentClient.LoginActivity");
            //设置中文输入的属性
            capabilities.setCapability("unicodeKeyboard", "True");
            capabilities.setCapability("resetKeyboard", "True");
            driver = new AppiumDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);

    }

    @Override
    protected void tearDown() throws Exception {
        // TODO Auto-generated method stub
        driver.quit();
    }


    /**
     * Rigourous Test :-)
     * @throws InterruptedException 
     */
    public void testLogin() throws InterruptedException
    {


        WebElement login_with_guest_button = driver.findElement(By.id("login_with_guest"));
        login_with_guest_button.click();
         Thread.sleep(2000);
         List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");


         textFieldsList.get(0).sendKeys("aaaaa");
         Thread.sleep(2000);


         driver.findElementByName("登录").click();

    }

为什么执行的时候 4725 这个端口的 appium 不执行测试?
log 提示找不到 activity 我确定我的 activity 设置没有错。

 error: Failed to start an Appium session, err was: Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
>     at null.<anonymous> (E:\study\xuexi\Appium\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1130:21)
>     at null.<anonymous> (E:\study\xuexi\Appium\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:172:9)
>     at ChildProcess.exithandler (child_process.js:635:7)
>     at ChildProcess.EventEmitter.emit (events.js:98:17)
>     at maybeClose (child_process.js:743:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)","origValue":"Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 27197.867 ms - 346 


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