Giter Club home page Giter Club logo

dappeteer's Introduction

DEPRECATED - no longer actively maintained

You can find active and updated fork at https://github.com/chainsafe/dappeteer


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

dappeteer's People

Contributors

abarmat avatar cazala avatar fleupold avatar fmiras avatar kivutar avatar lionseal avatar minheq avatar mpetrunic avatar nicosantangelo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dappeteer's Issues

ES6 compatibility issue

I have a create react app. Normally running npm test runs all of our test specs properly, but when I add the file from your readme as a test file, this is the error that i get:

` FAIL src/test/E2ETestingSuite.spec.js
● Test suite failed to run

/Users/pranavpillai/Consensys/ujo-portal/ujo-portal/node_modules/dappeteer/index.js:7
  launch: async function launch (puppeteer, options = {}) {
                ^^^^^^^^

SyntaxError: Unexpected token function

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
  at Object.<anonymous> (src/test/E2ETestingSuite.spec.js:20:180)`

It seems like we’re facing an ES6 compilation error. Do you have to configure your jest in any way to preprocess code in the node modules?

Feature to wait for "Tx mined" UI popup to be observed

It would be nice to have some helper method to wait for this notification to be observed. In our integration tests we don't want to have to write blockchain connectors and methods to verify if some transaction was mined or not and would rather be able to detect this via metamask UI elements.

Dappeteer + dolphin

Does it possible to use it with the Dolphin anty browser? Something goes wrong when I am trying

Gas/gasLimit doesn't work

When I added the parameters(gas, gasLimit) to the function metamask.confirmTransaction ([{gas: 10, gasLimit: 210000}]), the transaction ceased to be confirmed and gas / gasLimit doesn't set. Can you tell me what the matter is?

Maintained fork

Hey guys,
first of all, great product and great idea. kudos!

Since there was no active maintenance on project, we forked it and added bunch of stuff and improvements.
We've added all original contributors to notice as per licence. Feel free to pull changes if you wish.

tldr We will maintain fork for anyone interested:
https://github.com/NodeFactoryIo/dappeteer

dappeteer undefined

I installed dappeteer and puppeteer with yarn add dappeteer and yarn add puppeteer and yarn add -D @types/puppeteer.
I then proceeded to run this simple function, but it seems like the dappeteer import is undefined.

TypeError: Cannot read property 'launch' of undefined

My file: minting.ts

import puppeteer from "puppeteer";
import dappeteer from "dappeteer";

export async function run() {
  const browser = await dappeteer.launch(puppeteer);
  const metamask = await dappeteer.getMetamask(browser);

  await browser.close();
}

I saw that in your instructions, you said to install with npm install -s dappeteer. I'm using yarn, but is the -s of any significance for npm? I couldn't find it in the npm help. That's probably not the issue though.

❯ yarn -v
1.22.4
❯ node -v
v12.13.0

Is there some kind of more information I can provide to help debug why this is?

Get website data for smart contract

Hey, I have a question concerning the use of your app. It would be really kind if you could answer it. I just want to check if I understood it right.

If I offer a weather bet on a smart contract and the weather service doesn't provide an api can I use your app to check how the weather actually is? Or do I just misunderstand the use of your app?

Kind regards,
Finn

Jest + puppeteer + dappeteer

Hi, got a beginners question here.

I've been trying to use jest + puppeteer and then I've tried to install dappeteer, but after that for some reason it stop recognizing a file inside Jest that is there.
Have you tried to use Jest with this? Have you encountered this issue before?
image

Support headless mode

Headless mode allows to run puppeteer tests in travis.

But dappeteer is not working properly in headless mode.

For example, all the page.waitForSelector time out.

Problems with 0.4.0 from npm: "not a function" and wrong initialization

Thank you for this useful tool!

Using MacOS 10.14.3, node v11.10.1 (via homebrew) and dAppeteer 0.4.0, I receive an error in the following code:

await (async () => {
    await metamask.importAccount('my secret words ...', 'password1234');
  })().catch(err => console.log(err));

The error is:

TypeError: metamask.importAccount is not a function
    at .../src/dAppeteer1/main1.js:21:20
    at .../src/dAppeteer1/main1.js:22:5
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

The test harness (nearly identical to the one in your README) does start Chromium and does load MetaMask. However, MetaMask is not initialized with the appropriate account; the default account is used ("already turtle...").

Switching to Ropsten test chain does work, but I haven't tested anything else.

Downgrading to 0.3.0 fixes both issues (the Node error and the incorrect account message), at the cost of the older version of MetaMask.

Thanks for considering this problem.

getMetamask get stuck when using userDataDir

If we use...

const browser = await dappeteer.launch(puppeteer, {
    userDataDir: './myData'
  });

...in other words, preserve Chrome Profile with previous Metamask usage, then...
const metamask = await dappeteer.getMetamask(browser);
...gets stuck, because Metamask opens on "login" page.

It would be nice if getMetamask doesn't always go thru "create account" routine, but just to return Metamask handle if it detects that we are on the "login" page.

Sentry error

I've been having this issue for a couple of weeks now. Any way to solve it?
image

It was all of the sudden, I don't touch anything regarding what it is in the dappeteer sourcecode.

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.