UNPKG

@finn_gal/patchright-wallet-mock-ts

Version:

Mock Web3 Browser wallets, like Metamask, in Patchright tests.

35 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const playwright_1 = require("playwright"); const index_1 = require("../index"); const accounts_1 = require("viem/accounts"); const chains_1 = require("viem/chains"); const viem_1 = require("viem"); /** * Example of basic usage of the library */ async function main() { const browser = await playwright_1.chromium.launch({ headless: false, }); const context = await browser.newContext(); const page = await context.newPage(); // Install the mock wallet await (0, index_1.installMockWallet)({ page, account: (0, accounts_1.privateKeyToAccount)("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"), defaultChain: chains_1.mainnet, transports: { [chains_1.mainnet.id]: (0, viem_1.http)() }, debug: true, }); // Navigate to a dApp await page.goto("https://metamask.github.io/test-dapp/"); // Click the connect button await page.getByRole("button", { name: "USE METAMASK" }).click(); // Keep the browser open for demonstration await new Promise((resolve) => setTimeout(resolve, 30000)); await browser.close(); } // Run the example main().catch(console.error); //# sourceMappingURL=basic-usage.js.map