コード例 #1
0
  @Before
  public void init() {
    device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    device.pressHome();
    device.wait(Until.hasObject(By.desc("Apps")), 3000);

    UiObject2 appsButton = device.findObject(By.desc("Apps"));
    appsButton.click();
    device.wait(Until.hasObject(By.text("Calculator")), 3000);

    UiObject2 calculatorApp = device.findObject(By.text("Calculator"));
    calculatorApp.click();
  }
コード例 #2
0
  @Test
  public void launchCalculatorAndTest() {
    device.wait(Until.hasObject(By.text("9")), 3000);
    UiObject2 buttonNine = device.findObject(By.text("9"));
    buttonNine.click();
    UiObject2 buttonPlus = device.findObject(By.desc("plus"));
    buttonPlus.click();
    buttonNine.click();
    UiObject2 buttonEquals = device.findObject(By.desc("equals"));
    buttonEquals.click();

    device.waitForIdle(3000);

    UiObject2 resultText = device.findObject(By.clazz("android.widget.EditText"));
    String result = resultText.getText();
    assertTrue(result.equals("18"));
  }