5.2.1 • Published 4 months ago

@chainsafe/dappeteer v5.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

dAppeteer

E2E testing for dApps using Puppeteer + MetaMask

Installation

$ npm install -s @chainsafe/dappeteer
$ yarn add @chainsafe/dappeteer

Usage

import dappeteer from '@chainsafe/dappeteer';

async function main() {
  const { metaMask, browser } = await dappeteer.bootstrap();

  // create a new page and visit your dapp
  const dappPage = browser.newPage();
  await dappPage.goto('http://my-dapp.com');

  // you can change the network if you want
  await metaMask.switchNetwork('goerli');

  // do something in your dapp that prompts MetaMask to add a Token
  const addTokenButton = await dappPage.$('#add-token');
  await addTokenButton.click();
  // instruct MetaMask to accept this request
  await metaMask.acceptAddToken();

  // do something that prompts MetaMask to confirm a transaction
  const payButton = await dappPage.$('#pay-with-eth');
  await payButton.click();

  // 🏌
  await metaMask.confirmTransaction();
}

main();

Usage with Snaps

import dappeteer from '@chainsafe/dappeteer';
import { exec } from "child_process";

async function buildSnap(): Promise<string> {
  console.log(`Building my-snap...`);
  await new Promise((resolve, reject) => {
    exec(`cd ./my-snap && npx mm-snap build`, (error, stdout) => {
      if (error) {
        reject(error);
        return;
      }
      resolve(stdout);
    });
  });

  return "./my-snap";
}

async function main() {
  // you need to have a webpage open to interact with MetaMask, you can also visit a dApp page
  const dappPage = browser.newPage();
  await dappPage.goto('http://example.org/');

  // build your local snap
  const builtSnapDir = await buildSnap()

  // setup dappateer and install your snap
  const { snapId, metaMask, dappPage } = await dappeteer.initSnapEnv({
    snapIdOrLocation: builtSnapDir
  });

  // invoke a method from your snap that promps users with approve/reject dialog
  metaMask.snaps.invokeSnap(dappPage, snapId, "my-method")

  // instruct MetaMask to accept this request
  await metaMask.snaps.acceptDialog();

  // get the notification emitter and the promise that will receive the notifications
  const emitter = await metaMask.snaps.getNotificationEmitter();
  const notificationPromise = emitter.waitForNotification();

  // do something that prompts you snap to emit notifications
  await metaMask.snaps.invokeSnap(dappPage, snapId, "notify");

  // Make sure the notification promise has resolved
  await notificationPromise;

  // You can now read the snap notifications and run tests against them
  const notifications = await metaMask.snaps.getAllNotifications();
}

main();
5.2.1

4 months ago

5.1.1

12 months ago

5.1.0-82922ec

1 year ago

5.2.0

11 months ago

5.0.1-774958e

1 year ago

4.2.0-1fb43bd

1 year ago

5.0.0-a5acd5c

1 year ago

5.0.1-f3041fe

1 year ago

4.2.0-2d66fba

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

4.2.0-a11e1ac

1 year ago

5.0.0-64340b1

1 year ago

4.2.0-23a0121

1 year ago

4.2.0-27156f7

1 year ago

4.1.1-bf8499d

1 year ago

4.2.0-58d01f2

1 year ago

4.2.0-bbc1374

1 year ago

4.2.0-a20d0e1

1 year ago

4.2.0-0f365a2

1 year ago

4.2.0-54b2f1d

1 year ago

4.1.1-e32457f

1 year ago

4.2.0-61978c2

1 year ago

4.1.1-970854d

1 year ago

4.2.0-ee4a513

1 year ago

4.2.0-49a646f

1 year ago

4.1.1-1e3a69f

1 year ago

4.2.0-225efaa

1 year ago

4.1.1-814b69b

1 year ago

4.1.0

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

4.2.0-36e7ccb

1 year ago

4.2.0-1914169

1 year ago

4.2.0-ec7e492

1 year ago

4.0.3-rc.2

1 year ago

4.0.3-rc.1

1 year ago

4.2.0-5ea28fe

1 year ago

3.0.0

2 years ago

4.0.0-rc.1

1 year ago

4.0.0-rc.0

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

3.0.0-rc.0

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.0

2 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago