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

fix: 2FA OTP flaky test #13583

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions apps/web/playwright/login.2fa.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ test.describe("2FA Tests", async () => {
await fillOtp({ page, secret: "123456", noRetry: true });
await expect(page.locator('[data-testid="error-submitting-code"]')).toBeVisible();

await removeOtpInput(page);

Comment on lines +45 to +46
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing last digit to prevent auto submitting of form while we fill the correct OTP in the next line

await fillOtp({
page,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -162,6 +164,14 @@ test.describe("2FA Tests", async () => {
});
});

async function removeOtpInput(page: Page) {
await page.locator('input[name="2fa6"]').waitFor({ state: "visible", timeout: 60_000 });
Udit-takkar marked this conversation as resolved.
Show resolved Hide resolved

// Remove one OTP input
await page.locator('input[name="2fa6"]').focus();
await page.keyboard.press("Backspace");
}

async function fillOtp({ page, secret, noRetry }: { page: Page; secret: string; noRetry?: boolean }) {
let token = authenticator.generate(secret);
if (!noRetry && !totpAuthenticatorCheck(token, secret)) {
Expand Down
Loading