mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Make all UI tests pass and add more tests (#2700)
This commit is contained in:
parent
239f74942f
commit
f7e6b20cab
8 changed files with 214 additions and 60 deletions
61
app/src/androidTest/java/fr/free/nrw/commons/UITestHelper.kt
Normal file
61
app/src/androidTest/java/fr/free/nrw/commons/UITestHelper.kt
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import androidx.test.espresso.Espresso.closeSoftKeyboard
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.NoMatchingViewException
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import fr.free.nrw.commons.utils.StringUtils
|
||||
import timber.log.Timber
|
||||
|
||||
class UITestHelper {
|
||||
companion object {
|
||||
fun skipWelcome() {
|
||||
try {
|
||||
//Skip tutorial
|
||||
onView(ViewMatchers.withId(R.id.finishTutorialButton))
|
||||
.perform(ViewActions.click())
|
||||
} catch (ignored: NoMatchingViewException) {
|
||||
}
|
||||
}
|
||||
|
||||
fun loginUser() {
|
||||
try {
|
||||
//Perform Login
|
||||
onView(ViewMatchers.withId(R.id.loginUsername))
|
||||
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUsername()))
|
||||
onView(ViewMatchers.withId(R.id.loginPassword))
|
||||
.perform(ViewActions.clearText(), ViewActions.typeText(getTestUserPassword()))
|
||||
closeSoftKeyboard()
|
||||
onView(ViewMatchers.withId(R.id.loginButton))
|
||||
.perform(ViewActions.click())
|
||||
sleep(5000)
|
||||
} catch (ignored: NoMatchingViewException) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun sleep(timeInMillis: Long) {
|
||||
try {
|
||||
Timber.d("Sleeping for %d", timeInMillis)
|
||||
Thread.sleep(timeInMillis)
|
||||
} catch (e: InterruptedException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getTestUsername(): String {
|
||||
val username = BuildConfig.TEST_USERNAME
|
||||
if (StringUtils.isNullOrWhiteSpace(username) || username == "null") {
|
||||
throw NotImplementedError("Configure your beta account's username")
|
||||
} else return username
|
||||
}
|
||||
|
||||
private fun getTestUserPassword(): String {
|
||||
val password = BuildConfig.TEST_PASSWORD
|
||||
if (StringUtils.isNullOrWhiteSpace(password) || password == "null") {
|
||||
throw NotImplementedError("Configure your beta account's password")
|
||||
} else return password
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue