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

[BUG] beforeunload event in headless mode is failing #4021

Closed
reiinoldo opened this issue Sep 30, 2020 · 1 comment · Fixed by #4341
Closed

[BUG] beforeunload event in headless mode is failing #4021

reiinoldo opened this issue Sep 30, 2020 · 1 comment · Fixed by #4341
Assignees

Comments

@reiinoldo
Copy link

Context:

Here is the problem

I'm trying to simulate changes to be saved before closing the page, running not in a headless mode it succeeds but when headless is activated due to the need to run inside a Docker container its fails.

I've just created a React App with a button that active/deactivate the preventDefault event (https://github.com/reiinoldo/playwright-docker-test/blob/master/src/App.js).

image

The test clicks on the button to unsaved the changes and tries to close the page, so with that, the dialog appears and after saving the changes clicking on the button then the page can be closed.

Code Snippet

https://github.com/reiinoldo/playwright-docker-test/blob/master/e2e/playwright.config.js

import { chromium } from "playwright";

module.exports = {
  browserType: chromium,
  launchConfig: {
    headless: true,
    args: ["--no-sandbox", "--disable-setuid-sandbox"],
    slowMo: 500,
  },
};

https://github.com/reiinoldo/playwright-docker-test/blob/master/e2e/pageObjects/index.js

import { browserType, launchConfig, contextConfig } from "../playwright.config";
import DialogHandler from "./dialog";

const rootSelector = "#root";
let browser, context, page, dialog;

export const root = async () => await page.$(rootSelector);

export const load = async () => {
  browser = await browserType.launch(launchConfig);
  context = await browser.newContext(contextConfig);
  page = await context.newPage();
  await page.goto(baseURL);
  dialog = new DialogHandler(page);
};

export const reload = async () => await page.reload();

export const close = async () => await page.close({ runBeforeUnload: true });

export const closeBrowser = async () => await browser.close();

export const getTitle = async () => await page.title();

export const dialogAppers = async () => await dialog.appeared();

export const dismissDialog = async () => await dialog.dismiss();
;

https://github.com/reiinoldo/playwright-docker-test/blob/master/e2e/specs/app.js

import { clicOnSaveButton } from "../pageObjects/app";
import {
  load,
  close,
  closeBrowser,
  dialogAppers,
  dismissDialog,
} from "../pageObjects/index";

describe("React App", () => {
  beforeEach(async () => {
    await load();
  });

  afterEach(async () => {
    await closeBrowser();
  });

  it("Should show the unsaved changes dialog when tries to close the page without saving the changes", async () => {
    expect(await clicOnSaveButton()); // save
    expect(await clicOnSaveButton()); // unsaved changes
    await close();
    expect(await dialogAppers());
    expect(await dismissDialog());
    expect(await clicOnSaveButton()); // save to close
  });
});

Output result

image

Comparing to successful execution, the left side is headless false, and the other is headless true which is failing:

image

@reiinoldo
Copy link
Author

I've noticed that using the browserType Webkit it works well in both modes headless or not.

aslushnikov added a commit to aslushnikov/playwright that referenced this issue Nov 3, 2020
This patch:
- co-locates beforeunload tests
- adds a new test to make sure browser context can be closed if there's
a page with beforeunload

References microsoft#4021
aslushnikov added a commit to aslushnikov/playwright that referenced this issue Nov 3, 2020
This patch:
- co-locates beforeunload tests
- adds new tests to make sure browser and browsercontext can be closed if there's
  a page with beforeunload listener
- re-writes the `should access page after beforeunload` test to properly
  emit `beforeunload` event

References microsoft#4021
aslushnikov added a commit to aslushnikov/playwright that referenced this issue Nov 3, 2020
aslushnikov added a commit that referenced this issue Nov 3, 2020
This patch:
- co-locates beforeunload tests
- adds new tests to make sure browser and browsercontext can be closed if there's
  a page with beforeunload listener
- re-writes the `should access page after beforeunload` test to properly
  emit `beforeunload` event

References #4021
aslushnikov added a commit to aslushnikov/playwright that referenced this issue Nov 3, 2020
This roll includes:
- fix for the firefox flakiness related to popups
- fix for browser context closing with beforeunload events

References microsoft#4021
aslushnikov added a commit that referenced this issue Nov 3, 2020
This roll includes:
- fix for the firefox flakiness related to popups
- fix for browser context closing with beforeunload events

References #4021
aslushnikov added a commit that referenced this issue Nov 4, 2020
aslushnikov added a commit to aslushnikov/playwright that referenced this issue Nov 4, 2020
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

Successfully merging a pull request may close this issue.

3 participants