@@ -21,6 +21,7 @@ package org.kiwix.kiwixmobile
21
21
import android.R.id
22
22
import android.app.Instrumentation
23
23
import android.content.Context
24
+ import androidx.test.espresso.NoMatchingViewException
24
25
import androidx.test.platform.app.InstrumentationRegistry
25
26
import androidx.test.uiautomator.Direction
26
27
import androidx.test.uiautomator.UiDevice
@@ -52,7 +53,7 @@ abstract class BaseRobot(
52
53
uiDevice.pressBack()
53
54
}
54
55
55
- protected fun isVisible (findable : Findable , timeout : Long = DEFAULT_WAIT ) =
56
+ protected fun isVisible (findable : Findable , timeout : Long = VERY_LONG_WAIT ) =
56
57
waitFor(findable, timeout) ? : throw RuntimeException (findable.errorMessage(this ))
57
58
58
59
protected fun UiObject2.swipeLeft () {
@@ -63,7 +64,7 @@ abstract class BaseRobot(
63
64
customSwipe(Direction .RIGHT )
64
65
}
65
66
66
- protected fun clickOn (findable : Findable , timeout : Long = DEFAULT_WAIT ) {
67
+ protected fun clickOn (findable : Findable , timeout : Long = VERY_LONG_WAIT ) {
67
68
isVisible(findable, timeout).click()
68
69
}
69
70
@@ -81,9 +82,20 @@ abstract class BaseRobot(
81
82
82
83
private fun waitFor (
83
84
findable : Findable ,
84
- timeout : Long = DEFAULT_WAIT
85
- ): UiObject2 ? =
86
- uiDevice.wait(Until .findObject(findable.selector(this )), timeout)
85
+ timeout : Long = VERY_LONG_WAIT ,
86
+ retryCount : Int = 5
87
+ ): UiObject2 ? {
88
+ var uiObject2: UiObject2 ? = null
89
+ for (i in 0 until retryCount) {
90
+ try {
91
+ uiObject2 = uiDevice.wait(Until .findObject(findable.selector(this )), timeout)
92
+ break
93
+ } catch (noMatchingViewException: NoMatchingViewException ) {
94
+ noMatchingViewException.printStackTrace()
95
+ }
96
+ }
97
+ return uiObject2
98
+ }
87
99
88
100
private fun UiObject2.customSwipe (
89
101
direction : Direction ,
0 commit comments