Tuesday, July 2, 2013

[android help] How to press a button twice using Google UiAutomator?


How to press a button twice using Google UiAutomator?



I have the following script for typing '33' into the Calculator, in Android, using UiAutomator. However, only the first '3' is accepted, the second press is entirely ignored.



import com.android.uiautomator.core.*;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class MyFirstUiAutomatorTest extends UiAutomatorTestCase {
UiObject getByDescription(String description) {
return new UiObject(new UiSelector().description(description));
}

UiObject getByText(String description) {
return new UiObject(new UiSelector().text(description));
}

UiObject scrollableGetByText(String text ) throws UiObjectNotFoundException {
UiScrollable uiScrollable = new UiScrollable(new UiSelector().scrollable(true));
uiScrollable.setAsHorizontalList();
return uiScrollable.getChildByText(new UiSelector().className(
android.widget.TextView.class.getName()),
text);
}

public void testStuff() throws UiObjectNotFoundException {
getUiDevice().pressHome();
getByDescription("Apps").clickAndWaitForNewWindow();
getByText("Apps").click();
scrollableGetByText("Calculator").clickAndWaitForNewWindow();

// pressing '+' and '=' effectively clears the previous input
getByText("+").click();
getByText("=").click();
getByText("3").click();
// this second '3' is ignored
getByText("3").click();
}
}


I've tried adding a sleep for 2 seconds after the first click, by doing:



try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}


... but that didn't change anything.


I also tried clicking on a different button, in between the 2 '3's, ie:



new UiObject(new UiSelector().text("3")).click();
new UiObject(new UiSelector().className("android.widget.EditText")).click();
new UiObject(new UiSelector().text("3")).click();


... but that didn't work either.


Ideas?


(Note: using Android 4.1.2, in an AVD; running on Ubuntu linux 12.04)



.

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...