Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #9783: bring app in focus with sendSingleTapToScreen for UI test (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Apr 28, 2020
1 parent f0e659b commit 2c18c25
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
21 changes: 21 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
}
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Up @@ -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()
)
Expand Down

0 comments on commit 2c18c25

Please sign in to comment.