Appium总结
运行case前,最好在case前加入等待,以免activity还未关闭,就开始定位或其他操作(如果case总报错,则考虑此问题);
swipe效果:
Thread.sleep(2000);
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
driver.swipe(width * 3 / 4, height / 2, width / 4, height / 2, 500);
Thread.sleep(1000);
driver.swipe(width * 3 / 4, height / 2, width / 4, height / 2, 500);
实现输入中文的方法:
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");
xpath定位:
//相对定位
WebElement el = driver.findElement(By.xpath("//android.support.v7.widget.RecyclerView/child::android.widget.RelativeLayout/android.widget.TextView[1]"));
//绝对定位
WebElement element = driver.findElement(By.xpath("//android.widget.ImageButton[contains(@content-desc,'转到上一层级')]"));
//相对定位
WebElement element1 = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'热门推荐')]/parent::android.widget.RelativeLayout/following-sibling::android.widget.FrameLayout[1]/"
+ "android.widget.RelativeLayout/child::android.widget.TextView[3]"));
自动化测试时,可以录制测试视频且保存在手机设备:
Runtime rt = Runtime.getRuntime();
// this code for record the screen of your device
rt.exec("cmd /C adb shell screenrecord /sdcard/test2.mp4");