Skip to content

Commit 65ec071

Browse files
authored
Fix existing Espresso tests (commons-app#3450)
* Fix existing Espresso tests * Convert class to kotlin
1 parent 36cafd7 commit 65ec071

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class LoginActivityTest {
4646

4747
@Test
4848
fun testForgotPassword() {
49+
UITestHelper.sleep(3000)
4950
Espresso.onView(ViewMatchers.withId(R.id.forgot_password))
5051
.perform(ViewActions.click())
5152
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(BuildConfig.FORGOT_PASSWORD_URL)));

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

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SignupTest {
3535

3636
}
3737

38+
UITestHelper.sleep(3000)
3839
Espresso.onView(withId(R.id.sign_up_button))
3940
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
4041
.perform(click())

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

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class UITestHelper {
2525
fun loginUser() {
2626
try {
2727
//Perform Login
28+
sleep(3000)
2829
onView(ViewMatchers.withId(R.id.login_username))
2930
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUsername()))
3031
closeSoftKeyboard()

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

+20-13
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ class UploadTest {
135135
val commonsFileName = "MobileTest " + dateFormat.format(Date())
136136

137137
// Try to dismiss the error, if there is one (probably about duplicate files on Commons)
138-
try {
139-
onView(withText("Yes"))
140-
.check(matches(isDisplayed()))
141-
.perform(click())
142-
} catch (ignored: NoMatchingViewException) {}
138+
dismissWarning("Yes")
143139

144140
onView(allOf<View>(isDisplayed(), withId(R.id.et_title)))
145141
.perform(replaceText(commonsFileName))
@@ -151,25 +147,27 @@ class UploadTest {
151147
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
152148
.perform(click())
153149

154-
try {
155-
onView(withText("Yes"))
156-
.check(matches(isDisplayed()))
157-
.perform(click())
158-
} catch (ignored: NoMatchingViewException) {}
150+
UITestHelper.sleep(5000)
151+
dismissWarning("Yes")
159152

160-
UITestHelper.sleep(1000)
153+
UITestHelper.sleep(3000)
161154

162155
onView(allOf(isDisplayed(), withId(R.id.et_search)))
163156
.perform(replaceText("Uploaded with Mobile/Android Tests"))
164157

165158
UITestHelper.sleep(3000)
166159

167-
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
168-
.perform(click())
160+
try {
161+
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
162+
.perform(click())
163+
} catch (ignored: NoMatchingViewException) {
164+
}
169165

170166
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
171167
.perform(click())
172168

169+
dismissWarning("Yes, Submit")
170+
173171
UITestHelper.sleep(500)
174172

175173
onView(allOf(isDisplayed(), withId(R.id.btn_submit)))
@@ -181,4 +179,13 @@ class UploadTest {
181179
commonsFileName.replace(' ', '_') + ".jpg"
182180
Timber.i("File should be uploaded to $fileUrl")
183181
}
182+
183+
private fun dismissWarning(warningText: String) {
184+
try {
185+
onView(withText(warningText))
186+
.check(matches(isDisplayed()))
187+
.perform(click())
188+
} catch (ignored: NoMatchingViewException) {
189+
}
190+
}
184191
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fr.free.nrw.commons
2+
3+
import android.view.View
4+
import androidx.test.espresso.UiController
5+
import androidx.test.espresso.ViewAction
6+
import org.hamcrest.Matcher
7+
8+
object ViewActions {
9+
fun clickChildViewWithId(id: Int): ViewAction {
10+
return object : ViewAction {
11+
override fun getConstraints(): Matcher<View> {
12+
return null
13+
}
14+
15+
override fun getDescription(): String {
16+
return "Click on a child view with specified id."
17+
}
18+
19+
override fun perform(uiController: UiController, view: View) {
20+
val v = view.findViewById<View>(id)
21+
v.performClick()
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)