Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] different behavior in headful and headless mode? #2025

Closed
JonnyLeiZhang opened this issue Apr 29, 2020 · 2 comments
Closed

[Question] different behavior in headful and headless mode? #2025

JonnyLeiZhang opened this issue Apr 29, 2020 · 2 comments

Comments

@JonnyLeiZhang
Copy link

Hi experts,

I write some test cases, can pass in headful mode, but fail in headless mode.

  await page.click('#remove-dialog > button'); //close dialog
  const dialog = await page.$('dialog[show]'); // check if the dialog closed
  if (dialog) {
    console.log(dialog);
  }

in headful mode, no output.(that's what I want)
however in headless mode, it prints the dialog.

but if I add some wait time, then it can behave same as headful mode.

  await page.click('#remove-dialog > button'); //close dialog
  await page.waitFor(1000)
  const dialog = await page.$('dialog[show]');
  if (dialog) {
    console.log(dialog);
  }

so I guess in headless mode, there'll be some residual dialog for a while after it's closed?

@pavelfeldman
Copy link
Member

It could be a simple race where headless just works faster. Looks like you dialog closes asynchronously with the click - the code there is doing something like fetch or setTimeout first. You should await for a signal instead, for example:

await page.waitForSelector('dialog[show]', waitFor: 'detached');

@JonnyLeiZhang
Copy link
Author

It could be a simple race where headless just works faster. Looks like you dialog closes asynchronously with the click - the code there is doing something like fetch or setTimeout first. You should await for a signal instead, for example:

await page.waitForSelector('dialog[show]', waitFor: 'detached');

get it! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants