Fix existing Espresso tests (#3450)

* Fix existing Espresso tests

* Convert class to kotlin
This commit is contained in:
Vivek Maskara 2020-03-02 15:17:24 -07:00 committed by GitHub
parent 36cafd7c39
commit 65ec071493
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 13 deletions

View file

@ -46,6 +46,7 @@ class LoginActivityTest {
@Test @Test
fun testForgotPassword() { fun testForgotPassword() {
UITestHelper.sleep(3000)
Espresso.onView(ViewMatchers.withId(R.id.forgot_password)) Espresso.onView(ViewMatchers.withId(R.id.forgot_password))
.perform(ViewActions.click()) .perform(ViewActions.click())
Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(BuildConfig.FORGOT_PASSWORD_URL))); Intents.intended(CoreMatchers.allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(BuildConfig.FORGOT_PASSWORD_URL)));

View file

@ -35,6 +35,7 @@ class SignupTest {
} }
UITestHelper.sleep(3000)
Espresso.onView(withId(R.id.sign_up_button)) Espresso.onView(withId(R.id.sign_up_button))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed())) .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.perform(click()) .perform(click())

View file

@ -25,6 +25,7 @@ class UITestHelper {
fun loginUser() { fun loginUser() {
try { try {
//Perform Login //Perform Login
sleep(3000)
onView(ViewMatchers.withId(R.id.login_username)) onView(ViewMatchers.withId(R.id.login_username))
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUsername())) .perform(ViewActions.clearText(), ViewActions.typeText(getTestUsername()))
closeSoftKeyboard() closeSoftKeyboard()

View file

@ -135,11 +135,7 @@ class UploadTest {
val commonsFileName = "MobileTest " + dateFormat.format(Date()) val commonsFileName = "MobileTest " + dateFormat.format(Date())
// Try to dismiss the error, if there is one (probably about duplicate files on Commons) // Try to dismiss the error, if there is one (probably about duplicate files on Commons)
try { dismissWarning("Yes")
onView(withText("Yes"))
.check(matches(isDisplayed()))
.perform(click())
} catch (ignored: NoMatchingViewException) {}
onView(allOf<View>(isDisplayed(), withId(R.id.et_title))) onView(allOf<View>(isDisplayed(), withId(R.id.et_title)))
.perform(replaceText(commonsFileName)) .perform(replaceText(commonsFileName))
@ -151,25 +147,27 @@ class UploadTest {
onView(allOf(isDisplayed(), withId(R.id.btn_next))) onView(allOf(isDisplayed(), withId(R.id.btn_next)))
.perform(click()) .perform(click())
try { UITestHelper.sleep(5000)
onView(withText("Yes")) dismissWarning("Yes")
.check(matches(isDisplayed()))
.perform(click())
} catch (ignored: NoMatchingViewException) {}
UITestHelper.sleep(1000) UITestHelper.sleep(3000)
onView(allOf(isDisplayed(), withId(R.id.et_search))) onView(allOf(isDisplayed(), withId(R.id.et_search)))
.perform(replaceText("Uploaded with Mobile/Android Tests")) .perform(replaceText("Uploaded with Mobile/Android Tests"))
UITestHelper.sleep(3000) UITestHelper.sleep(3000)
onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories)))) try {
.perform(click()) onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
.perform(click())
} catch (ignored: NoMatchingViewException) {
}
onView(allOf(isDisplayed(), withId(R.id.btn_next))) onView(allOf(isDisplayed(), withId(R.id.btn_next)))
.perform(click()) .perform(click())
dismissWarning("Yes, Submit")
UITestHelper.sleep(500) UITestHelper.sleep(500)
onView(allOf(isDisplayed(), withId(R.id.btn_submit))) onView(allOf(isDisplayed(), withId(R.id.btn_submit)))
@ -181,4 +179,13 @@ class UploadTest {
commonsFileName.replace(' ', '_') + ".jpg" commonsFileName.replace(' ', '_') + ".jpg"
Timber.i("File should be uploaded to $fileUrl") 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) {
}
}
} }

View 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()
}
}
}
}