????Appium?в???api????÷???????????????????ο????
??????????????java??appium??汾??1.3.4??java-client??汾??java-client-2.1.0???????ο?java-client-2.1.0-javadoc??
????1.???AndroidDriver????????????AppiumDriver
????private AndroidDriver driver;
????@Before
????public void setUp() throws Exception {
????DesiredCapabilities capabilities = new DesiredCapabilities();
????capabilities.setCapability("deviceName"?? "Android Emulator");
????capabilities.setCapability("platformVersion"?? "4.4");
????capabilities.setCapability("platformName"?? "Android");
????capabilities.setCapability("appPackage"?? "com.android.settings");
????capabilities.setCapability("appActivity"?? ".Settings");
????driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub")??
????capabilities);
????}
????@After
????public void tearDown() throws Exception {
????driver.quit();
????}
????2.????????????????
????//????????????????
????File screen = driver.getScreenshotAs(OutputType.FILE);
????File screenFile = new File("d:\screen.png");
????try {
????FileUtils.copyFile(screen?? screenFile); //commons-io-2.0.1.jar?е?api
????} catch (IOException e) {
????e.printStackTrace();
????}
????3.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"
????4.
????//???????????activity???????????????????????activity
????driver.currentActivity();
????5.
????//??????????
????driver.openNotifications();
????6.
????//?????????
????int status = driver.getNetworkConnection().value;
????System.out.println(status);
????//??????????
????driver.setNetworkConnection(new NetworkConnectionSetting(status));
????//????
????driver.setNetworkConnection(new NetworkConnectionSetting(false?? true?? false));
????7.
????//?????????????APP
????driver.startActivity("com.android.camera"?? ".CameraLauncher");
????8.
????//????????б?
????driver.scrollTo("text");
????//????
????driver.scrollToExact("text");
????9.
????//???APP
????driver.installApp(appPath);
????//?ж???????????
????driver.isAppInstalled("package name");
????10.
????//??????????????????λ??
????new TouchAction(driver).longPress(driver.findElementByName("???"))
????.moveTo(driver.findElementByName("????")).release().perform();
????11.
????//????
????driver.lockScreen(2);
????//?ж????????
????driver.isLocked();
????12.
????//??????????
????driver.sendKeyEvent(AndroidKeyCode.HOME);
????13.
????<span style="color:#ff0000;"> </span>
????//???uiautomator??λclickable?????true?????????
????driver.findElementByAndroidUIAutomator("new UiSelector().clickable(true)").click();
????//??????????????List???
????List<WebElement> elements = driver.findElementsByClassName("class name");
????elements.get(0).click(); //???List?е????????
????//tap????????λ??
????driver.tap(1?? driver.findElementByName("????????")?? 0);