@walletwright/core
v0.2.1
Published
Playwright wallet automation for MetaMask, Phantom, Rabby, Solflare, and Slush across EVM, Solana, and Sui. Connect and sign in real browser extensions.
Maintainers
Readme
walletwright
Playwright wallet automation for MetaMask (EVM + Solana), Phantom (EVM + Solana), Rabby (EVM), Solflare (Solana), and Slush (Sui). It connects and signs in the real browser extensions.
- Real extensions, no mocks: MetaMask, Phantom, Rabby, Solflare, and Slush on their current versions.
- EVM, Solana, and Sui from one fixture:
window.ethereum,window.phantom.solana, and the Sui Wallet Standard. - Onboard a wallet once into a cached profile, then unlock it and drive the popups in every test.
- Plain
@playwright/testfixtures, so there is no framework lock-in.
Install
pnpm add -D @walletwright/core @playwright/test
pnpm exec playwright install chromium@playwright/test is a peer dependency.
1. Describe the wallet
// wallet-setup.ts
import type { WalletSetup } from "@walletwright/core";
export const metamask: WalletSetup = {
wallet: "metamask",
seedPhrase: "test test test test test test test test test test test junk",
password: "Tester@1234",
};Phantom and Slush reject the famous public test seed (Phantom flags it as malicious and drops the connection). Use a fresh, unfunded mnemonic for those two.
2. Build the cache (once)
walletwright cache --setup ./wallet-setup.ts
# or: walletwright cache --wallet metamask --seed "YOUR_SEED_HERE" --password "YOUR_PASSWORD_HERE"Or call it from code, which works well as a Playwright global setup:
import { buildCache } from "@walletwright/core";
import { metamask } from "./wallet-setup.ts";
await buildCache(metamask);3. Write a test
import { createWalletFixtures } from "@walletwright/core";
import { metamask } from "./wallet-setup.ts";
const test = createWalletFixtures(metamask);
const { expect } = test;
test("connect and sign", async ({ page, wallet }) => {
await page.goto("/");
await page.getByRole("button", { name: "Connect" }).click();
await wallet.connectToDapp();
await expect(page.locator("#account")).toContainText("0x");
await page.getByRole("button", { name: "Sign" }).click();
await wallet.confirmSignature();
});The wallet fixture:
| Method | Description |
| ----------------------- | --------------------------------------------------------------------------------- |
| connectToDapp() | Approve a pending connection popup. Resolves quietly if the wallet auto-approved. |
| confirmSignature() | Approve a pending signature popup. |
| approve({ optional }) | Approve any pending popup, whether connect, sign, or a transaction. |
| extensionId | The loaded extension id. |
The same two calls drive every chain. A Phantom test can connect and sign on
window.phantom.ethereum and then on window.phantom.solana; a Slush test does the same on Sui. See
apps/demo for a full example.
Without fixtures
import { launchWallet } from "@walletwright/core";
const { context, wallet } = await launchWallet(metamask);
const page = await context.newPage();
// drive the page and the wallet here
await context.close();Requirements and notes
- Headless works for Phantom and Rabby, whose approval windows surface as pages that way.
MetaMask, Solflare and Slush need a real window, so default those suites to headed and give CI a
virtual display:
xvfb-run --auto-servernum pnpm exec playwright test. - MetaMask is pinned to a known-good version (override it with
WalletSetup.version). Phantom, Rabby, Solflare, and Slush always use the current Web Store build. - The cache lives in
.walletwright/(override it withWalletSetup.cacheDir). Add that directory to.gitignore.
License
MIT
