UNPKG

@dfinity/internet-identity-playwright

Version:

A Playwright library to simplify the integration of Internet Identity authentication in E2E tests.

60 lines (59 loc) 2.87 kB
import { type Browser, type BrowserContext, type Page } from '@playwright/test'; /** * A page object to test Internet Identity. */ export declare class InternetIdentityPage { private readonly page; private readonly browser; private readonly context; /** * Creates an instance of InternetIdentityPage. * * @param {Object} params - The parameters for the constructor. * @param {Page} params.page - The Page instance to interact with Internet Identity a single tab in a Browser. * @param {BrowserContext} params.context - The isolated BrowserContext instance provided by Playwright, created for each test. * @param {Browser} params.browser - The browser launched by Playwright. */ constructor({ page, context, browser }: { page: Page; context: BrowserContext; browser: Browser; }); /** * Waits until the Internet Identity page is ready. * * @param {Object} params - The parameters for the waitReady method. * @param {string} params.url - The root URL of the Internet Identity page. e.g. https://identity.internetcomputer.org, http://localhot:4973 or http://127.0.0.1:5987 * @param {string} [params.canisterId] - An optional canister ID. If provided, will be added to the url parameter. * @param {number} [params.timeout] - } [params.timeout] - An optional timeout period in milliseconds for the function to wait until Internet Identity is mounted. Defaults to 60000 milliseconds. * @returns {Promise<void>} A promise that resolves when the page is ready. */ waitReady: ({ url: rootUrl, canisterId, timeout }: { url: string; canisterId?: string | undefined; timeout?: number | undefined; }) => Promise<void>; /** * Signs in and create a new user. * * @param {Object} [params] - The optional arguments for the sign-in method. * @param {string} [params.selector] - The selector for the login button. Defaults to [data-tid=login-button]. * @param {boolean} [params.captcha] - Set to true if the II login flow requires a captcha. * @returns {Promise<number>} A promise that resolves to the new identity number. */ signInWithNewIdentity: (params?: { selector?: string; captcha?: boolean; }) => Promise<number>; /** * Signs in with an existing identity. * @param {Object} params - The parameters for the sign-in method. * @param {string} [params.selector] - The selector for the login button. Defaults to [data-tid=login-button]. * @param {number} params.identity - The identity number. * @returns {Promise<void>} A promise that resolves when the sign-in process is complete. */ signInWithIdentity: ({ selector, identity }: { selector?: string | undefined; identity: number; }) => Promise<void>; }