Android Automation Test-robotium (eight) drag

Source: Internet
Author: User

This article is from: http://xiaomaozi.blog.51cto.com/925779/933056

Seekbar controls

Code implementation: http://luwenjie.blog.51cto.com/925779/933023

Default display: "Hello world,myandroidactivity"

Operation:

1. Click on the control (dot)

2. Dragging to a certain position

Verify: TextView: "< drag bar > Finish dragging"

1  Public void  2     booleantrue; 3     Solo.clickonscreen (one, 121); 4     Solo.drag (one, 121, a, 35     boolean actual = Solo.searchtext ("< drag bar > Finish dragging "6     assertequals (" This was not found "7

Clickonscreen has two parameters

Action: Tap a coordinate point on the screen

public void Clickonscreen (float x,float y)

x: X coordinate of the screen

Y: the y-coordinate of the screen

Drag has five parameters

Role: Drag the screen from a to B coordinates

public void drag (float FromX, float toX, float fromY, float toY, int stepcount)

From x: the initial x-coordinate of the screen coordinates

To x: screen coordinates drag the X-coordinate of the destination

From Y: the initial y-coordinate of the screen coordinates

To Y: Drag the y-coordinate of the destination in screen coordinates

Stepcount: Number of steps required to complete the drag

This API uses a called coordinates, of course, the android simulator coordinates are fixed, you can rely on experience to get the screen coordinates, but this is not reliable ...

Here is a tool: Monkeyrunner

Monkeyrunner Recording mode can help you get to the android screen coordinates

For Monkeyrunner, refer to: http://luwenjie.blog.51cto.com/925779/925659

This test example is mainly to explain the role of drag, the actual need only one step to complete the test. We can simply click on a coordinate point of the Seekbar control without dragging it.

Supplement the first Api:setprogressbar

Effect: Set the progress of the obtained ProgressBar  , for example: Seekbar and Ratinbar

public void Setprogressbar (int index, int progress)

int index: ProgressBar  control positioning

int progress: ProgressBar  The progress position that should be set

1  Public voidDrag () {2     Booleanexpected =true; 3Solo.setprogressbar (0, 65); 4     //Solo.clickonscreen (121, 80); 5     //Solo.drag (one, 121, he, 3);6     Booleanactual = Solo.searchtext ("Current < drag bar > value: 65"); 7Assertequals ("This isn't a found", expected,actual); 8}

Note: After using Setprogressbar, you still hold the pressed state.

Add a second Api:clicklongonscreen

Function: Hold down a coordinate point of the screen for a long time

public void Clicklongscreen (float x, float y, int time)

float X:X coordinates

float Y:y coordinates

int time: long and regular room

Android Automation Test-robotium (eight) drag

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.