From 777aaa6f01bff6df292ad6442f29b613f6e6e1b1 Mon Sep 17 00:00:00 2001 From: Harry Date: Tue, 20 Aug 2024 08:58:15 +0700 Subject: [PATCH] test: work around if token is invalid --- .../login-with-passwordless/AuthServicePage.ts | 17 +++++++++++++++++ .../login-with-passwordless/auth-case-3.test.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/authservice/login-with-passwordless/AuthServicePage.ts b/authservice/login-with-passwordless/AuthServicePage.ts index 362d407..e78f650 100644 --- a/authservice/login-with-passwordless/AuthServicePage.ts +++ b/authservice/login-with-passwordless/AuthServicePage.ts @@ -54,6 +54,23 @@ export class AuthServicePage { }); await this.page.locator(`xpath=.//input[@data-test='single-input']`).first().type(token); + + await delay(2000); + if (await this.page.locator('text="Invalid OTP, please try again"').isVisible()) { + await this.page.locator(`xpath=.//input[@data-test='single-input']`).last().click(); + + for (let index = 0; index < 6; index++) { + await this.page.keyboard.press("Delete"); + } + + const newToken = speakeasy.totp({ + secret, + encoding: "base32", + step: 30, + }); + + await this.page.locator(`xpath=.//input[@data-test='single-input']`).first().type(newToken); + } } async setupAuthenticator() { diff --git a/authservice/login-with-passwordless/auth-case-3.test.ts b/authservice/login-with-passwordless/auth-case-3.test.ts index c5bc81b..ee47a28 100644 --- a/authservice/login-with-passwordless/auth-case-3.test.ts +++ b/authservice/login-with-passwordless/auth-case-3.test.ts @@ -8,7 +8,7 @@ import { LoginPage } from "./LoginPage"; const passwordTestingFactor = "Testing@123"; test.describe.serial("Passwordless Login scenarios", () => { - test.setTimeout(90000); + test.setTimeout(120000); test("Login email passwordless case 3, mandatory MFA then setup 2FA @mandatorymfa", async ({ page, browser }) => { const testEmail = generateEmailWithTag();