1
0
Fork 0

UITests: New tests for save Login prompt (#8381)

* UITests: New tests for save Login prompt

* fixing firebase timing issues when webpage loads

* adding tests for don't save and check the prompt options

* fix detekt issue

* fix reviewer comments
master
isabelrios 2020-02-19 13:23:25 +01:00 committed by GitHub
parent 020608275d
commit 4582c25208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body aria-label="body">
<form method="GET" action="passwordsubmit.html">
<p>Username: <input id="username" type="text" value="test@example.com"></p>
<p>Password: <input id="password" type="password" value="verysecret"></p>
<p><input type="submit" id="submit" value="Login" aria-label="submit"/></p>
</form>
</body>
<script>
document.getElementById("password").value = Math.random().toString();
</script>
</html>

View File

@ -0,0 +1,9 @@
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body aria-label="body">
<p>Password submitted. Nope just a test.</p>
</body>
</html>

View File

@ -83,4 +83,10 @@ object TestAssetHelper {
return TestAsset(url, "") return TestAsset(url, "")
} }
fun getSaveLoginAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/password.html").toString().toUri()!!
return TestAsset(url, "")
}
} }

View File

@ -14,8 +14,10 @@ import org.junit.Ignore
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
/** /**
* Tests for verifying the main three dot menu options * Tests for verifying the main three dot menu options
@ -133,6 +135,65 @@ class SettingsPrivacyTest {
} }
} }
@Test
fun saveLoginFromPromptTest() {
val saveLoginTest =
TestAssetHelper.getSaveLoginAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(saveLoginTest.url) {
verifySaveLoginPromptIsShown()
// Click save to save the login
saveLoginFromPrompt("Save")
}.openHomeScreen {
}.openThreeDotMenu {
}.openSettings {
TestHelper.scrollToElementByText("Logins and passwords")
}.openLoginsAndPasswordSubMenu {
verifyDefaultView()
verifyDefaultValueSyncLogins()
}.openSavedLogins {
verifySavedLoginsView()
tapSetupLater()
// Verify that the login appears correctly
verifySavedLoginFromPrompt()
}
}
@Test
fun doNotSaveLoginFromPromptTest() {
val saveLoginTest = TestAssetHelper.getSaveLoginAsset(mockWebServer)
navigationToolbar {
}.enterURLAndEnterToBrowser(saveLoginTest.url) {
verifySaveLoginPromptIsShown()
// Don't save the login
saveLoginFromPrompt("Dont save")
}.openHomeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openLoginsAndPasswordSubMenu {
verifyDefaultView()
verifyDefaultValueSyncLogins()
}.openSavedLogins {
verifySavedLoginsView()
tapSetupLater()
// Verify that the login list is empty
verifyNotSavedLoginFromPromt()
}
}
@Test
fun saveLoginsAndPasswordsOptions() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openLoginsAndPasswordSubMenu {
}.saveLoginsAndPasswordsOptions {
verifySaveLoginsOptionsView()
}
}
@Ignore("This is a stub test, ignore for now") @Ignore("This is a stub test, ignore for now")
@Test @Test
fun toggleTrackingProtection() { fun toggleTrackingProtection() {

View File

@ -256,6 +256,18 @@ class BrowserRobot {
).perform(ViewActions.click()) ).perform(ViewActions.click())
} }
fun verifySaveLoginPromptIsShown() {
mDevice.waitNotNull(Until.findObjects(By.text("test@example.com")), TestAssetHelper.waitingTime)
val submitButton = mDevice.findObject(By.res("submit"))
submitButton.clickAndWait(Until.newWindow(), TestAssetHelper.waitingTime)
// Click save to save the login
mDevice.waitNotNull(Until.findObjects(By.text("Save")))
}
fun saveLoginFromPrompt(optionToSaveLogin: String) {
mDevice.findObject(By.text(optionToSaveLogin)).click()
}
class Transition { class Transition {
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private fun threeDotButton() = onView( private fun threeDotButton() = onView(

View File

@ -0,0 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import org.hamcrest.CoreMatchers
/**
* Implementation of Robot Pattern for the Privacy Settings > saved logins sub menu
*/
class SettingsSubMenuLoginsAndPasswordOptionsToSaveRobot {
fun verifySaveLoginsOptionsView() {
onView(ViewMatchers.withText("Ask to save"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
onView(ViewMatchers.withText("Never save"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
class Transition {
fun goBack(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition {
goBackButton().perform(ViewActions.click())
SettingsSubMenuLoginsAndPasswordRobot().interact()
return SettingsSubMenuLoginsAndPasswordRobot.Transition()
}
}
}
private fun goBackButton() =
onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up")))

View File

@ -65,6 +65,14 @@ class SettingsSubMenuLoginsAndPasswordRobot {
SettingsTurnOnSyncRobot().interact() SettingsTurnOnSyncRobot().interact()
return SettingsTurnOnSyncRobot.Transition() return SettingsTurnOnSyncRobot.Transition()
} }
fun saveLoginsAndPasswordsOptions(interact: SettingsSubMenuLoginsAndPasswordOptionsToSaveRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordOptionsToSaveRobot.Transition {
fun saveLoginsAndPasswordButton() = onView(ViewMatchers.withText("Save logins and passwords"))
saveLoginsAndPasswordButton().click()
SettingsSubMenuLoginsAndPasswordOptionsToSaveRobot().interact()
return SettingsSubMenuLoginsAndPasswordOptionsToSaveRobot.Transition()
}
} }
} }

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
@ -29,6 +30,11 @@ class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot {
fun tapSetupLater() = onView(ViewMatchers.withText("Later")).perform(ViewActions.click()) fun tapSetupLater() = onView(ViewMatchers.withText("Later")).perform(ViewActions.click())
fun verifySavedLoginFromPrompt() = mDevice.waitNotNull(Until.findObjects(By.text("test@example.com")))
fun verifyNotSavedLoginFromPromt() = onView(ViewMatchers.withText("test@example.com"))
.check(ViewAssertions.doesNotExist())
class Transition { class Transition {
fun goBack(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition { fun goBack(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit): SettingsSubMenuLoginsAndPasswordRobot.Transition {
goBackButton().perform(ViewActions.click()) goBackButton().perform(ViewActions.click())