Appium Related methods

Source: Internet
Author: User
Tags appium

1, relative coordinates unlocked nine Gongge

Application Scenarios

QQ unlock screen as above, visible nine keys under the same view, to achieve unlocking, with press MoveTo release perform method

The implementation code is as follows:

Webelement Jiugongge = Pi.findbyxpath ("Jiugongge");//Get the position element where nine Gongge are locatedFinalTouchaction touchaction =Newtouchaction (driver); //the starting x and y coordinates of the elementPoint start =jiugongge.getlocation (); intStartX =Start.x; intStarty =Start.y; System.out.println ("StartX:" +StartX); System.out.println ("Starty:" +starty); //the width and height of the elementDimension q =jiugongge.getsize (); intwidth =q.getwidth (); intHight =q.getheight (); System.out.println ("Width:" +width); System.out.println ("Hight:" +hight); //calculate the distance between each digit interval        intJianjux = WIDTH/3; intJianjuy = HIGHT/3; System.out.println ("Jianjux:" +Jianjux); System.out.println ("Jianjuy:" +Jianjuy); //calculate the control end coordinates        intEndX = width +StartX; intEndY = hight +Starty; System.out.println ("EndX:" +endx); System.out.println ("EndY:" +EndY); //1 of coordinates        intOneX = StartX + JIANJUX/2; intOney = Starty + JIANJUY/2; System.out.println ("OneX:" +OneX); System.out.println ("Oney:" +Oney); //when you swipe up and down, x relative coordinates are 0,y relative coordinates are jianju, the relative coordinate values are positive when you swipe down, and when negative numbers slide upward ZuoTouchaction.press (OneX, Oney). Waitaction (moveTo, 0). Jianjux (moveTo, 0). Jianjux (MoveTo,-jianjux). MoveTo (-jianjux, Jianjuy). MoveTo (Jianjux, 0). MoveTo (Jianjux, 0). Waitaction (500). Release (); Touchaction.perform ();

Basic ideas:

1, find the location of the element;

2, find the coordinates of the first point;

3, find the average moving distance;

4, using the Touchaction Press () MoveTo () and other methods to achieve relative movement

Explanation:Press (OneX, Oney) is the coordinate at the time of pressing, and the coordinates of MOVETO () are relative to the pressed coordinates.

When sliding up and down, x relative coordinates are 0,y relative coordinates are jianju, and the relative coordinate values are positive, swipe down to the right, and swipe up left when negative

2. Swipe up or down on the control

Application Scenarios:

Left-slip Delete on first chat control

The implementation code is as follows:

/*** Position according to the control * swipe up or down inside the control *@paramelement Control Positioning method *@paramheading slide direction up down*/     Public voidSwipecontrol (webelement element, Heading Heading) {//Gets the axis of the control's positionPoint start =element.getlocation (); intStartX =Start.x; intStarty =Start.y; //Get control axis differenceDimension q =element.getsize (); intx =q.getwidth (); inty =q.getheight (); //calculate the control end coordinates        intEndX = x +StartX; intEndY = y +Starty; //Calculate intermediate Point coordinates        intCentreX = (EndX + StartX)/2; intCentrey = (EndY + starty)/2; Switch(heading) {//Swipe to you             CaseRIGHT:driver.swipe (EndX-Ten, EndY, CentreX, EndY, 500);  Break; //Slide to Zuo             CaseLEFT:driver.swipe (EndX-10,endy, CentreX, endY-5, 1000);  Break; //swipe up             CaseUP:driver.swipe (Endx,endy+ 5,centrex,centrey,1000);  Break; //Swipe down             CaseDOWN:driver.swipe (Endx,endy-5,centrex,centrey,1000);  Break; }    }
/**      * Control the slide     direction */public     enum  Heading {Right        , left,        Up, down    }

Basic ideas:

1, find the element to slide;

2, get the starting position of the element;

3, using the swipe (startx,starty,endx,endy,time) function to slide, time for sliding, millisecond units

Explanation: The sliding coordinates can be controlled according to their needs.

3, clear the value of the control

Scenario: The Password box gets no value, the clear function directly with appium cannot be cleaned

Pro-Test, QQ Password box value with clear function sometimes can not clear the feeling

The implementation code is as follows:

/*** One to delete the value in the EditText control *@authorLu *@paramdriver *@paramtext*/     Public voidCleartext (String text,intsecond) {Driver.presskeycode (123);//123: Cursor moves to the far right of the input box        if(Text.length ()!=0) Driver.presskeycode (67);//67 DeleteCommonutils.sleep (second); }

Appium Related methods

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.