npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jduttweiler/dappeteer

v1.0.2

Published

E2E testing for dApps using Puppeteer + MetaMask

Downloads

2

Readme

dAppeteer

E2E testing for dApps using Puppeteer + MetaMask

Installation

$ npm install -s dappeteer

Usage

import puppeteer from 'puppeteer'
import dappeteer from 'dappeteer'

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

  // create or import an account
  // await metamask.createAccount()
  await metamask.importAccount('already turtle birth enroll since...')

  // 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 two extra ones:

    • metamaskPath: Path to the MetaMask extension (by default it uses the one bundled)

    • extensionUrl: URL of the MetaMask extension, by default it is chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/popup.html but if you use a different version you might need to change it use the right extension id.

  • dappeteer.getMetaMask(browser): returns a promise that resolves to an object that allows you to interact with MetaMask by using the following methods:

    • metamask.createAccount([password]): it commands MetaMask to create a new account, it resolves when it's done. It can only be used while you haven't signed in yet, otherwise it throws. The password is optional, it defaults to password1234.

    • metamask.importAccount(seed[, password]): it commands MetaMask to import an account, you need to provide the twelve words seed. It can only be used while you haven't signed in yet, otherwise it throws. The password is optional, it defaults to password1234.

    • 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(url): 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