appium部分api

來源:互聯網
上載者:User

標籤:

 

轉自:http://www.aichengxu.com/view/41510

 

使用的語言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建議多參考java-client-2.1.0-javadoc。

1.使用AndroidDriver,其已經繼承了AppiumDriver

 

        private AndroidDriver driver;@Beforepublic 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);}@Afterpublic 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.

                //安裝APPdriver.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);

appium部分api

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.