スマートフォンアプリでは、画面遷移の途中でイレギュラーな画面が挿入されることがよくあります。
ポップアップダイアログ(位置情報の許可、ネットワークエラー、Firebase In-App Messaging、広告など)、機能の使い方を説明するチュートリアル、通知バルーンなどが表示されたり、されなかったりすることがあります。
このようなイレギュラーを処理するためには、条件分岐を実装する必要があります。これはとても面倒な作業です。
AnnoyingEventHandling1.kt
@Test @Order(10) fun annoyingEventHandling1() { scenario { case(1) { condition { it.macro("[Some Screen]") .ifCanSelect("While using the app") { it.tap() } }.action { it.tap("[Button1]") .ifCanSelect("While using the app") { it.tap() } }.expectation { it.screenIs("[Next Screen]") } } } } @Test @Order(20) fun annoyingEventHandling2() { scenario { case(1) { condition { it.macro("[Some Screen2]") .ifCanSelect("While using the app") { it.tap() } }.action { it.tap("[Button2]") .ifCanSelect("While using the app") { it.tap() } }.expectation { it.screenIs("[Next Screen]") } } } }
irregularHandler
イレギュラーに関する処理はirregularHandlerで一元的に記述することができます。
TestClass内の全てのテスト関数に適用するには、setEventHandlers関数をオーバーライドし、context.iregularHandlerに処理を記述します。
irregularHandlerは操作コマンドの実行時に毎回呼び出されるので割り込み処理を実現できます。この仕組みは非常に強力であり、テストコードをシンプルにすることができます。
IrregularHandler1
(kotlin/tutorial/inaction/IrregularHandler1.kt)
@Testrun("testConfig/android/androidSettings/testrun.properties") class IrregularHandler1 : UITest() { override fun setEventHandlers(context: TestDriverEventContext) { context.irregularHandler = { ifCanSelect("While using the app") { it.tap() } } } @Test @Order(10) fun irregularHandler1() { scenario { case(1) { condition { it.macro("[Some Screen]") }.action { it.tap("[Button1]") }.expectation { it.screenIs("[Next Screen]") } } } } }
注意事項
- irregularHandlerに大量の処理を記述すると、パフォーマンス上の問題が発生する可能性があります。
- irregularHandlerの処理の実行中は、デフォルトでロギングが抑制されます。
suppressHandler
suppressHandler関数を使用することで、regularregularHandlerの発射を抑制することができます。
IrregularHandler1
(kotlin/tutorial/inaction/IrregularHandler1.kt)
@Test @Order(20) fun suppressHandler() { scenario { case(1) { condition { it.macro("[Some Screen]") }.action { /** * In suppressHandler block, * calling irregular handler is suppressed */ suppressHandler { it.tap("[Button1]") } }.expectation { it.screenIs("[Next Screen]") } } } }
disableHandler(), enableHandler()
これらの機能により、irregularHandlerの無効化、有効化を行うことができます。
IrregularHandler1
(kotlin/tutorial/inaction/IrregularHandler1.kt)
@Test @Order(30) fun disableHandler_EnableHandler() { scenario { case(1) { condition { it.macro("[Some Screen]") }.action { disableHandler() // Calling irregular handler is disabled. it.tap("[Button1]") ifCanSelect("While using the app") { it.tap() } enableHandler() // Calling irregular handler is enabled again. }.expectation { it.screenIs("[Next Screen]") } } } }
shirates-core モバイルアプリ用結合テストフレームワーク
OSSなので無償で利用できます。ぜひお試しください。