Skip to content

Commit fc3545d

Browse files
committed
Fix tests
1 parent 052ee6a commit fc3545d

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

app/src/androidTest/java/fr/free/nrw/commons/UITestHelper.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import androidx.test.espresso.action.ViewActions
99
import androidx.test.espresso.matcher.ViewMatchers
1010
import androidx.test.rule.ActivityTestRule
1111
import org.apache.commons.lang3.StringUtils
12+
import org.hamcrest.BaseMatcher
13+
import org.hamcrest.Description
14+
import org.hamcrest.Matcher
1215
import timber.log.Timber
1316

17+
1418
class UITestHelper {
1519
companion object {
1620
fun skipWelcome() {
@@ -34,7 +38,7 @@ class UITestHelper {
3438
closeSoftKeyboard()
3539
onView(ViewMatchers.withId(R.id.login_button))
3640
.perform(ViewActions.click())
37-
sleep(5000)
41+
sleep(10000)
3842
} catch (ignored: NoMatchingViewException) {
3943
}
4044

@@ -68,5 +72,22 @@ class UITestHelper {
6872
activityRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
6973
assert(activityRule.activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
7074
}
75+
76+
fun <T> first(matcher: Matcher<T>): Matcher<T>? {
77+
return object : BaseMatcher<T>() {
78+
var isFirst = true
79+
override fun matches(item: Any): Boolean {
80+
if (isFirst && matcher.matches(item)) {
81+
isFirst = false
82+
return true
83+
}
84+
return false
85+
}
86+
87+
override fun describeTo(description: Description) {
88+
description.appendText("should return first matching item")
89+
}
90+
}
91+
}
7192
}
7293
}

app/src/androidTest/java/fr/free/nrw/commons/UploadTest.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.graphics.Bitmap
88
import android.net.Uri
99
import android.os.Environment
1010
import android.view.View
11+
import androidx.recyclerview.widget.RecyclerView
1112
import androidx.test.espresso.Espresso.onView
1213
import androidx.test.espresso.NoMatchingViewException
1314
import androidx.test.espresso.action.ViewActions.click
@@ -116,7 +117,7 @@ class UploadTest {
116117
UITestHelper.sleep(3000)
117118

118119
try {
119-
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
120+
onView(allOf(isDisplayed(), UITestHelper.first(withParent(withId(R.id.rv_categories)))))
120121
.perform(click())
121122
} catch (ignored: NoMatchingViewException) {
122123
}
@@ -173,18 +174,18 @@ class UploadTest {
173174
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
174175
.perform(click())
175176

176-
UITestHelper.sleep(5000)
177+
UITestHelper.sleep(10000)
177178
dismissWarning("Yes")
178179

179180
UITestHelper.sleep(3000)
180181

181182
onView(allOf(isDisplayed(), withId(R.id.et_search)))
182-
.perform(replaceText("Uploaded with Mobile/Android Tests"))
183+
.perform(replaceText("Test"))
183184

184185
UITestHelper.sleep(3000)
185186

186187
try {
187-
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
188+
onView(allOf(isDisplayed(), UITestHelper.first(withParent(withId(R.id.rv_categories)))))
188189
.perform(click())
189190
} catch (ignored: NoMatchingViewException) {
190191
}
@@ -261,7 +262,7 @@ class UploadTest {
261262
UITestHelper.sleep(3000)
262263

263264
try {
264-
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
265+
onView(allOf(isDisplayed(), UITestHelper.first(withParent(withId(R.id.rv_categories)))))
265266
.perform(click())
266267
} catch (ignored: NoMatchingViewException) {
267268
}

0 commit comments

Comments
 (0)