Skip to main content

Overview

The createWalletTest function creates a Playwright test configured with one or more wallet extensions. It returns a test function with custom fixtures for wallet interaction.

Function signature

function createWalletTest<const T extends readonly WalletConfig[]>(
  options?: ChromaTestOptions<T>
): TestType<WalletFixtures<ConfiguredWallets<T>>, WalletWorkerFixtures>

ChromaTestOptions type

The options object accepts the following parameters:
wallets
WalletConfig[]
Array of wallet configurations to load. Defaults to [{ type: 'polkadot-js' }] if not specified.Each WalletConfig has:
  • type: 'polkadot-js' | 'talisman' | 'metamask'
  • downloadUrl: Optional custom download URL for the extension
headless
boolean
default:"false"
Whether to run the browser in headless mode.
slowMo
number
default:"150"
Slows down operations by the specified milliseconds. Useful for debugging.

Return value

Returns a Playwright test function with extended fixtures:
page
ExtendedPage
Test-scoped page fixture with extension context
wallets
ConfiguredWallets<T>
Test-scoped wallet instances based on your configuration
walletContext
BrowserContext
Worker-scoped browser context (persists across tests)
walletExtensionIds
Map<string, string>
Worker-scoped map of wallet type to extension ID

Examples

import { createWalletTest } from '@avalix/chroma'

const test = createWalletTest()

test('can connect to Polkadot-JS', async ({ page, wallets }) => {
  // wallets['polkadot-js'] is available
  await wallets['polkadot-js'].authorize()
})

Type safety

The function uses TypeScript const assertions to infer the exact wallet types you’ve configured:
const test = createWalletTest({
  wallets: [{ type: 'talisman' }] as const,
})

test('example', async ({ wallets }) => {
  // TypeScript knows only wallets.talisman exists
  await wallets.talisman.authorize() // ✅
  await wallets['polkadot-js'].authorize() // ❌ Type error
})

Worker-scoped fixtures

The browser context and extension IDs are worker-scoped, meaning they persist across all tests in a worker process. This improves performance by avoiding repeated extension loading.
The page and wallets fixtures are test-scoped and recreated for each test, but they reuse the worker-scoped browser context.

Build docs developers (and LLMs) love