@swapper-finance/sdk
Version:
JavaScript SDK form Swapper
47 lines (38 loc) • 1.55 kB
text/typescript
import { Page, expect } from "@playwright/test";
import { urlParams } from "../variables.playwright";
export async function loginPrivy(page: Page, email: string, otpCode: string) {
// Navigate to initial page
await page.goto(urlParams);
// Open the Privy wallet modal
await page.getByTestId("login-button").click();
const modal = page.locator("#privy-modal-content");
await expect(modal).toBeVisible({ timeout: 10000 });
// Fill in the email with typing delays
const emailInput = modal.locator("#email-input");
await emailInput.click();
for (const char of email) {
await emailInput.type(char, { delay: Math.random() * 150 + 50 });
}
await modal.locator('button:has-text("Submit")').click();
// Wait for first OTP field to render
await modal
.locator('input[name="code-0"]')
.waitFor({ state: "visible", timeout: 10000 });
if (otpCode.length !== 6) {
throw new Error(`OTP must be 6 digits, got ${otpCode.length}`);
}
// Fill in the 6 separate OTP inputs (code-0 … code-5) with typing delays
for (let index = 0; index < 6; index++) {
const selector = `input[name="code-${index}"]`;
const otpField = modal.locator(selector);
await otpField.click();
await otpField.type(String(otpCode[index]), {
delay: Math.random() * 150 + 50,
});
}
// Allow time login
await page.waitForTimeout(1000);
// Check if wallet view is visible
const walletHeader = page.getByText("Your wallet", { exact: true });
await expect(walletHeader).toBeVisible({ timeout: 10000 });
}