Mobile phone Automation test: Appium Source analysis of Bootstrap six

Source: Internet
Author: User
Tags getmessage appium

Poptest is the only training institute for developing Test and development engineers in China, aiming at the ability of the trainees to be competent in automated testing, performance testing and testing tools development. Poptest Test Development Engineer Employment Training please consult qq:908821478) Mobile automation testing is the technical requirements of future Test engineers, we need to lay a good foundation.

Flick

Package Io.appium.android.bootstrap.handler;

Import Com.android.uiautomator.core.UiDevice;

Import io.appium.android.bootstrap.*;

Import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;

Import Io.appium.android.bootstrap.utils.Point;

Import org.json.JSONException;

Import java.util.Hashtable;

/**

* This handler are used to flick elements in the Android UI.

*

* Based on the element Id, flick this element.

*

*/

public class Flick extends CommandHandler {

Private Point Calculateendpoint (final point start, final Integer xspeed,

Final Integer yspeed) {

Final Uidevice D = uidevice.getinstance ();

Final point end = new Point ();

Final double speedRatio = (double) xspeed/yspeed;

Double xOff;

Double Yoff;

Final Double value = Math.min (D.getdisplayheight (), D.getdisplaywidth ());

if (SpeedRatio < 1) {

Yoff = VALUE/4;

XOFF = VALUE/4 * speedRatio;

} else {

XOFF = VALUE/4;

Yoff = VALUE/4/speedRatio;

}

XOFF = Integer.signum (xspeed) * XOFF;

Yoff = Integer.signum (yspeed) * YOFF;

End.X = Start.x + xOff;

End.y = Start.y + Yoff;

return end;

}

/*

* @param command the {@link Androidcommand} used for this handler.

*

* @return {@link Androidcommandresult}

*

* @throws jsonexception

*

* @see Io.appium.android.bootstrap.commandhandler#execute (io.appium.android.

* Bootstrap. Androidcommand)

*/

@Override

Public Androidcommandresult Execute (final androidcommand command)

Throws Jsonexception {

Point start = new Point (0.5, 0.5);

Point end = new Point ();

Double steps;

Final hashtable<string, object> params = Command.params ();

Final Uidevice D = uidevice.getinstance ();

if (Command.iselementcommand ()) {

Androidelement el;

try {

el = Command.getelement ();

Start = El.getabsoluteposition (start);

Final Integer xoffset = (integer) params.get ("Xoffset");

Final Integer yoffset = (integer) params.get ("Yoffset");

Final Integer speed = (integer) params.get ("Speed");

Steps = 1250.0/speed + 1;

End.X = Start.x + xoffset;

End.y = Start.y + yoffset;

} catch (Final Exception e) {

Return Geterrorresult (E.getmessage ());

}

} else {

try {

Final Integer xspeed = (integer) params.get ("XSpeed");

Final Integer yspeed = (integer) params.get ("Yspeed");

Final Double speed = Math.min (1250.0,

MATH.SQRT (xspeed * xspeed + yspeed * yspeed));

Steps = 1250.0/speed + 1;

Start = Getdeviceabspos (start);

End = Calculateendpoint (Start, xspeed, yspeed);

} catch (Final Invalidcoordinatesexception e) {

Return Geterrorresult (E.getmessage ());

}

}

Steps = Math.Abs (steps);

Logger.debug ("flicking from" + start.tostring () + "to" + end.tostring ()

+ "with steps:" + Steps.intvalue ());

Final Boolean res = D.swipe (Start.x.intvalue (), Start.y.intvalue (),

End.x.intvalue (), End.y.intvalue (), Steps.intvalue ());

if (res) {

Return Getsuccessresult (RES);

} else {

Return Geterrorresult ("Flick did not complete successfully");

}

}

}

The code steps are similar to swipe, and the final call is also the Uidevice.swipe method, so let's see where the difference is. First it also points to the controls and coordinates, respectively, to analyze:

Control

The center point of the control is first used as the starting coordinate, and the displacement data is obtained based on the supplied parameters Xoffset and Yoffset, and the speed parameter is used to calculate the step.

Steps = 1250.0/speed + 1;
End.X = Start.x + xoffset;
End.y = Start.y + yoffset;

The starting coordinate plus the displacement is the end of the coordinates, this steps setting is still a bit confusing, I this 1250 I think is the largest displacement bar, speed represents each step away. Use 1250/speed to get the number of steps to the end point, plus the initial value of the point to get steps value. The starting point coordinates, the end point coordinates, and the step values are all set.

Coordinate

Strictly speaking, can not be said to coordinate, should be calculated coordinate displacement, because only the parameters passed in the coordinate system speed xspeed and Yspeed. The x-axis moves the xspeed distance, and the y-axis moves the yspeed coordinates. Then get the coordinate value and the steps value.
It uses 1250 and the square of the displacement to make a comparison, take out the minimum value to calculate the steps. The starting coordinate point locates the center point coordinates of the screen. Then call end = Calculateendpoint (Start, XSpeed, Yspeed), and the method gets the end point coordinates.

Private Point Calculateendpoint (final point start, final Integer xspeed,

Final Integer yspeed) {

Final Uidevice D = uidevice.getinstance ();

Final point end = new Point ();

Final double speedRatio = (double) xspeed/yspeed;

Double xOff;

Double Yoff;

Final Double value = Math.min (D.getdisplayheight (), D.getdisplaywidth ());

if (SpeedRatio < 1) {

Yoff = VALUE/4;

XOFF = VALUE/4 * speedRatio;

} else {

XOFF = VALUE/4;

Yoff = VALUE/4/speedRatio;

}

XOFF = Integer.signum (xspeed) * XOFF;

Yoff = Integer.signum (yspeed) * YOFF;

End.X = Start.x + xOff;

End.y = Start.y + Yoff;

return end;

}

First, the displacement is calculated from the displacement of the SpeedRatio (x displacement/y), then the screen width and the minimum number of the high school is copied to value. If the value of Speedratio<1,x's moving distance is the same as the X-Move distance, the 1/4.Y coordinates are the same. So the coordinates and the starting point of the end point after the above calculation should be the diagonal of the square type.

The last call to Uidevice.swipe and swipe is the same. Nothing special.

Mobile phone Automation test: Appium Source analysis of Bootstrap six

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.