Web3 dApp testing with a MetaMask equivalent headless wallet, using Playwright or Selenium WebDriver —no extension popups
- Create comprehensive E2E tests for your dApps, including real blockchain transactions
- All wallet actions are pre-approved by default, eliminating the need for user interaction
- All wallet interactions are headless, meaning, no user interaction is required. You should be testing your dApp, not the wallet
npm install -D @assert-equals/headless-walletimport{test}from"@playwright/test";import{HeadlessWalletServer,setupHeadlessWallet}from"@assert-equals/headless-wallet";letserver: HeadlessWalletServer;test.beforeEach(async({ page })=>{// MetaMask test seed https://github.com/MetaMask/metamask-extension/blob/v12.8.1/test/e2e/seeder/ganache.tsconstmnemonic: string="phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent";constport: number=8001;server=newHeadlessWalletServer({ mnemonic, port });awaitserver.start();awaitsetupHeadlessWallet({ page, port });});test.afterEach(async()=>{awaitserver.stop();});test("Metamask Wallet Test Dapp",async({ page })=>{awaitpage.goto("https://metamask.github.io/test-dapp/");awaitexpect(page.getByText("Name: Headless Wallet")).toBeVisible();});import{HeadlessWalletServer,setupHeadlessWallet}from"@assert-equals/headless-wallet";import{Builder,Browser,WebDriver,By,until}from"selenium-webdriver";import{Options}from"selenium-webdriver/chrome";(asyncfunctiontest(){constserver: HeadlessWalletServer=newHeadlessWalletServer({mnemonic: ""});awaitserver.start();constoptions: Options=newOptions();options.enableBidi();letdriver: WebDriver=awaitnewBuilder().forBrowser(Browser.CHROME).setChromeOptions(options).build();try{awaitsetupHeadlessWallet({ driver });awaitdriver.get("https://metamask.github.io/test-dapp/");constproviderName=awaitdriver.findElement(By.css("#activeProviderName"));awaitdriver.wait(until.elementTextContains(providerName,"Headless Wallet"),1000);}finally{awaitdriver.quit();awaitserver.stop();}})();Note: This setup will execute actual transactions on the blockchain without user intervention using the provided Mnemonic Phrase.
