Skip to content

Commit

Permalink
Merge pull request #4837 from mozilla/mntor-3420-new
Browse files Browse the repository at this point in the history
Mntor-3420: addressed failing test cases
  • Loading branch information
mozilloid authored Jul 19, 2024
2 parents d84a0f1 + d1fd653 commit 9c4bebb
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 86 deletions.
4 changes: 3 additions & 1 deletion src/e2e/pages/dashBoardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ export class DashboardPage {
this.faqsPageLink = page.getByTitle("Frequently asked questions").first();

//upsell button
this.upsellScreenButton = page.getByText(/Lets (keep going|fix it)/);
this.upsellScreenButton = page
.locator("a")
.getByText(/Lets (keep going|fix it)/);
this.overviewCard = page.locator("[class*='DashboardTopBanner_container']");
this.overviewCardSummary = page.locator(
"[aria-label='Dashboard summary'] > div > p",
Expand Down
12 changes: 10 additions & 2 deletions src/e2e/pages/landingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class LandingPage {
readonly monitorPlusTooltipText: Locator;
readonly closeTooltips: Locator;

// Landing-page-free-scan-cta experiment enabled
readonly emailInputPrompt: Locator;

constructor(page: Page) {
this.page = page;
this.freeMonitoringTooltipTrigger = page
Expand Down Expand Up @@ -166,7 +169,7 @@ export class LandingPage {
has: this.reuseEmailInputField,
});
this.couldBeAtRiskFormInputSubmitButton = this.couldBeAtRiskSection.filter({
has: this.reuseButton,
hasText: "Get free scan",
});
this.couldBeAtRiskGraphic = page.locator(
'img[data-testid="leaked-password-example"]',
Expand All @@ -184,7 +187,7 @@ export class LandingPage {
has: this.reuseEmailInputField,
});
this.getStartedScanFormSubmitButton = this.getStartedScanSection.filter({
has: this.reuseButton,
hasText: "Get free scan",
});

// choose your level of protection section
Expand Down Expand Up @@ -235,6 +238,11 @@ export class LandingPage {
this.startFreeMonitoringButton = page.getByRole("button", {
name: "Start free monitoring",
});

// Landing-page-free-scan-cta experiment enabled
this.emailInputPrompt = page.locator(
'//label[text()="Enter your email address to check for data breach exposures and sites selling your info."]',
);
}

async open() {
Expand Down
5 changes: 4 additions & 1 deletion src/e2e/pages/purchasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class PurchasePage {
this.returnToDashboardButton = page.getByLabel("Return to dashboard");
this.goToNextStep = page.getByLabel("Go to next step");
this.planDetails = page.locator(".plan-details-description");
this.paypalButton = page.getByTitle("PayPal").nth(1);
this.paypalButton = this.page
.frameLocator('//iframe[@title="PayPal"]')
.first()
.locator('div[role="link"]');
}

async fillOutStripeCardInfo() {
Expand Down
80 changes: 45 additions & 35 deletions src/e2e/specs/dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ test.describe(`${process.env.E2E_TEST_ENV} - Breaches Dashboard - Overview Card`
});

await dashboardPage.open();
await page.waitForURL("**/dashboard/**");

//get the number of exposures count
const overviewCardSummary =
Expand Down Expand Up @@ -719,40 +720,49 @@ test.describe(`${process.env.E2E_TEST_ENV} - Breaches Dashboard - Navigation`, (
});
});

test.describe(`${process.env.E2E_TEST_ENV} - Breaches Dashboard - Data Breaches`, () => {
test.beforeEach(async ({ landingPage, page, authPage }) => {
const emailToUse = process.env
.E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED as string;
const pwdToUse = process.env.E2E_TEST_ACCOUNT_PASSWORD as string;
expect(emailToUse).not.toBeUndefined();
expect(pwdToUse).not.toBeUndefined();
await forceLoginAs(emailToUse, pwdToUse, page, landingPage, authPage);
});

test("Verify that the High risk data breaches step is displayed correctly", async ({
dashboardPage,
dataBrokersPage,
page,
}) => {
test.info().annotations.push({
type: "testrail",
description:
"https://testrail.stage.mozaws.net/index.php?/cases/view/2463592",
// This test has inconsistent results - may need to rely on mocks.
test.describe.skip(
`${process.env.E2E_TEST_ENV} - Breaches Dashboard - Data Breaches`,
() => {
test.beforeEach(async ({ landingPage, page, authPage }) => {
const emailToUse = process.env
.E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED as string;
const pwdToUse = process.env.E2E_TEST_ACCOUNT_PASSWORD as string;
expect(emailToUse).not.toBeUndefined();
expect(pwdToUse).not.toBeUndefined();
await forceLoginAs(emailToUse, pwdToUse, page, landingPage, authPage);
});

await expect(dashboardPage.upsellScreenButton).toBeVisible();
await dashboardPage.upsellScreenButton.click();
await page.waitForURL(/.*\/data-broker-profiles\/view-data-brokers\/?/);
await expect(dataBrokersPage.forwardArrowButton).toBeVisible();
await dataBrokersPage.forwardArrowButton.click();
await page.waitForURL(/.*\/high-risk-data-breaches.*/);
const highRiskDataBreachLi = page.locator(
'li:has(div:has-text("High risk data breaches"))',
);
await expect(highRiskDataBreachLi).toBeVisible();
await expect(highRiskDataBreachLi).toHaveAttribute("aria-current", "step");
await expect(
highRiskDataBreachLi.locator("div").getByText("High risk data breaches"),
).toBeVisible();
});
});
test("Verify that the High risk data breaches step is displayed correctly", async ({
dashboardPage,
dataBrokersPage,
page,
}) => {
test.info().annotations.push({
type: "testrail",
description:
"https://testrail.stage.mozaws.net/index.php?/cases/view/2463592",
});

await expect(dashboardPage.upsellScreenButton).toBeVisible();
await dashboardPage.upsellScreenButton.click();
await page.waitForURL(/.*\/data-broker-profiles\/view-data-brokers\/?/);
await expect(dataBrokersPage.forwardArrowButton).toBeVisible();
await dataBrokersPage.forwardArrowButton.click();
await page.waitForURL(/.*\/high-risk-data-breaches.*/);
const highRiskDataBreachLi = page.locator(
'li:has(div:has-text("High risk data breaches"))',
);
await expect(highRiskDataBreachLi).toBeVisible();
await expect(highRiskDataBreachLi).toHaveAttribute(
"aria-current",
"step",
);
await expect(
highRiskDataBreachLi
.locator("div")
.getByText("High risk data breaches"),
).toBeVisible();
});
},
);
119 changes: 78 additions & 41 deletions src/e2e/specs/landing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { test, expect } from "../fixtures/basePage.js";
import {
defaultScreenshotOpts,
emailInputShouldExist,
getVerificationCode,
} from "../utils/helpers.js";

Expand Down Expand Up @@ -41,8 +42,10 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page content`, (
await expect(landingPage.monitorHeroSubtitle).toHaveText(
"We scan to see if your phone number, passwords or home address have been leaked, and help you make it private again.",
);
await expect(landingPage.monitorHeroFormEmailInputField).toBeVisible();
await expect(landingPage.monitorHeroFormInputSubmitButton).toBeVisible();
if (await emailInputShouldExist(landingPage)) {
await expect(landingPage.monitorHeroFormEmailInputField).toBeVisible();
await expect(landingPage.monitorHeroFormInputSubmitButton).toBeVisible();
}
await expect(landingPage.monitorLandingMidHeading).toBeVisible();
});

Expand All @@ -57,8 +60,10 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page content`, (

await expect(landingPage.fixExposuresTitle).toBeVisible();
await expect(landingPage.fixExposuresSubtitle).toBeVisible();
await expect(landingPage.fixExposuresFormEmailInputField).toBeVisible();
await expect(landingPage.fixExposuresFormInputSubmitButton).toBeVisible();
if (await emailInputShouldExist(landingPage)) {
await expect(landingPage.fixExposuresFormEmailInputField).toBeVisible();
await expect(landingPage.fixExposuresFormInputSubmitButton).toBeVisible();
}
await expect(landingPage.fixExposuresGraphic).toBeVisible();
});

Expand All @@ -73,7 +78,9 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page content`, (

await expect(landingPage.couldBeAtRiskTitle).toBeVisible();
await expect(landingPage.couldBeAtRiskSubtitle).toBeVisible();
await expect(landingPage.couldBeAtRiskFormEmailInputField).toBeVisible();
if (await emailInputShouldExist(landingPage)) {
await expect(landingPage.couldBeAtRiskFormEmailInputField).toBeVisible();
}
await expect(landingPage.couldBeAtRiskFormInputSubmitButton).toBeVisible();
await expect(landingPage.couldBeAtRiskGraphic).toBeVisible();
});
Expand All @@ -88,7 +95,8 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page content`, (
});

await expect(landingPage.getStartedScanTitle).toBeVisible();
await expect(landingPage.getStartedScanFormEmailInputField).toBeVisible();
if (await emailInputShouldExist(landingPage))
await expect(landingPage.getStartedScanFormEmailInputField).toBeVisible();
await expect(landingPage.getStartedScanFormSubmitButton).toBeVisible();
});

Expand Down Expand Up @@ -130,8 +138,12 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page content`, (
});

await expect(landingPage.takeBackControlTitle).toBeVisible();
await expect(landingPage.takeBackControlFormEmailInputField).toBeVisible();
await expect(landingPage.takeBackControlFormSubmitButton).toBeVisible();
if (await emailInputShouldExist(landingPage)) {
await expect(
landingPage.takeBackControlFormEmailInputField,
).toBeVisible();
await expect(landingPage.takeBackControlFormSubmitButton).toBeVisible();
}
});

test("Observe footer section", async ({ landingPage }) => {
Expand Down Expand Up @@ -182,17 +194,30 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page content`, (
description:
"https://testrail.stage.mozaws.net/index.php?/cases/view/2463504",
});

await landingPage.monitorHeroFormEmailInputField.fill("invalid");
await landingPage.monitorHeroFormInputSubmitButton.click();
// Stays on same page
await expect(landingPage.monitorHeroFormEmailInputField).toBeVisible();

const randomEmail = `_${Date.now()}[email protected]`;
await landingPage.monitorHeroFormEmailInputField.fill(randomEmail);
await landingPage.monitorHeroFormInputSubmitButton.click();
await authPage.passwordInputField.waitFor();
await expect(authPage.passwordInputField).toBeVisible();
if (await emailInputShouldExist(landingPage)) {
///free-scan-cta experiment is off
await landingPage.monitorHeroFormEmailInputField.fill("invalid");
await landingPage.monitorHeroFormInputSubmitButton.click();
await expect(landingPage.monitorHeroFormEmailInputField).toBeVisible();

const randomEmail = `_${Date.now()}[email protected]`;
await landingPage.monitorHeroFormEmailInputField.fill(randomEmail);
await landingPage.monitorHeroFormInputSubmitButton.click();
await authPage.passwordInputField.waitFor();
await expect(authPage.passwordInputField).toBeVisible();
} else {
///free-scan-cta experiment is on
await landingPage.monitorHeroFormInputSubmitButton.click();
await authPage.emailInputField.waitFor({
state: "visible",
timeout: 10000,
});
const randomEmail = `_${Date.now()}[email protected]`;
await authPage.emailInputField.fill(randomEmail);
await authPage.continueButton.click();
await authPage.passwordInputField.waitFor();
await expect(authPage.passwordInputField).toBeVisible();
}
});

test('Verify manual/automatic removal "more info" tips from "Choose your level of protection" section', async ({
Expand Down Expand Up @@ -221,20 +246,27 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page Functionali
page,
authPage,
}) => {
// link to testrail case
test.info().annotations.push({
type: "testrail",
description:
"https://testrail.stage.mozaws.net/index.php?/cases/view/2463502",
});

// fill out free scan form
const randomEmail = `${Date.now()}[email protected]`;
await landingPage.monitorHeroFormEmailInputField.fill(randomEmail);
await landingPage.monitorHeroFormInputSubmitButton.click();
await page.waitForURL("**/oauth/**");

// complete registration form
if (await emailInputShouldExist(landingPage)) {
await landingPage.monitorHeroFormEmailInputField.fill(randomEmail);
await landingPage.monitorHeroFormInputSubmitButton.click();
await page.waitForURL("**/oauth/**");
} else {
await landingPage.monitorHeroFormInputSubmitButton.click();
await authPage.emailInputField.waitFor({
state: "visible",
timeout: 10000,
});
await authPage.emailInputField.fill(randomEmail);
await authPage.continueButton.click();
}
// continue with the common steps
await authPage.passwordInputField.fill(
process.env.E2E_TEST_ACCOUNT_PASSWORD as string,
);
Expand All @@ -243,12 +275,8 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page Functionali
);
await authPage.ageInputField.fill("31");
await authPage.continueButton.click();

// enter registration verification code
const vc = await getVerificationCode(randomEmail, page);
await authPage.enterVerificationCode(vc);

// verify dashboard redirect
const successUrl = process.env.E2E_TEST_BASE_URL + "/user/welcome";
expect(page.url()).toBe(successUrl);
});
Expand Down Expand Up @@ -298,24 +326,33 @@ test.describe(`${process.env.E2E_TEST_ENV} - Verify the Landing Page Functionali
"https://testrail.stage.mozaws.net/index.php?/cases/view/2463503",
});

// fill out free scan form
await landingPage.monitorHeroFormEmailInputField.fill(
process.env.E2E_TEST_ACCOUNT_EMAIL as string,
);
await landingPage.monitorHeroFormInputSubmitButton.click();
await page.waitForURL("**/oauth/**");
const existingEmail = process.env.E2E_TEST_ACCOUNT_EMAIL as string;

if (await emailInputShouldExist(landingPage)) {
// Scenario where the form is still used
await landingPage.monitorHeroFormEmailInputField.fill(existingEmail);
await landingPage.monitorHeroFormInputSubmitButton.click();
await page.waitForURL("**/oauth/**");
} else {
// Scenario where direct redirection happens
await landingPage.monitorHeroFormInputSubmitButton.click();
await authPage.emailInputField.waitFor({
state: "visible",
timeout: 10000,
});
await authPage.emailInputField.fill(existingEmail);
await authPage.continueButton.click();
}

// complete sign in form
await authPage.enterPassword();

// verify dashboard redirect
const successUrl =
process.env.E2E_TEST_BASE_URL +
`${
process.env.E2E_TEST_ENV === "local"
? "/user/welcome"
: "/user/dashboard"
}`;
(process.env.E2E_TEST_ENV === "local"
? "/user/welcome"
: "/user/dashboard");
expect(page.url()).toBe(successUrl);
});

Expand Down
14 changes: 8 additions & 6 deletions src/e2e/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,10 @@ export const forceLoginAs = async (
await page.context().clearCookies();
await landingPage.open();
await landingPage.goToSignIn();
let visible = true;
try {
await expect(authPage.useDifferentEmailButton).toBeVisible();
} catch {
visible = false;
}
await page
.locator("//input[@type='password'] | //div/input[@type='email']")
.waitFor({ state: "visible" });
const visible = await authPage.useDifferentEmailButton.isVisible();
if (visible) {
await authPage.useDifferentEmailButton.click();
await page.waitForURL(/^(?!.*signin).*/);
Expand All @@ -222,3 +220,7 @@ export const forceLoginAs = async (
await page.waitForURL("**/user/dashboard");
await expect(page).toHaveURL(/.*\/user\/dashboard.*/);
};

export async function emailInputShouldExist(landingPage: LandingPage) {
return 0 < (await landingPage.emailInputPrompt.count());
}

0 comments on commit 9c4bebb

Please sign in to comment.