Socket
Book a DemoInstallSign in
Socket

@nodefactory/dappeteer

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodefactory/dappeteer

E2E testing for dApps using Puppeteer + MetaMask

2.0.1
latest
Source
npmnpm
Version published
Weekly downloads
1
-75%
Maintainers
3
Weekly downloads
 
Created
Source

dAppeteer

E2E testing for dApps using Puppeteer + MetaMask

Installation

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

Usage

import puppeteer from 'puppeteer';
import dappeteer from '@nodefactory/dappeteer';

async function main() {
  const browser = await dappeteer.launch(puppeteer);
  const metamask = await dappeteer.setupMetamask(browser);

  // you can change the network if you want
  await metamask.switchNetwork('ropsten');

  // go to a dapp and do something that prompts MetaMask to confirm a transaction
  const page = await browser.newPage();
  await page.goto('http://my-dapp.com');
  const payButton = await page.$('#pay-with-eth');
  await payButton.click();

  // 🏌
  await metamask.confirmTransaction();
}

main();

API

  • dappeteer.launch(puppeteer[, launchOptions]): returns an instance of browser, same as puppeteer.launch, but it also installs the MetaMask extension. It supports all the regular puppeteer.launch options as a second argument with the addition of:

    • metamaskVersion: Metamask plugin version (by default it uses latest)
  • dappeteer.setupMetamask(browser[, {seed, password}]): returns a promise that resolves to an object that allows you to interact with MetaMask by using the following methods:

    • metamask.switchAccount(accountIndex): it commands MetaMask to switch to a different account, by passing the index/position of the account in the accounts list.

    • metamask.importPK(privateKey): it commands MetaMask to import an private key. It can only be used while you haven't signed in yet, otherwise it throws.

    • metamask.lock(): signs out from MetaMask. It can only be used if you arelady signed it, otherwise it throws.

    • metamask.unlock([password]): it unlocks the MetaMask extension. It can only be used in you locked/signed out before, otherwise it throws. The password is optional, it defaults to password1234.

    • metamask.switchNetwork(networkName): it changes the current selected network. networkName can take the following values: "main", "ropsten", "rinkeby", "kovan", "localhost".

    • metamask.addNetwork({ networkName, rpc, chainId[, symbol, explorer]}): it adds a custom network to MetaMask.

    • metamask.confirmTransaction([{ gas, gasLimit }]): commands MetaMask to submit a transaction. For this to work MetaMask has to be in a transaction confirmation state (basically promting the user to submit/reject a transaction). You can (optionally) pass an object with gas and/or gasLimit, by default they are 20 and 50000 respectively.

    • metamask.sign(): commands MetaMask to sign a message. For this to work MetaMask must be in a sign confirmation state.

    • metamask.approve(): enables the app to connect to MetaMask account in privacy mode

Keywords

e2e

FAQs

Package last updated on 01 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.