mirror of
https://github.com/hmalik144/Driver.git
synced 2026-03-18 15:36:03 +00:00
- Robots added for tests
- Tests added - view naming refactoring - Image selecting stubbing added Took 3 hours 48 minutes
This commit is contained in:
@@ -5,13 +5,17 @@ import android.app.Instrumentation
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import android.widget.DatePicker
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import androidx.test.espresso.Espresso.onData
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.UiController
|
||||
import androidx.test.espresso.ViewAction
|
||||
import androidx.test.espresso.ViewInteraction
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.action.ViewActions.swipeDown
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.contrib.PickerActions
|
||||
@@ -20,12 +24,12 @@ import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.espresso.intent.Intents.intending
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
import h_mal.appttude.com.driver.helpers.DataHelper
|
||||
import h_mal.appttude.com.driver.helpers.EspressoHelper.waitForView
|
||||
import org.hamcrest.CoreMatchers.allOf
|
||||
import org.hamcrest.CoreMatchers.anything
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.Matchers
|
||||
import java.io.File
|
||||
|
||||
@@ -38,25 +42,25 @@ open class BaseTestRobot {
|
||||
)
|
||||
|
||||
fun clickButton(resId: Int): ViewInteraction =
|
||||
onView((withId(resId))).perform(ViewActions.click())
|
||||
onView((withId(resId))).perform(click())
|
||||
|
||||
fun matchView(resId: Int): ViewInteraction = onView(withId(resId))
|
||||
|
||||
fun matchViewWaitFor(resId: Int): ViewInteraction = waitForView(withId(resId))
|
||||
|
||||
fun matchText(viewInteraction: ViewInteraction, text: String): ViewInteraction = viewInteraction
|
||||
.check(matches(ViewMatchers.withText(text)))
|
||||
.check(matches(withText(text)))
|
||||
|
||||
fun matchText(resId: Int, text: String): ViewInteraction = matchText(matchView(resId), text)
|
||||
|
||||
fun clickListItem(listRes: Int, position: Int) {
|
||||
onData(anything())
|
||||
.inAdapterView(allOf(withId(listRes)))
|
||||
.atPosition(position).perform(ViewActions.click())
|
||||
.atPosition(position).perform(click())
|
||||
}
|
||||
|
||||
fun <VH : ViewHolder> clickRecyclerItemWithText(recyclerId: Int, text: String) {
|
||||
onView(withId(recyclerId))
|
||||
fun <VH : ViewHolder> scrollToRecyclerItem(recyclerId: Int, text: String): ViewInteraction? {
|
||||
return onView(withId(recyclerId))
|
||||
.perform(
|
||||
// scrollTo will fail the test if no item matches.
|
||||
RecyclerViewActions.scrollTo<VH>(
|
||||
@@ -65,6 +69,26 @@ open class BaseTestRobot {
|
||||
)
|
||||
}
|
||||
|
||||
fun <VH : ViewHolder> clickViewInRecycler(recyclerId: Int, text: String) {
|
||||
scrollToRecyclerItem<VH>(recyclerId, text)?.perform(click())
|
||||
}
|
||||
|
||||
fun <VH : ViewHolder> clickSubViewInRecycler(recyclerId: Int, text: String, subView: Int) {
|
||||
scrollToRecyclerItem<VH>(recyclerId, text)
|
||||
?.perform(
|
||||
// scrollTo will fail the test if no item matches.
|
||||
RecyclerViewActions.actionOnItem<VH>(
|
||||
hasDescendant(withText(text)), object : ViewAction {
|
||||
override fun getDescription(): String = "Matching recycler descendant"
|
||||
override fun getConstraints(): Matcher<View>? = isRoot()
|
||||
override fun perform(uiController: UiController?, view: View?) {
|
||||
view?.findViewById<View>(subView)?.performClick()
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun checkErrorOnTextEntry(resId: Int, errorMessage: String): ViewInteraction =
|
||||
onView(withId(resId)).check(matches(checkErrorMessage(errorMessage)))
|
||||
|
||||
@@ -78,7 +102,7 @@ open class BaseTestRobot {
|
||||
Resources.getSystem().getString(resId)
|
||||
|
||||
fun selectDateInPicker(year: Int, month: Int, day: Int) {
|
||||
onView(ViewMatchers.withClassName(Matchers.equalTo(DatePicker::class.java.name))).perform(
|
||||
onView(withClassName(Matchers.equalTo(DatePicker::class.java.name))).perform(
|
||||
PickerActions.setDate(
|
||||
year,
|
||||
month,
|
||||
|
||||
@@ -13,14 +13,10 @@ import org.junit.BeforeClass
|
||||
open class FirebaseTest<T : BaseActivity<*, *>>(
|
||||
activity: Class<T>,
|
||||
private val registered: Boolean = false,
|
||||
private val signedIn: Boolean = false
|
||||
private val signedIn: Boolean = false,
|
||||
private val signOutAfterTest: Boolean = true
|
||||
) : BaseUiTest<T>(activity) {
|
||||
|
||||
// @get:Rule
|
||||
// val intentsRule = IntentsRule()
|
||||
|
||||
private val firebaseAuthSource by lazy { FirebaseAuthSource() }
|
||||
|
||||
private var email: String? = null
|
||||
|
||||
companion object {
|
||||
@@ -48,9 +44,10 @@ open class FirebaseTest<T : BaseActivity<*, *>>(
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDownFirebase() = runBlocking {
|
||||
removeUser()
|
||||
firebaseAuthSource.logOut()
|
||||
fun tearDownFirebase() {
|
||||
if (signOutAfterTest) {
|
||||
firebaseAuthSource.logOut()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setupUser(
|
||||
@@ -85,9 +82,6 @@ open class FirebaseTest<T : BaseActivity<*, *>>(
|
||||
}
|
||||
|
||||
fun getEmail(): String? {
|
||||
firebaseAuthSource.getUser()?.email?.let {
|
||||
return it
|
||||
}
|
||||
return email
|
||||
return firebaseAuthSource.getUser()?.email ?: email
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package h_mal.appttude.com.driver.firebase.api
|
||||
|
||||
import h_mal.appttude.com.driver.firebase.model.SignUpRequest
|
||||
import h_mal.appttude.com.driver.firebase.model.SignUpResponse
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class FirebaseApiModule {
|
||||
|
||||
private val firebaseApi = FirebaseApi()
|
||||
|
||||
fun signUp(email: String, password: String): SignUpResponse? {
|
||||
return runBlocking {
|
||||
val req = SignUpRequest(email = email, password = password)
|
||||
val response = firebaseApi.signUp(req)
|
||||
response.body()
|
||||
}
|
||||
}
|
||||
|
||||
fun signIn(email: String, password: String): SignUpResponse? {
|
||||
return runBlocking {
|
||||
val req = SignUpRequest(email = email, password = password)
|
||||
val response = firebaseApi.signInWithPassword(req)
|
||||
response.body()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package h_mal.appttude.com.driver.robots
|
||||
|
||||
import h_mal.appttude.com.driver.BaseTestRobot
|
||||
import h_mal.appttude.com.driver.PASSWORD
|
||||
import h_mal.appttude.com.driver.R
|
||||
|
||||
|
||||
@@ -21,4 +22,11 @@ class LoginRobot : BaseTestRobot() {
|
||||
|
||||
fun checkPasswordError(err: String) = checkErrorOnTextEntry(R.id.password, err)
|
||||
|
||||
fun attemptLogin(emailAddress: String, password: String = PASSWORD) {
|
||||
matchViewWaitFor(R.id.email)
|
||||
setEmail(emailAddress)
|
||||
setPassword(password)
|
||||
clickLogin()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user