mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Fix existing Espresso tests (#3450)
* Fix existing Espresso tests * Convert class to kotlin
This commit is contained in:
parent
36cafd7c39
commit
65ec071493
5 changed files with 48 additions and 13 deletions
|
|
@ -46,6 +46,7 @@ class LoginActivityTest {
|
|||
|
||||
@Test
|
||||
fun testForgotPassword() {
|
||||
UITestHelper.sleep(3000)
|
||||
Espresso.onView(ViewMatchers.withId(R.id.forgot_password))
|
||||
.perform(ViewActions.click())
|
||||
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(BuildConfig.FORGOT_PASSWORD_URL)));
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class SignupTest {
|
|||
|
||||
}
|
||||
|
||||
UITestHelper.sleep(3000)
|
||||
Espresso.onView(withId(R.id.sign_up_button))
|
||||
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
|
||||
.perform(click())
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class UITestHelper {
|
|||
fun loginUser() {
|
||||
try {
|
||||
//Perform Login
|
||||
sleep(3000)
|
||||
onView(ViewMatchers.withId(R.id.login_username))
|
||||
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUsername()))
|
||||
closeSoftKeyboard()
|
||||
|
|
|
|||
|
|
@ -135,11 +135,7 @@ class UploadTest {
|
|||
val commonsFileName = "MobileTest " + dateFormat.format(Date())
|
||||
|
||||
// Try to dismiss the error, if there is one (probably about duplicate files on Commons)
|
||||
try {
|
||||
onView(withText("Yes"))
|
||||
.check(matches(isDisplayed()))
|
||||
.perform(click())
|
||||
} catch (ignored: NoMatchingViewException) {}
|
||||
dismissWarning("Yes")
|
||||
|
||||
onView(allOf<View>(isDisplayed(), withId(R.id.et_title)))
|
||||
.perform(replaceText(commonsFileName))
|
||||
|
|
@ -151,25 +147,27 @@ class UploadTest {
|
|||
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
|
||||
.perform(click())
|
||||
|
||||
try {
|
||||
onView(withText("Yes"))
|
||||
.check(matches(isDisplayed()))
|
||||
.perform(click())
|
||||
} catch (ignored: NoMatchingViewException) {}
|
||||
UITestHelper.sleep(5000)
|
||||
dismissWarning("Yes")
|
||||
|
||||
UITestHelper.sleep(1000)
|
||||
UITestHelper.sleep(3000)
|
||||
|
||||
onView(allOf(isDisplayed(), withId(R.id.et_search)))
|
||||
.perform(replaceText("Uploaded with Mobile/Android Tests"))
|
||||
|
||||
UITestHelper.sleep(3000)
|
||||
|
||||
try {
|
||||
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
|
||||
.perform(click())
|
||||
} catch (ignored: NoMatchingViewException) {
|
||||
}
|
||||
|
||||
onView(allOf(isDisplayed(), withId(R.id.btn_next)))
|
||||
.perform(click())
|
||||
|
||||
dismissWarning("Yes, Submit")
|
||||
|
||||
UITestHelper.sleep(500)
|
||||
|
||||
onView(allOf(isDisplayed(), withId(R.id.btn_submit)))
|
||||
|
|
@ -181,4 +179,13 @@ class UploadTest {
|
|||
commonsFileName.replace(' ', '_') + ".jpg"
|
||||
Timber.i("File should be uploaded to $fileUrl")
|
||||
}
|
||||
|
||||
private fun dismissWarning(warningText: String) {
|
||||
try {
|
||||
onView(withText(warningText))
|
||||
.check(matches(isDisplayed()))
|
||||
.perform(click())
|
||||
} catch (ignored: NoMatchingViewException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
25
app/src/androidTest/java/fr/free/nrw/commons/ViewActions.kt
Normal file
25
app/src/androidTest/java/fr/free/nrw/commons/ViewActions.kt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import android.view.View
|
||||
import androidx.test.espresso.UiController
|
||||
import androidx.test.espresso.ViewAction
|
||||
import org.hamcrest.Matcher
|
||||
|
||||
object ViewActions {
|
||||
fun clickChildViewWithId(id: Int): ViewAction {
|
||||
return object : ViewAction {
|
||||
override fun getConstraints(): Matcher<View> {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getDescription(): String {
|
||||
return "Click on a child view with specified id."
|
||||
}
|
||||
|
||||
override fun perform(uiController: UiController, view: View) {
|
||||
val v = view.findViewById<View>(id)
|
||||
v.performClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue