Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

dAppeteer with Jest not working in Headless mode #270

Open
asimpk opened this issue Feb 6, 2023 · 8 comments
Open

dAppeteer with Jest not working in Headless mode #270

asimpk opened this issue Feb 6, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@asimpk
Copy link

asimpk commented Feb 6, 2023

Describe the bug
I am facing an issue while running dAppeteer with jest in headless mode, in setup.js launch runs successfully but setupMetaMask doesn't work properly, similar issue is dappeteer.bootstrap() runs perfectly without headless mode

To Reproduce
Steps to reproduce the behavior:

  1. Follow the doc to run DAppteer with Jest https://github.com/ChainSafe/dappeteer/blob/master/docs/JEST.md
  2. const browser = await launch(puppeteer, PUPPETEER_CONFIG), add the Headless: true option, BTW doc needs to be updated.
  3. run the tests

Logs

Determining test suites to run...
        Running tests on MetaMask version v10.23.0
        Flask version: false,
        Headless: true

Expected behavior
Tests should run, and logs should be seen to get show progress or give error

System:

  • OS: windows
  • OS version windows 10
  • NodeJs version v16.16.0
  • dAppeteer version ^4.2.0
  • testing framework jest
  • testing framework version 27.5.1

Additional context
A similar bug is seen when we run script without jest from as in README.md;
https://github.com/ChainSafe/dappeteer
const { metaMask, browser } = await dappeteer.bootstrap({
browser: "chrome",
headless: true
});

@asimpk asimpk added the bug Something isn't working label Feb 6, 2023
@BeroBurny
Copy link
Contributor

Thanks for pointing issue.
Can you tell me which automation framework you use and what version?

@BeroBurny BeroBurny self-assigned this Feb 6, 2023
@asimpk
Copy link
Author

asimpk commented Feb 6, 2023

Sorry, I'm not using any framework right now, I first tried to use synpress https://github.com/Synthetixio/synpress but not using it and any other

@BeroBurny
Copy link
Contributor

try to install playwright or puppeteer and then run tests

@asimpk
Copy link
Author

asimpk commented Feb 6, 2023

try to install playwright or puppeteer and then run tests

Yeah I'm using "puppeteer": "^19.6.2", as that, was the requirement for setup, tests running successfully but only when not in headless mode

@BeroBurny
Copy link
Contributor

it is confirmed that there is a bug, for now, the workaround is to use the playwright


observed notes

return new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
browser.on("targetcreated", async (target: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
if (target.url().match(MM_HOME_REGEX)) {
try {
const pages = await browser.pages();
for (const page of pages) {
if (page.url().match(MM_HOME_REGEX)) {
resolve(page);
}
}
} catch (e) {
reject(e);
}
}
});
});

for some reason, targetcreated is never triggered in puppeteer

cc @irubido @Lykhoyda

@BeroBurny
Copy link
Contributor

simple repo for reproducing issue https://github.com/BeroBurny/dappeteer-jest

@asimpk
Copy link
Author

asimpk commented Feb 7, 2023

it is confirmed that there is a bug, for now, the workaround is to use the playwright

observed notes

return new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
browser.on("targetcreated", async (target: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
if (target.url().match(MM_HOME_REGEX)) {
try {
const pages = await browser.pages();
for (const page of pages) {
if (page.url().match(MM_HOME_REGEX)) {
resolve(page);
}
}
} catch (e) {
reject(e);
}
}
});
});

for some reason, targetcreated is never triggered in puppeteer
cc @irubido @Lykhoyda

Thanks @BeroBurny , by using playwright, it throws an exception from environment.js
if (!wsEndpoint) throw new Error('wsEndpoint not found');
but in the case of puppeteer we get browser.wsEndpoint(),
ws://127.0.0.1:50927/devtools/browser/{key}

@Lykhoyda
Copy link
Contributor

Lykhoyda commented Feb 7, 2023

@asimpk the issue is due to the puppeteer version. Please set version 14.0.0 in package.json until we update it on the dappeteer side

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants