0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Android UITest実行前にChromeのキャッシュを削除したい

Last updated at Posted at 2021-12-08

結論

UiDevice.getInstance(getInstrumentation()).executeShellCommand("pm clear com.android.chrome")

こいつをsetUp時に呼ぶ

背景

UI Automatorを利用したAndroidのUITest実行時にSNSログインなどのアプリ外の動作を検証するテストを作りたかった

もちろん各SNS連携後のブラウザでの動作はUI Automatorを使って自動化することができるのですが、
FacebookやYahoo!ログインではブラウザのキャッシュに残っている状況によってパスワード入力がスキップされたりメールアドレス入力が既に入力されている状態になったりと実行時によって動作が変わってしまう

よって先にすべてのChromeブラウザのキャッシュを毎度クリアしてテスト実行しようとした

解説

UiDevice.getInstance(getInstrumentation())

UI Automatorを利用してアプリ外の動作を行います

.executeShellCommand("pm clear com.android.chrome")

adb shell commandを実行します。
これでchromeアプリのストレージを削除します

補足

chrome以外のアプリのストレージを削除したい

$ adb shell pm list packages

アプリパッケージの一覧が表示されますのでそれを引数に指定してください

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?