• #6 楼 @umbrella1978
    另一个测试类怎么能延续前面的测试呢?我现在是两个应用要交互,我得写多个测试类:
    比如我在测试类 A 中执行了方法 a,完成了登录
    我在测试类 B 中想执行登录后的操作,能不能不再重复登录动作?

    或者说能不能在测试类 A 中执行完登录后暂停,然后我执行另外一个类,完了再回来执行测试类 A,有办法实现么?
    谢谢

  • #6 楼 @umbrella1978 恩 我按你说的方法试了 好了 非常感谢

  • #2 楼 @anikikun

    什么意思?怎么保持 case 的独立性?我想依赖之前的页面

  • #1 楼 @umbrella1978
    testStudentlist() 这个方法就不会执行

    package appiumdemo.mytest;

    import io.appium.java_client.AppiumDriver;

    import java.io.File;
    import java.net.URL;
    import java.util.List;

    import org.junit.After;
    import org.junit.Before;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;

    import junit.framework.Test;
    import junit.framework.TestCase;
    import junit.framework.TestSuite;

    /**

    • Unit test for simple App.
      */
      public class Login1Test extends TestCase
      {

      private AppiumDriver driver;
      /**

      • Create the test case *
      • @param testName name of the test case */ public Login1Test( String testName ) { super( testName ); }

    @Before
    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-4.0y--2014-12-11-1851-.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("udid","430072fe4758a07f");
    capabilities.setCapability("deviceName","430072fe4758a07f");
    capabilities.setCapability("platformVersion", "4.3");
    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:4492/wd/hub"), capabilities);

    }

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

    }

    /**
    * @return the suite of tests being tested
    */
    public static Test suite()
    {
    return new TestSuite( Login1Test.class );
    }

    /**
    * Rigourous Test :-)
    * @throws InterruptedException
    */
    @org.junit.Test
    public void testLogin() throws InterruptedException
    {
    List 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);
    }

    @org.junit.Test
    public void testStudentlist() throws InterruptedException

    {
    Thread.sleep(2000);
    WebElement Studentlistbutton = driver.findElement(By.id("air.com.xueersi.ICSClient3:id/menu_student"));
    Studentlistbutton.click();

    }

    }

  • #3 楼 @anikikun 不 quit 的话 是可以结束一个 session 再开启一个 session,可是把应用也结束了,所有流程都得重来一遍啊

  • #7 楼 @test_skp 现在可以在一个类里连续执行多个测试方法了么,求教

  • #8 楼 @mingyuwang 然后在 maven 的 pom.xml 文件中配置测试文件夹路径

    这个怎么配置?

  • #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 不存在

    这个是为什么

  • 问题解决,初始化的时候多加一行
    capabilities.setCapability("udid","430072fe470da099");
    就能指定设备了

  • #18 楼 @sziitash 只有 ios 设备才是 udid 吧 Android 设备就是设备名吧 我用 adb devices 得到的名字 不对么?
    appium 里面要设置端口和 bp 端口么?

  • #16 楼 @sziitash 我一个是 4723 另一个是 4725

  • #12 楼 @sziitash
    以下是官方文档说明

    Parallel Android Tests
    Appium provides a way for users to automate multiple Android sessions on a single machine. All it involves is starting multiple Appium servers with different flags.

    The important flags for automating multiple Android sessions are:

    -p the main Appium port
    -U the device id
    -bp the Appium bootstrap port
    --chromedriver-port the chromedriver port (if using webviews or chrome)
    --selendroid-port the selendroid port (if using selendroid)
    More information on these flags can be found here.

    If we had two devices with the ID’s 43364 and 32456, we would start two different Appium servers with the following commands:

    node . -p 4492 -bp 2251 -U 32456

    node . -p 4491 -bp 2252 -U 43364

    As long as your Appium and Appium bootstrap ports are between 0 and 65536, all they have to be is different so that two Appium servers aren’t trying to listen on the same port. Be sure that your -u flag corresponds with the correct device ID. This is how Appium knows which device to communicate with, so it must be accurate.

    If you are using chromedriver or selendroid, set a different port for each server.

  • #11 楼 @sanlengjingvv 我通过这个启动了 还是不行
    C:\Users\Administrator>appium -p 4492 -bp 2251 -U 430072fe4758a07f
    C:\Users\Administrator>appium -p 4491 -bp 2252 -U 430072fe470da099

    端口我都设置一样了 也是每次都只用一个设备执行 你用 testNG 并行的时候 确实两个机器都跑了?

  • #9 楼 @sanlengjingvv 恩 是没用 关键是连接 2 个设备的时候 怎么才能指定设备?没有办法了么?

    我看官网上有这个命令
    If we had two devices with the ID’s 43364 and 32456, we would start two different Appium servers with the following commands:

    node . -p 4492 -bp 2251 -U 32456

    node . -p 4491 -bp 2252 -U 43364

    可是我执行的时候提示我

    C:\Users\Administrator>node . -p 4492 -bp 2251 -U 32456

    module.js:340
    throw err;
    ^
    Error: Cannot find module 'C:\Users\Administrator'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

  • #7 楼 @sanlengjingvv
    我是 Android 设备 应该设置名字就行了吧
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName","430072fe4758a07f");
    capabilities.setCapability("platformVersion", "4.3");

    每个类我都指定了设备 可还是发现 2 个 执行用例只用一个

  • 我现在能跑两个类了,但是为什么只能发现一个设备?

  • #2 楼 @sanlengjingvv udid 是啥?

  • #3 楼 @yangyajie_002 你看我代码里也指定了啊 我也是启动了两个 appium 都设置过了
    每次还是都只能发现一个设备

  • #6 楼 @frankqian 具体怎么操作呢?
    是启动 2 个 appium 然后指定端口么?我设置了不同的端口 为什么每次还是只执行一个设备

  • 很好 我昨天 java 中也实现了中文输入
    decode 那个暂时没用 没报错 有需要的时候再用吧