Selendroid test-app的實例總結

準備工作

安裝java,設置java_home環境變量

設置android_home環境變量

由於我沒有注意pom.xml,導致很久才搞定這個問題

1. pom.xml文件裏需要有:

   
    <dependency>
    <groupId>io.selendroid</groupId>
    <artifactId>android-driver-app</artifactId> // A built in Android driver, Web View app to test the mobile web.
    <version>0.16.0</version>
</dependency>


    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-java</artifactId>

                                                                  //The Java client library based on Selenium. This library should be installed on the computer (which is used to develop the test cases)
              <version>2.47.1</version>
    </dependency>


       <dependency >
     <groupId >io.selendroid </groupId >
         <version >0.16.0</version >
         <artifactId >Selendroid-standalone</artifactId >

                                                               //This component is used to install the Selendroid server and the application under test (AUT)

     </dependency >
    
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-server</artifactId>

                                                    //The server which runs be in the app under test on Android device or simulator. This is the main components of Selendroid architecture
              <version>2.47.1</version>
    </dependency>


    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-client</artifactId>
              <version>0.16.0</version>
    </dependency>


2.  需要啓動selenium-standalone-server

具體命令:

java -jar path\selendroid-standalone-0.16.0-with-dependencies.jar -app xx\selendroid-test-app-0.16.0.apk

啓動成功後,在瀏覽器中輸入: http://localhost:4444/wd/hub/status

Console output

============================

{"value":
{"os":
  {"name":"Windows 7","arch":"amd64","version":"6.1"},"build":{"browserName":"selendroid","version":"0.16.0"},
"supportedDevices":[{"emulator":true,"screenSize":"(768, 1280)","avdName":"00","platformVersion":"19","apiTargetType":"android"},
{"emulator":true,"screenSize":"(800, 1280)","avdName":"11","platformVersion":"19","apiTargetType":"android"},
{"emulator":true,"screenSize":"(768, 1280)","avdName":"test","platformVersion":"19","apiTargetType":"android"}],
"supportedApps":[{"mainActivity":"io.selendroid.testapp.HomeScreenActivity","appId":"io.selendroid.testapp:0.16.0","basePackage":"io.selendroid.testapp"},
{"mainActivity":"io.selendroid.androiddriver.WebViewActivity","appId":"io.selendroid.androiddriver:0.16.0","basePackage":"io.selendroid.androiddriver"}]},
"status":0}
=================

3.  JAVA代碼可以參考

    @Test
    public void test01() throws Exception{
        SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.16.0");  //這裏填寫appId
        
        capa.setPlatformVersion(DeviceTargetPlatform.ANDROID19);
        capa.setEmulator(true);
        
        SelendroidDriver sd = new SelendroidDriver(capa);
        
        WebElement inputField = sd.findElement(By.id("my_text_field"));
        inputField.sendKeys("Selendroid");
        
        Assert.assertEquals("Selendroid", inputField.getText());
        sd.quit();
    }

參考文章

http://selendroid.io/setup.html

http://www.guru99.com/introduction-to-selendroid.html


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章