Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mntor-3138 - Verify that the user can purchase the plus subscription with a PayPal account #4615

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env-dist
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ E2E_TEST_ACCOUNT_PASSWORD=
E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES=
E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED=

E2E_TEST_PAYPAL_LOGIN =
E2E_TEST_PAYPAL_PASSWORD =

# Monitor Premium features
# Link to start user on the subscription process. PREMIUM_ENABLED must be set to `true`.
FXA_SUBSCRIPTIONS_URL=https://accounts.stage.mozaws.net/subscriptions
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/e2e_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
E2E_TEST_ACCOUNT_PASSWORD: ${{ secrets.E2E_TEST_ACCOUNT_PASSWORD }}
E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES }}
E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED }}
E2E_TEST_PAYPAL_LOGIN: ${{ secrets.E2E_TEST_PAYPAL_LOGIN }}
E2E_TEST_PAYPAL_PASSWORD: ${{ secrets.E2E_TEST_PAYPAL_PASSWORD }}
ADMINS: ${{ secrets.ADMINS }}
FXA_ENABLED: true
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/e2e_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES }}
E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED }}
E2E_TEST_ACCOUNT_PASSWORD: ${{ secrets.E2E_TEST_ACCOUNT_PASSWORD }}
E2E_TEST_PAYPAL_LOGIN: ${{ secrets.E2E_TEST_PAYPAL_LOGIN }}
E2E_TEST_PAYPAL_PASSWORD: ${{ secrets.E2E_TEST_PAYPAL_PASSWORD }}
ADMINS: ${{ secrets.ADMINS }}
FXA_ENABLED: true
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}
Expand Down
85 changes: 84 additions & 1 deletion src/e2e/pages/purchasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* 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/. */

import { Locator, Page, expect } from "@playwright/test";
import { BrowserContext, Locator, Page, expect } from "@playwright/test";
import { removeUnicodeChars } from "../utils/helpers";
import { DashboardPage } from "./dashBoardPage";

export class PurchasePage {
readonly page: Page;
Expand All @@ -17,6 +18,7 @@ export class PurchasePage {
readonly returnToDashboardButton: Locator;
readonly goToNextStep: Locator;
readonly planDetails: Locator;
readonly paypalButton: Locator;

constructor(page: Page) {
this.page = page;
Expand All @@ -37,6 +39,7 @@ 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);
}

async fillOutStripeCardInfo() {
Expand Down Expand Up @@ -68,6 +71,42 @@ export class PurchasePage {
await frame.fill(".InputElement[name=postal]", "77777");
}

async fillOutPaypalInfo(context: BrowserContext) {
const emailToUse = process.env.E2E_TEST_PAYPAL_LOGIN as string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) The paypal email and password can go in the constructor properties

const pwdToUse = process.env.E2E_TEST_PAYPAL_PASSWORD as string;
expect(emailToUse).not.toBeUndefined();
expect(pwdToUse).not.toBeUndefined();

//away from mozilla
const pagePromise = context.waitForEvent("page");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

await this.paypalButton.click();
const newPage = await pagePromise;
await newPage.waitForLoadState();
await newPage.waitForURL(/.*paypal\.com\/checkoutnow.*/);

const emailPrompt = newPage.locator("#email");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wanted to confirm, are these id's the same when you go through the flow in prod as well?

await expect(emailPrompt).toBeVisible();

await emailPrompt.fill(emailToUse);
const nextButton = newPage.locator("#btnNext");
if (await nextButton.isVisible()) {
await newPage.locator("#btnNext").click();
await newPage.waitForSelector("#password", { state: "visible" });
}
const pwdInput = newPage.locator("#password");
await expect(pwdInput).toBeVisible();
await pwdInput.fill(pwdToUse);

await newPage.locator("#btnLogin").click();
await newPage.waitForURL(/^(?!.*checkoutnow).*/);

const saveAndContinue = newPage.locator("#consentButton");
await expect(saveAndContinue).toBeVisible();
await saveAndContinue.click();

//back to mozilla
}

async verifyMonthlyPlanDetails() {
await this.subscriptionHeader.waitFor();
const planDetails = removeUnicodeChars(
Expand All @@ -86,4 +125,48 @@ export class PurchasePage {
`${process.env.E2E_TEST_ENV === "prod" ? "yearly" : "every 2 months"}`,
);
}

async gotoPurchaseFromDashboard(
dashboardPage: DashboardPage,
yearly: boolean,
) {
// navigate to subscription
await dashboardPage.open();
await dashboardPage.subscribeButton.click();

// verify user purchase choices
await expect(dashboardPage.subscribeDialogCloseButton).toBeVisible();
await expect(dashboardPage.yearlyMonthlyTablist).toBeVisible();
await dashboardPage.yearlyTab.click();
await expect(
dashboardPage.subscribeDialogSelectYearlyPlanLink,
).toBeVisible();

await dashboardPage.monthlyTab.click();
await expect(
dashboardPage.subscribeDialogSelectMonthlyPlanLink,
).toBeVisible();

if (yearly) {
await dashboardPage.yearlyTab.click();
await dashboardPage.subscribeDialogSelectYearlyPlanLink.click();
} else {
await dashboardPage.monthlyTab.click();
await dashboardPage.subscribeDialogSelectMonthlyPlanLink.click();
}
await this.subscriptionHeader.waitFor();
}

async postPaymentPageCheck(dashboardPage: DashboardPage) {
await this.page.getByText("Subscription confirmation").waitFor();
// navigate to confirmation
await this.getStartedButton.click();
await this.goToNextStep.click();
// confirm successful payment
await dashboardPage.plusSubscription.waitFor({
state: "attached",
timeout: 5000,
});
await expect(dashboardPage.plusSubscription).toBeVisible();
}
}
46 changes: 46 additions & 0 deletions src/e2e/specs/purchase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,50 @@ test.describe(`${process.env.E2E_TEST_ENV} - Breach Scan, Monitor Plus Purchase
});
await expect(dashboardPage.plusSubscription).toBeVisible();
});

test("Verify that the user can purchase the plus subscription with a PayPal account - yearly", async ({
purchasePage,
dashboardPage,
context,
}) => {
test.skip(
process.env.E2E_TEST_ENV === "production",
"payment method test not available in production",
);
// link to testrail case
test.info().annotations.push({
type: "testrail",
description:
"https://testrail.stage.mozaws.net/index.php?/cases/view/2463628",
});

await purchasePage.gotoPurchaseFromDashboard(dashboardPage, true);
// fill out subscription payment
await purchasePage.authorizationCheckbox.check();
await purchasePage.fillOutPaypalInfo(context);
await purchasePage.postPaymentPageCheck(dashboardPage);
});

test("Verify that the user can purchase the plus subscription with a PayPal account - monthly", async ({
purchasePage,
dashboardPage,
context,
}) => {
test.skip(
process.env.E2E_TEST_ENV === "production",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ignore my previous comment about the production id's

"payment method test not available in production",
);
// link to testrail case
test.info().annotations.push({
type: "testrail",
description:
"https://testrail.stage.mozaws.net/index.php?/cases/view/2463628",
});

await purchasePage.gotoPurchaseFromDashboard(dashboardPage, false);
// fill out subscription payment
await purchasePage.authorizationCheckbox.check();
await purchasePage.fillOutPaypalInfo(context);
await purchasePage.postPaymentPageCheck(dashboardPage);
});
});
Loading