LoginSignup
0
2

More than 5 years have passed since last update.

Androidの自動UIテストで他アプリや設定ダイアログのボタンを押す

Last updated at Posted at 2018-08-01

概要

Espressoの操作録画機能(Record Espresso Test)は便利ですが、残念ながら一部の操作は記録されないようです。
今回は、他のアプリや設定ダイアログのボタンを押す操作が記録されなくて困ったので、OKの文字列を探し出して押すコードで代用できないか調べました。
結果としては可能で、UI AutomatorUiDeviceを使います。

実装方法(例)

build.gradle

dependencies {
    ・・・
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
        ・・・
}

テストコード

private static final int TIMEOUT = 5000;

// Initialize UiDevice instance (UI Automator)
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

// Tap "OK" button
UiObject2 obj = device.wait(Until.findObject(By.text("OK")), TIMEOUT);
if (obj == null) {
    fail("OK button was not found.");
}
obj.click();

補足

以下調査中。もしわかる方いましたらコメント下さい。
- 言語が違う場合に対応する

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2