2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

[fenix] Save logins and external links in custom tabs UI test

This commit is contained in:
AndiAJ 2022-02-11 11:51:02 +02:00 committed by mergify[bot]
parent bee88db440
commit c874f11dc7
2 changed files with 108 additions and 0 deletions

View File

@ -26,6 +26,8 @@ import org.mozilla.fenix.ui.robots.searchScreen
class CustomTabsTest { class CustomTabsTest {
private lateinit var mockWebServer: MockWebServer private lateinit var mockWebServer: MockWebServer
private val customMenuItem = "TestMenuItem" private val customMenuItem = "TestMenuItem"
private val externalLinksPWAPage = "https://mozilla-mobile.github.io/testapp/externalLinks.html"
private val loginPage = "https://mozilla-mobile.github.io/testapp/loginForm"
@get:Rule @get:Rule
val activityTestRule = HomeActivityIntentTestRule() val activityTestRule = HomeActivityIntentTestRule()
@ -53,6 +55,59 @@ class CustomTabsTest {
mockWebServer.shutdown() mockWebServer.shutdown()
} }
@SmokeTest
@Test
fun customTabsOpenExternalLinkTest() {
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
externalLinksPWAPage.toUri().toString(),
customMenuItem
)
)
customTabScreen {
waitForPageToLoad()
clickLinkMatchingText("External link")
waitForPageToLoad()
verifyCustomTabToolbarTitle("Google")
}
}
@SmokeTest
@Test
fun customTabsSaveLoginTest() {
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
loginPage.toUri().toString(),
customMenuItem
)
)
customTabScreen {
waitForPageToLoad()
fillAndSubmitLoginCredentials("mozilla", "firefox")
}
browserScreen {
verifySaveLoginPromptIsDisplayed()
saveLoginFromPrompt("Save")
}
openAppFromExternalLink(loginPage)
browserScreen {
}.openThreeDotMenu {
}.openSettings {
}.openLoginsAndPasswordSubMenu {
}.openSavedLogins {
verifySecurityPromptForLogins()
tapSetupLater()
verifySavedLoginFromPrompt("mozilla")
}
}
@SmokeTest @SmokeTest
@Test @Test
fun customTabCopyToolbarUrlTest() { fun customTabCopyToolbarUrlTest() {

View File

@ -11,6 +11,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiObjectNotFoundException
import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.UiSelector
import junit.framework.TestCase.assertTrue import junit.framework.TestCase.assertTrue
import org.mozilla.fenix.R import org.mozilla.fenix.R
@ -84,6 +85,48 @@ class CustomTabRobot {
copyText.click() copyText.click()
} }
fun fillAndSubmitLoginCredentials(userName: String, password: String) {
var currentTries = 0
while (currentTries++ < 3) {
try {
mDevice.waitForIdle(waitingTime)
userNameTextBox.setText(userName)
passwordTextBox.setText(password)
submitLoginButton.click()
mDevice.waitForObjects(mDevice.findObject(UiSelector().resourceId("$packageName:id/save_confirm")))
break
} catch (e: UiObjectNotFoundException) {
customTabScreen {
}.openMainMenu {
refreshButton().click()
waitForPageToLoad()
}
}
}
}
fun clickLinkMatchingText(expectedText: String) {
var currentTries = 0
while (currentTries++ < 3) {
try {
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
.waitForExists(waitingTime)
mDevice.findObject(UiSelector().textContains(expectedText))
.waitForExists(waitingTime)
val element = mDevice.findObject(UiSelector().textContains(expectedText))
element.click()
break
} catch (e: UiObjectNotFoundException) {
customTabScreen {
}.openMainMenu {
refreshButton().click()
waitForPageToLoad()
}
}
}
}
fun waitForPageToLoad() = progressBar.waitUntilGone(waitingTime) fun waitForPageToLoad() = progressBar.waitUntilGone(waitingTime)
class Transition { class Transition {
@ -131,3 +174,13 @@ private val progressBar =
mDevice.findObject( mDevice.findObject(
UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_progress") UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_progress")
) )
private val submitLoginButton =
mDevice.findObject(
UiSelector()
.index(2)
.resourceId("submit")
.textContains("Submit Query")
.className("android.widget.Button")
.packageName("$packageName")
)