LoginSignup
0
0

More than 5 years have passed since last update.

Androidの自動UIテストでWebViewやScrollViewを座標指定でスワイプスクロールする

Last updated at Posted at 2018-08-01

概要

Espressoの操作録画機能(Record Espresso Test)は便利ですが、残念ながら一部の操作は記録されないようです。
今回は、WebViewのスクロールが記録されなくて困ったので、座標指定でスクロールするコードで代用できないか調べました。
結果としては可能で、UI AutomatorUiDeviceを使います。

実装方法(例)

build.gradle

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

テストコード

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

// 座標{80, 1000}から{80, 100}に1秒(第5引数かける5ミリ秒)かけてスワイプ
device.swipe(80, 1000, 80, 100, 200);

補足

以下調査中。もしわかる方いましたらコメント下さい。
- WebViewの最後までスクロールする
- WebViewの中で特定の文字列が見つかるまでスクロールする

0
0
2

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
0