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