When I used UiAutomator to test, I encapsulated many methods. As I did not share these methods in the previous article, it was not easy to read. Originally planned to finish the image recognition and auxiliary classes in the share, in view of the resignation, the UI will not update the code for a long time, so I shared all the encapsulation methods. Some of them are outdated and temporarily useless and you can ignore them.

The following is a wrapper around the basic UiAutomator methods, as well as a wrapper around the basic UiAutomator methods used in test report generation, and some helper classes that I’ll sort out and send out later.

package source; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Random; import com.android.uiautomator.core.Configurator; import com.android.uiautomator.core.UiDevice; import com.android.uiautomator.core.UiObject; import com.android.uiautomator.core.UiObjectNotFoundException; import com.android.uiautomator.core.UiScrollable; import com.android.uiautomator.core.UiSelector; import com.android.uiautomator.testrunner.UiAutomatorTestCase; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Point; import android.graphics.Rect; import android.graphics.Bitmap.CompressFormat; import android.os.RemoteException; import android.view.KeyEvent; import jp.jun_nama.test.utf7ime.helper.Utf7ImeHelper; /** * @author ··-· Chen * @e-mail :[email protected] * @version Created time: August 18, 2017 10:53:24 * @alter time: * Class Description: Basic API package */ @SuppressWarnings("deprecation")
public class UiaLibrary extends UiAutomatorTestCase{
	public String LINE = "\r\n";
//	public static UiaLibrary library = null;
//	public static UiaLibrary getInstance() {
//		library = new UiaLibrary();
//		return library;
//	}
	public void swipeLeft() {// left slider int y = uidevice.getInstance ().getDisplayHeight(); int x = UiDevice.getInstance().getDisplayWidth(); UiDevice.getInstance().swipe(x-100, y/2, 100, y/2, 20); sleep(150); } public voidswipeRight() {// right slider int y = uidevice.getInstance ().getDisplayHeight(); int x = UiDevice.getInstance().getDisplayWidth(); UiDevice.getInstance().swipe(100, y/2, x-100, y/2, 20); sleep(150); } public voidswipeDown() {// slide int y = uidevice.getInstance ().getDisplayHeight(); int x = UiDevice.getInstance().getDisplayWidth(); UiDevice.getInstance().swipe(x/2, 200, x/2, y-200, 20); sleep(150); } public voidswipeUp() {// slide up int y = UiDevice.getInstance().getDisplayHeight(); int x = UiDevice.getInstance().getDisplayWidth(); UiDevice.getInstance().swipe(x/2, y-200, x/2, 200, 20); sleep(150); } public voidswipUpLittle() {// scroll up a little bit int x = uidevice.getInstance ().getDisplayWidth()/2; int y = UiDevice.getInstance().getDisplayHeight()/2; UiDevice.getInstance().swipe(x, y+150, x, y-150, 20); sleep(150); } public voidswipDownLittle() {// drop down a bit int x = uidevice.getInstance ().getDisplayWidth()/2; int y = UiDevice.getInstance().getDisplayHeight()/2; UiDevice.getInstance().swipe(x, y-150, x, y+150, 20); sleep(150); } public StringgetNowDate time = new Date(); SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String c = now.format(time);
		return c;
		}
	public void screenShot() {name+time String name = getName(); File file = new File("/mnt/sdcard/123/");
		if(! file.exists()) { file.mkdirs(); } File files = new File(file.toString()+"/"+getDayHourMinute()+name+".png");
	    UiDevice.getInstance().takeScreenshot(files);
	    output("Screenshot success by default!"); } public void compressPictureToJpeg(String oldPath, File newFile) throws FileNotFoundException { Bitmap bitmap = BitmapFactory.decodeFile(oldPath); FileOutputStream out = new FileOutputStream(newFile); // Create file output stream bitmap.press (compressformat.jpeg, 100, out); / / jpeg images can be converted to a control's image output} / / public Bitmap getBitmapByResourceId (String id) throws UiObjectNotFoundException {the Rect rect = getUiObjectByResourceId(id).getVisibleBounds(); // Get a rect object from the control String path = screenShot("test"); Bitmap = bitmapFactory.decodefile (path); Bitmap = bitmap.createBitmap (bitmap, rect.left, rect.top, rect.width(), rect.height())); // Capture a Bitmap instancereturnbitmap; } public int getColorPixel(int x, int y) {screenShot(screenShot)"test"); // Screenshot String path ="/mnt/sdcard/123/test.png"; Bitmap bitmap = BitmapFactory.decodeFile(path); Int color = bitmap.getPixel(x, y); // output(color); // Outputs the color valuereturn color;
	}
	public int getRedPixel(int x, int y) {
		screenShot("test"); // Screenshot String path ="/mnt/sdcard/123/test.png"; Bitmap bitmap = BitmapFactory.decodeFile(path); Int color = bitmap.getPixel(x, y); // output(color); Int red = color.red (Color);return red;
	}
	public int getGreenPixel(int x, int y) {
		screenShot("test"); // Screenshot String path ="/mnt/sdcard/123/test.png"; Bitmap bitmap = BitmapFactory.decodeFile(path); Int color = bitmap.getPixel(x, y); // output(color); Int green = color.green (Color);return green;
	}
	public int getBluePixel(int x, int y) {
		screenShot("test"); // Screenshot String path ="/mnt/sdcard/123/test.png"; Bitmap bitmap = BitmapFactory.decodeFile(path); Int color = bitmap.getPixel(x, y); // output(color); // Output Color value int blue = color.blue (Color);return blue;
	}
	public int[] getRGBcolorPixel(int x, int y) {
		screenShot("testDemo");
		String path = "/mnt/sdcard/123/testDemo.png";
		Bitmap bitmap = BitmapFactory.decodeFile(path);
		int color = bitmap.getPixel(x, y);
		int red = Color.red(color);
		int green = Color.green(color);
		int blue = Color.blue(color);
		int[] rgb = {red, green, blue};
		returnrgb; } / / according to color judgment state public Boolean isBlue (UiObject UiObject) throws UiObjectNotFoundException {screenShot ("test"); // Screenshot String path ="/mnt/sdcard/123/test.png"; Bitmap bitmap = BitmapFactory.decodeFile(path); / / create and instantiate the Rect bitmap object. The Rect = uiObject getVisibleBounds (); int x = rect.left; int xx = rect.right; int y = rect.top; int yy = rect.bottom; List<Integer> blueColor = new ArrayList<Integer>();for (int i = x; i < xx; i++) {
			for(int k = y; k < yy; k++) { int color = bitmap.getPixel(i, k); Int red = color.blue (Color); blueColor.add(red); } } int sum = 0;for(int i = 0; i<blueColor.size(); i++) { sum += blueColor.get(i); } // output(sum/blueColor.size());return sum/blueColor.size() > 200?true:false; } public Boolean comparePicture(String path1, String path2, double);} public Boolean comparePicture(String path1, String path2, doublelimit) { Bitmap bitmap1 = BitmapFactory.decodeFile(path1); Bitmap2 = bitmapFactory.decodefile (path2); Int width = bitmap1.getwidth (); Int height = bitmap1.getheight (); Int total = 0; // count the same number inttimes= 0; // Count the total number of times // traverse the color value of pixel points, save time increment by 5 pixels each timefor(int x = 0; x < width; x +=3) {for(int y = 0; y < height; y +=3) { int oldPic = bitmap1.getPixel(x, y); Int newPic = bitmap2.getPixel(x, y); // int differ = math.abs (ss-dd); // Calculate the absolute differencetimes+ +;if(oldPic == newPic) {// if = total++; }}} double differ = total*1.0/times;
		output(differ);
		returnDiffer > 0.99?true:false; Public double getVideoProgress(Bitmap Bitmap) {int height = bitmap.getheight (); int width = bitmap.getWidth(); List<Integer> date = new ArrayList<Integer>();for(int i = 0; i < width; i++) { int color = bitmap.getPixel(i, height / 2); int red = Color.red(color); // output(red); date.add(red); } int date1 = 0,date2 = 0,date3 = 0,date4 = 0; int status1 = 0,status2 = 0;for(int i = 1; i < date.size() - 1; i++) {if (date.get(i) == 255 && status1 == 0) {
				status1++;
				date1 = i;
			}
			if (date.get(i) == 238 && status2 == 0) {
				status2++;
				date2 = i;
			}
			if (date.get(i + 1) < 238 && date.get(i) == 238) {
				date3 = i;
			}
			if(date.get(i + 1) < 165 && date.get(i) == 165) { date4 = i; } } // output(date1, date2, date3, date4); // output((date2 + date3-date1 * 2.00)/(date4-date1)/2); // Output ((date2 + date3-date1 * 2.00)/(date4-date1)/2);return(date2 + date3-date1 * 2.00)/(date4-date1)/2; } public StringgetDayHourMinute() {// get Date hour minute Date time = new Date(); SimpleDateFormat format = new SimpleDateFormat("dd-HH-mm");
		String name = format.format(time);
		return name;
	}
	public String screenShot(String name) {//截图并命名
		File file = new File("/mnt/sdcard/123/");
		if(! file.exists()) { file.mkdirs(); } File files = new File("/mnt/sdcard/123/"+name+".png");
	    UiDevice.getInstance().takeScreenshot(files);
	    output(name + ".png screenshot successful!");
	    String path = "/mnt/sdcard/123/" + name + ".png";
	    return path;
	    }
	public String screenShot(int num) {//截图并命名
		File file = new File("/mnt/sdcard/123/");
		if(! file.exists()) { file.mkdirs(); } File files = new File("/mnt/sdcard/123/"+num+".png");
	    UiDevice.getInstance().takeScreenshot(files);
	    output(num + ".png screenshot successful!");
	    String path = "/mnt/sdcard/123/" + num + ".png";
	    returnpath; } public void circle(int x, int y, int r) {double d = (double) (math.pi /30); // Angle double[] XXX = new double[61];for(int i=0; i<61; i++){ xxx[i]=Math.cos(i*d); } double[] yyy = new double[61];for(int i=1; i<61; i++){ yyy[i]=Math.sin(i*d); Int [] xxx1 = new int[61];for(int i=0; i<61; i++){ xxx1[i]=(int) (xxx[i]*200); } int[] yyy1 = new int[61];for(int i=0; i<61; i++){ yyy1[i]=(int) (yyy[i]*200); } Point[] p = new Point[61];for(int i=0; i<61; i++){ p[i]=new Point(); p[i].x = xxx1[i]+x; p[i].y = y-yyy1[i]+50; } // Create a group of points uidevice.getinstance ().swipe(p, 2); } public void heart(int x, int y,int r) {double d = (double) (math.pi /30); double[] angle = new double[61]; // Set the Angle differencefor(int i=0; i<61; i++){ angle[i]=i*d; Double [] ox = new double[61];for(int i=0; i<61; i++){ ox[i]= r*(2*Math.cos(angle[i])-Math.cos(2*angle[i])); } double[] double = new double[61];for(int i=0; i<61; i++){ oy[i]=r*(2*Math.sin(angle[i])-Math.sin(2*angle[i])); } Point[] heart = new Point[61];for(int i=0; i<61; i++){ heart[i] = new Point(); heart[i].x = (int) oy[i]+x; heart[i].y = -(int) ox[i]+y; } // Create a set of indexes. uidevice.getinstance ().swipe(heart, 2); } public UiObject getUiObjectByText(String text) {// Get control by textreturn new UiObject(new UiSelector().text(text));
	}
	public UiObject getUiObjectByTextContains(String text) {
		returnnew UiObject(new UiSelector().textContains(text)); } public UiObject getUiObjectByStartText(String text) {return new UiObject(new UiSelector().textStartsWith(text));
	}
	public UiObject getUiObjectByStartDesc(String desc) {
		returnnew UiObject(new UiSelector().descriptionStartsWith(desc)); } public UiObject getUiObjectByTextClassName (String text, the String classname) {/ / through the text and the name of the class access controlreturnnew UiObject(new UiSelector().text(text).className(classname)); } public UiObject getUiObjectByTextResourceId (String text, the String id) {/ / through the text and id access objectreturn new UiObject(new UiSelector().text(text).resourceId(id));
	}
	public UiObject getUiObjectByResourceIdClassName(String id, String type) {
		return new UiObject(new UiSelector().resourceId(id).className(type)); } public UiObject getUiObjectByResourceId(String id) {// Get the control by the resource IDreturnnew UiObject(new UiSelector().resourceId(id)); } public UiObject getUiObjectByDesc(String desc) {// Get control by descreturn new UiObject(new UiSelector().description(desc));
	}
	public UiObject getUiObjectByStartDescContains(String desc) {
		return new UiObject(new UiSelector().descriptionContains(desc));
	}
	public UiObject getUiObjectByDescContains(String desc) {
		return new UiObject(new UiSelector().descriptionContains(desc));
	}
	public UiObject getUiObjectByClassName(String type{// Get the control by classnamereturn new UiObject(new UiSelector().className(type)); } public UiObject getUiObjectByResourceIdIntance (String id, int the instance) {/ / by id and the instance access controlsreturnnew UiObject(new UiSelector().resourceId(id).instance(instance)); } / / long press controls public void longclickUiObectByResourceId (String id) throws UiObjectNotFoundException {int x = getUiObjectByResourceId(id).getBounds().centerX(); int y = getUiObjectByResourceId(id).getBounds().centerY(); UiDevice.getInstance().swipe(x, y, x, y, 300); / / the last parameter unit is 5 ms} public void longclickUiObectByDesc (String desc) throws UiObjectNotFoundException {int x = getUiObjectByDesc(desc).getBounds().centerX(); int y = getUiObjectByDesc(desc).getBounds().centerY(); UiDevice.getInstance().swipe(x, y, x, y, 300); / / the last parameter unit is 5 ms} public void longclickUiObectByText (String text) throws UiObjectNotFoundException {int x = getUiObjectByText(text).getBounds().centerX(); int y = getUiObjectByText(text).getBounds().centerY(); UiDevice.getInstance().swipe(x, y, x, y, 300); // The last argument is in 5ms} // Click center public voidclickCenter() { int x = UiDevice.getInstance().getDisplayWidth(); int y = UiDevice.getInstance().getDisplayHeight(); clickPiont(x/2, y/2); } public void writeText (String text) throws UiObjectNotFoundException {/ / input text getUiObjectByClassName ("android.widget.EditText").setText(Utf7ImeHelper.e(text));
	}
	public UiScrollable getUiScrollabe() {// Get the scroll controlreturn new UiScrollable(new UiSelector().scrollable(true)); } public UiScrollable getUiScrollableByResourceId (String id) {/ / to get rollingreturn new UiScrollable(new UiSelector().scrollable(true).resourceId(id));
	}
	public void getChildByTextOfUiScrollableByClassName(String type, String text) throws UiObjectNotFoundException {
		getScrollableByClassName(type).getChildByText(new UiSelector().text(text), text).clickAndWaitForNewWindow(); } public UiObject getUiObjectByResourIdIndex (String id, int index) {/ / by id and index access controlsreturn new UiObject(new UiSelector().resourceId(id).index(index));
	}
	public void randomClickOpiton() throws UiObjectNotFoundException {
		int num = getUiObjectByClassName("android.widget.ListView").getChildCount();
		int i = new Random().nextInt(num);
		getUiObjectByResourceIdIntance("com.gaotu100.superclass:id/simpleitemview_left_text", i).clickAndWaitForNewWindow();
	}
	public void outputBegin() {// The output starts system.out.println (getNow()+".. -.... - Action!");
	}
	public void outputNowSystem.out.println(getNow())); } public voidoutputOverPrintln (getNow()+) {// End system.out.println (getNow()+".. -.... - Over!"); } // public void output(String text) {// system.out.println (text); // public void output(double num) {// system.out.println (num); Public void output(int num) {// system.out.println (system.out.println)"= = = ="+num+"= = = ="); Public void output(String text) {system.out.println (text); } public void output(String ... Text) {// Method overloadfor (int i = 0; i < text.length; i++) {
			System.out.println("The first"+ (i+1) + "个:"+ text[i]); } } public void output(long num) { System.out.println(num); } public void output(long ... Num) {// Method overloadfor (int i = 0; i < num.length; i++) {
			System.out.println("The first"+ (i+1) + "个:"+ num[i]); } } public void output(double num) { System.out.println(num); } public void output(double ... Num) {// Method overloadfor (int i = 0; i < num.length; i++) {
			System.out.println("The first"+ (i+1) + "个:"+ num[i]); } } public void output(int num) { System.out.println(num); } public void output(int ... Num) {// Method overloadfor (int i = 0; i < num.length; i++) {
			System.out.println("The first"+ (i+1) + "个:"+ num[i]); } } public void outpu(Object ... object) {for (int i = 0; i < object.length; i++) {
			System.out.println("The first"+ (i+1) + "个:"+ object[i]);
		}
	}
	public void outpu(Object object) {
		System.out.println(object.toString());
	}
	public void pressTimes(int keyCode, int times) {// Press the same key multiple timesfor(int i=0; i<times; i++){ sleep(200); UiDevice.getInstance().pressKeyCode(keyCode); } } public voidwaitForUiObjectByText(String text) {Date start = new Date(); // boolean key =true;
//		while(key){
//			sleep(200);
//			UiObject it = new UiObject(new UiSelector().text(text));
//			if (it.exists()) {
//				key = false;
//			}
//			Date end = new Date();
//			long time = end.getTime() - start.getTime();
//			if (time>10000) {
//				output("No more than 10 seconds!");
//				key = false;
//			}
//		}
		getUiObjectByText(text).waitForExists(10000);
	}
	public void waitForUiObjectByStartText(String text) { getUiObjectByStartText(text).waitForExists(10000); } public void outputTimeDiffer(Date start, Date end) {long time = end.getTime() - start.gettime (); double differ = (double)time/1000; output("Total time"+differ+"Second!"); } / / for child controls click public void getScrollChildByText (String text) throws UiObjectNotFoundException {UiObject child = getUiScrollabe().getChildByText(new UiSelector().text(text), text); child.clickAndWaitForNewWindow(); } public UiScrollable getScrollableByClassName public UiScrollable getScrollableByClassName(Stringtype) {
		return new UiScrollable(new UiSelector().scrollable(true).className(type));
	}
	public void waitForUiObjectByClassName(String type) throws UiObjectNotFoundException {/ / for control getUiObjectByClassName (type).waitForExists(10000);
	}
	public void waitForUiObjectByTextContains (String text) {/ / for object / / Date start = new Date (); // boolean key =true;
//		while(key){
//			sleep(1000);
//			UiObject it = new UiObject(new UiSelector().textContains(text));
//			if (it.exists()) {
//				key = false;
//			}
//			Date end = new Date();
//			long time = end.getTime() - start.getTime();
//			if (time>10000) {
//				output("No more than 10 seconds!");
//				key = false;
//			}
//		}
		getUiObjectByText(text).waitForExists(10000);
	}
	public void waitForUiObjectByDesc(String desc) {Date start = new Date(); // boolean key =true;
//		while(key){
//			sleep(1000);
//			UiObject it = new UiObject(new UiSelector().description(desc));
//			if (it.exists()) {
//				key = false;
//			}
//			Date end = new Date();
//			long time = end.getTime() - start.getTime();
//			if (time>10000) {
//				output("No more than 10 seconds!");
//				key = false;
//			}
//		}
		getUiObjectByDesc(desc).waitForExists(10000);
	}
	public void waitForUiObjectByResourceId(String id) {Date start = new Date(); // boolean key =true;
//		while(key){
//			sleep(1000);
//			UiObject it = new UiObject(new UiSelector().resourceId(id));
//			if (it.exists()) {
//				key = false;
//			}
//			Date end = new Date();
//			long time = end.getTime() - start.getTime();
//			if (time>10000) {
//				output("No more than 10 seconds!");
//				key = false;
//			}
//		}
		getUiObjectByResourceId(id).waitForExists(10000);
	}
	public void waitForUiObject(UiSelector selector) {Date start = new Date(); // boolean key =true;
//		while(key){
//			sleep(1000);
//			UiObject it = new UiObject(selector);
//			if (it.exists()) {
//				key = false;
//				}
//			Date end = new Date();
//			long time = end.getTime() - start.getTime();
//			if (time>10000) {
//				output("No more than 10 seconds!");
//				key = false;
//				}
//			}
		new UiObject(selector).waitForExists(10000);
		}
	public String getTextByResourceId(String id) throws UiObjectNotFoundException {
		return getUiObjectByResourceId(id).getText();
	}
	public String getDescByResourceI1d(String id) throws UiObjectNotFoundException {
		return getUiObjectByResourceId(id).getContentDescription();
	}
	public String getTextByResourceIdClassName(String id,String type) throws UiObjectNotFoundException {
		return getUiObjectByResourceIdClassName(id, type).getText(); } / public/brother controls for text String getTextByBrother (String myid, String brotherid) throws UiObjectNotFoundException {returngetUiObjectByResourceId(myid).getFromParent(new UiSelector().resourceId(brotherid)).getText(); } public void writeTextByResourceId(String id, String text) throws UiObjectNotFoundException { getUiObjectByResourceId(id).setText(Utf7ImeHelper.e(text)); } public void clickPiont(int x, int y) {uidevice.getInstance ().click(x, y); } public void getUiObjectByResoureIdAndclickRightHalf (String id) throws UiObjectNotFoundException {/ size/access controls the Rect SSS = getUiObjectByResourceId(id).getBounds(); // Calculate center offset clickPiont(ss.centerx ()+ ss.width()/4, ss.centery ()); } / / click on the left side control public void getUiObjectByResoureIdAndclickLeftHalf (String id) throws UiObjectNotFoundException {/ / access control size Rect sss = getUiObjectByResourceId(id).getBounds(); // Calculate center offset clickPiont(ss.centerx () -ss.width ()/4, ss.centery ()); } public voidsetShort() {/ / set the short wait Configurator. GetInstance () setActionAcknowledgmentTimeout (500); } public voidsetFast() {/ / set the short wait Configurator. GetInstance () setActionAcknowledgmentTimeout (100); } public voidsetLong() {/ / set the long wait Configurator. GetInstance () setActionAcknowledgmentTimeout (1500); } / / clear text in Chinese public void clearTextByResourceId (String id) throws UiObjectNotFoundException {String name = getUiObjectByResourceId(id).getText(); // output(name.length()); UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_MOVE_END); // UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_MOVE_HOME); // If the cursor is at the end pressTimes(keyevent.keycode_del, name.length()); // pressTimes(keyevent.keycode_forward_del, name.length()); // pressTimes(keyevent.keycode_forward_del, name.length()); } public int changeStringToInt (string text) {//return Integer.parseInt(text);
		returnInteger.valueOf(text); } // Wait for the text control and click public voidwaitForClassNameAndClick(String type) throws UiObjectNotFoundException {
		waitForUiObjectByClassName(type);
//		getUiObjectByText(type).waitForExists(10000);
		getUiObjectByClassName(type).clickAndWaitForNewWindow();	
	}
	public void waitForTextAndClick(String text) throws UiObjectNotFoundException {
		waitForUiObjectByText(text); // getUiObjectByText(text).waitForExists(10000); getUiObjectByText(text).clickAndWaitForNewWindow(); } // Find the control by the start text and hit public voidwaitForStartTextAndClick(String text) throws UiObjectNotFoundException {
		getUiObjectByStartText(text).waitForExists(10000);
		getUiObjectByStartText(text).clickAndWaitForNewWindow();
	}
	public void waitForTextContainsAndClick(String text) throws UiObjectNotFoundException {
		getUiObjectByTextContains(text).waitForExists(10000);
		getUiObjectByTextContains(text).clickAndWaitForNewWindow();
	}
	public void waitForStartDescAndClick(String desc) throws UiObjectNotFoundException {
		getUiObjectByStartDesc(desc).waitForExists(10000);
		getUiObjectByStartDesc(desc).clickAndWaitForNewWindow();
	}
	public void waitForDescContainsAndClick(String desc) throws UiObjectNotFoundException { getUiObjectByDescContains(desc).waitForExists(10000); getUiObjectByDescContains(desc).clickAndWaitForNewWindow(); } // Wait for the resource ID and hit public voidwaitForResourceIdAndClick(String id) throws UiObjectNotFoundException {
		waitForUiObjectByResourceId(id); // getUiObjectByResourceId(id).waitForExists(10000); getUiObjectByResourceId(id).clickAndWaitForNewWindow(); } // Wait for desc and click public voidwaitForDescAndClick(String desc) throws UiObjectNotFoundException {
		waitForUiObjectByDesc(desc); getUiObjectByDesc(desc).clickAndWaitForNewWindow(); Public void startClassApp() throws IOException, InterruptedException {Runtime.geTruntime ().exec("am start -n com.gaotu100.superclass/.activity.main.SplashActivity").waitFor();
	}
	public void startWechat() throws IOException, InterruptedException {
		Runtime.getRuntime().exec("am start -n com.tencent.mm/.ui.LauncherUI").waitFor(); Public void stopClassApp() throws InterruptedException, IOException {sleep(500); Runtime.getRuntime().exec("am force-stop com.gaotu100.superclass").waitFor(); sleep(500); Public void stopAlertover() throws InterruptedException, IOException {Runtime.geTruntime ().exec()"am force-stop com.alertover.app").waitFor(); sleep(500); } // Disable alertover public void startAlertover() throws IOException, InterruptedException {sleep(500); Runtime.getRuntime().exec("am start -n com.alertover.app/.activity.LoginActivity").waitFor(); Public void closeOrOpenWifi() throws InterruptedException, IOException {runtime.geTruntime ().exec("am start -n run.wifibutton/.WifiButtonActivity").waitFor(); sleep(1000); Public void stopWechat() throws InterruptedException, IOException {sleep(500); Runtime.getRuntime().exec("am force-stop com.tencent.mm").waitFor(); Thread.sleep(500); Public void stopAlipay() throws InterruptedException, IOException {runtime.getruntime ().exec()"am force-stop com.eg.android.AlipayGphone").waitFor(); Thread.sleep(500); Public void startWishApp() throws IOException {runtime.getruntime ().exec()"am start -n com.chaojizhiyuan.superwish/.activity.main.SplashActivity"); } // Disable APP public void stopWishApp() throws InterruptedException, IOException {sleep(500); Runtime.getRuntime().exec("am force-stop com.chaojizhiyuan.superwish").waitFor(); sleep(500); } public int getRandomInt(int num) {returnnew Random().nextInt(num); } // Verify the jump to alipay public voidverifySkipAlipay() {
		waitForUiObjectByText("Add card payment");
		String packagename = UiDevice.getInstance().getCurrentPackageName();
		assertEquals("Jump pay treasure failure!"."com.eg.android.AlipayGphone", packagename); } // Verify the jump to alipay public voidverifySkipWechat() {
		waitForUiObjectByText("Pay with small change");
		String packagename = UiDevice.getInstance().getCurrentPackageName();
		assertEquals("Jump to wechat failed!"."com.tencent.mm", packagename); Public void warningTester() throws RemoteException {uidevice.getInstance ().sleep(); / / out the screen to sleep (1200); / / sleepif(UiDevice.getInstance().isScreenon ()) {// Get the screen statusreturn; // Stop running if the screen is on}else{ UiDevice.getInstance().wakeUp(); // If the screen is off, rerun the method warningTester(); / / rolling forward recursion}} / / public Boolean scrollForward () throws UiObjectNotFoundException {returngetUiScrollabe().scrollForward(50); } / / rolling back public Boolean scrollBackward () throws UiObjectNotFoundException {return getUiScrollabe().scrollBackward(50);
	}
	public void deleteScreenShot() {// delete screenshot File File = new File("/mnt/sdcard/123/");
		if(file.exists()) {// If file exists file [] files = file.listfiles (); // Get the list of files under the folderfor(int i = 0; i < files.length; I ++) {// delete files[I].delete(); } file.delete(); // Delete the folder last, if there is no folder to delete directly}else {
			output("Folder does not exist!"); }}}Copy the code

Selected articles from previous issues

  1. Java one line of code to print a heart
  2. Linux performance monitoring software Netdata Chinese version
  3. Interface Test Code Coverage (JACOCO) solution sharing
  4. Performance testing framework
  5. How to perform performance tests on a Linux command line interface
  6. Graphic HTTP brain map
  7. Programming thinking for everyone
  8. Format the JSON data for output to the console
  9. How do I test a probabilistic business interface
  10. Automatically turn the Swagger document into test code
  11. Mac+ HttpClient high concurrency configuration example
  12. Httpclient handles multiple online users simultaneously

Map of official Account☢ ️~ FunTester together