1. access to information categories:
1.1 Gets the current interface components:
driver.currentActivity (); // get the current activity interface that can be used to jump to say whether the expected activity
1.2 Get tree source of current page
driver.pagesource (); // get a tree view of the current page
2.App install and uninstall the associated class API
Determining whether the installation 2.1 APP
driver.isAppInstalled ( "package name"); // determine whether the application has been installed
driver.installApp (appPath); // mounting APP
driver.removeApp (StringbundleId); // unload package, Android is the package name, IOS is bundleId
driver.closeApp (); // close the application, press and hold the Home key to application retreated backstage
driver.launchApp (); // start the application
driver.resetApp(); //先close再launch
2.2 launch other applications:
driver.startActivity("com.android.camera", ".CameraLauncher");
3. Set the relevant categories:
3.1 get and set network status
int status = driver.getNetworkConnection () value;. // acquired network state
System.out.println(status);
driver.setNetworkConnection (new NetworkConnectionSetting (status)); // set up the network status
//or
driver.setNetworkConnection(new NetworkConnectionSetting(false, true, false));
4. The file operation categories:
4.1.push file, pull files
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))); // print the results as "test"
5. Gets the control type (multiple elements just to get into findElements findElement can):
5.1 target element by element id find current page:
driver.findElementById ( "id"); // id by targeting elements
5.2 find the target elements of the current page element by name:
driver.findElementByClassName ( "classname"); // name by targeting elements
5.3 find the target elements of the current page by elemental Xpath:
driver.findElementByXpath ( "xpath"); // positioned by xpath element
5.4 name value by positioning element (i.e. text)
driver.findElementByName ( "name"); // value by locating text
5.5 hybrid positioning, by co-locating Xpath and index etc.
Element driver.find_element_by_xpath ( "// android.widget.TextView [contains (@text, 'Library')]") // contains text = "Gallery" in the page to detect all classes android.widget.TextView
6. User Action classes:
6.1 Click event:
1)driver.click();
2) driver.tap (position.duration); // finger click simulation, the length can be set to hold the time (ms)
Such as: driver.tap ([(300,500)], 10)
6.2 Shake the phone
1)driver.shake()
6.3 input events
1)driver.elememt.sendKeys();
2) driver.elememt.sendText ();
Swipe 6.4 (fast moving and flipping):
driver.swipe (startX, startY, endX, endY, during (ms)); // the screen from the screen (startX, startY) to slide (endX, endY) interval during (ms)
driver.flick (startX, startY, endX, endY) // hold the A (startX, startY) to quickly move to point B (endX, endY) point
6.5 Event Scale (similar sports map for test scenarios):
1) driver.pinch (element, percent, steps); // reduction operation performed on the element, and the steps may Percent writing, writing is not expressed when the default
如:driver.pinch(element,150,30)
2) driver.zoom (element, percent, steps); // you zoom in on the element, and the steps may Percent writing, writing is not expressed when the default
Such as: driver.zoom (element, 200,50)
6.6 press event:
1)driver.longPress();
6.7 Keyevent event
driver.keyevent ( "4") # Returns the key operation
6.8 opening and closing operation:
driver.close () // Close the current window
driver.quit () // exit the script and close the window associated with each connection
6.9 acquisition window height and width
driver.manage().window().getSize().width;
driver.manage().window().getSize().height;
7. Wait Wait Class;
7.1 sleep method:
Thread.sleep (60000) forced to wait 60s // forced to wait 60s
7.2 implicitlyWait method
. Driver.manage () timeouts () implicitlyWait (30, TimeUnit.SECONDS);. // implicit waiting, waiting for the global 30S regardless of whether the element is already loaded u
7.3 WebDriverWait process (a display waiting, the need to increase certain waiting time, and can be determined by WebDriverWait util)
7.4 waitActivity method (implicit waits for an accepts three parameters, Activity name, timeout detection time exceeds the time interval and (S)):
driver.waitActivity("Activity",timeout(s),during(s));
8.AppiumDriver helper class:
8.1 screenshot and save it locally
public static void ScreenShot(AndroidDriver driver,String ScreenName){
String dir_name = System.getProperty("user.dir")+"\\"+"异常图片";
if(!(new File(dir_name).isDirectory())){
new File(dir_name).mkdir();
}
File screen = driver.getScreenshotAs(OutputType.FILE);
try{
System.out.println ( "abnormal picture save path:" + new File (dir_name));
FileUtils.copyFile(screen, new File(dir_name+"\\"+ScreenName+".jpg"));
}catch(Exception e){
e.printStackTrace ();
}
}
8.2 Open the notification bar interface:
driver.openNotifications();
8.3 lock screen:
driver.lockScreen (2); // lock screen
// determine whether the lock screen
driver.isLocked();
8.4 automatic slide list
driver.scrollTo ( "text"); // automatically scroll list
//or
driver.scrollToExact("text");