For #9783: bring app in focus with sendSingleTapToScreen for UI test (#10136)

This commit is contained in:
Oana Horvath 2020-04-28 17:46:42 +03:00 committed by GitHub
parent f0e659bfdb
commit 2c18c255da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -11,6 +11,11 @@ import android.net.Uri
import android.os.Build
import android.preference.PreferenceManager
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.CoordinatesProvider
import androidx.test.espresso.action.GeneralClickAction
import androidx.test.espresso.action.Press
import androidx.test.espresso.action.Tap
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
@ -89,4 +94,20 @@ object TestHelper {
context.startActivity(intent)
}
}
fun sendSingleTapToScreen(x: Int, y: Int): ViewAction? {
return GeneralClickAction(
Tap.SINGLE,
CoordinatesProvider { view ->
val screenPos = IntArray(2)
view.getLocationOnScreen(screenPos)
val screenX = screenPos[0] + x.toFloat()
val screenY = screenPos[1] + y.toFloat()
floatArrayOf(screenX, screenY)
},
Press.FINGER,
0,
0
)
}
}

View File

@ -17,6 +17,7 @@ import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.sendSingleTapToScreen
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
@ -267,7 +268,9 @@ class TabbedBrowsingTest {
notificationShade {
verifyPrivateTabsNotification()
}.clickClosePrivateTabsNotification {
verifyPrivateSessionMessage()
// Tap an empty spot on the app homescreen to make sure it's into focus
sendSingleTapToScreen(20, 20)
verifyPrivateSessionMessage(visible = true)
}
}
}

View File

@ -559,7 +559,7 @@ const val PRIVATE_SESSION_MESSAGE =
" else who uses this device."
private fun assertPrivateSessionMessage(visible: Boolean) =
onView(allOf(withText(PRIVATE_SESSION_MESSAGE)))
onView(withId(R.id.private_session_description))
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE)) else doesNotExist()
)