Giter VIP home page Giter VIP logo

dappeteer's Introduction

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.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.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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.