Skip to content

Fix existing Espresso tests #3450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
1 change: 1 addition & 0 deletions app/src/androidTest/java/fr/free/nrw/commons/SignupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SignupTest {

}

UITestHelper.sleep(3000)
Espresso.onView(withId(R.id.sign_up_button))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.perform(click())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 20 additions & 13 deletions app/src/androidTest/java/fr/free/nrw/commons/UploadTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)

onView(allOf(isDisplayed(), withParent(withId(R.id.rv_categories))))
.perform(click())
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)))
Expand All @@ -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 changes: 25 additions & 0 deletions app/src/androidTest/java/fr/free/nrw/commons/ViewActions.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}