把代码修改如下,使用AndroidDriver而非原来的AppiumDriver
参考修改的文章:http://blog.csdn.net/zhubaitian/article/details/39717889
修改以后还是有错误,麻烦大家帮忙看一下代码,谢谢各位
public class MyClass {
private AndroidDriver driver;
@Before
public void setUp() throws Exception {
//设置apk的路径
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps");
File app = new File(appDir, "ContactManager.apk");
//设置自动化相关参数
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android");
//设置安卓系统版本
//capabilities.setCapability("platformVersion", "4.3");
//设置apk路径
//capabilities.setCapability("app", app.getAbsolutePath());
//设置app的主包名和主类名
capabilities.setCapability("appPackage", "com.example.android.ContactManager");
capabilities.setCapability("appActivity", ".ContactManager");
//初始化
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub,capabilities"));
}
@Test
public void addContact(){
WebElement el =driver.findElement(By.name("Add Contact"));
el.click();
List textFieldsList =driver.findElementsByName("android");
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.swipe(100, 500, 100, 100, 2);
driver.findElementByName("Save").click();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}