Appium实现的技巧

截图功能:

            //截屏并保存至本地
            File screen = driver.getScreenshotAs(OutputType.FILE);
            File screenFile = new File("d:\\screen.png");

            FileUtils.copyFile(screen, screenFile); //commons-io-2.0.1.jar中的api


push文件、pull文件

        	File file = new File("d:\\test.txt"); //test.txt内容为"test"
		String content = null;
		try {
			content = FileUtils.readFileToString(file);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		byte[] data = Base64.encodeBase64(content.getBytes());
		driver.pushFile("sdcard/test.txt", data);
		
		byte[] resultDate = driver.pullFile("sdcard/test.txt");
		System.out.println(new String(Base64.decodeBase64(resultDate))); //打印结果为"test"

发送按键事件
		driver.sendKeyEvent(AndroidKeyCode.HOME);
tap点击元素
		driver.tap(1, driver.findElementByName("日期和时间"), 0);

单击坐标

               如果怎么都定位不到控件,那就可以考虑坐标定位               

               driver.swipe(1257, 2263, 1257, 2263, 5);

          driver. tap(int fingers, int x, int y, int duration) ;



posted @ 2016-06-18 15:16  午夜飘雪789  阅读(185)  评论(0编辑  收藏  举报