准备工作
安装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