web icon indicating copy to clipboard operation
web copied to clipboard

on playwright firefox, sendmouse is flaky with concurrency > 1

Open clshortfuse opened this issue 2 years ago • 2 comments

Hi!

By default, concurrency is set to something higher than two. On Firefox, running identical test files that use sendMouse will fail.

Here's a quick sample with a file called file1.test.js

import { assert } from '@esm-bundle/chai';
import { resetMouse, sendMouse } from '@web/test-runner-commands';

/**
 * @param {string} fromString
 * @param {boolean} appendToDOM
 * @return {HTMLElement}
 */
export function makeFromString(fromString, appendToDOM = true) {
  const fragment = document.createRange().createContextualFragment(fromString);
  const { firstElementChild } = fragment;
  if (appendToDOM) {
    document.body.append(fragment);
  }
  // @ts-ignore Skip cast
  return firstElementChild;
}

/**
 * @param {HTMLElement} element
 */
function getMiddleOfElement(element) {
  const { x, y, width, height } = element.getBoundingClientRect();

  return {
    x: Math.floor(x + window.pageXOffset + width / 2),
    y: Math.floor(y + window.pageYOffset + height / 2),
  };
}

describe('sanity test', () => {
  beforeEach(() => document.body.replaceChildren());
  it('should hover element', async () => {
    const element = makeFromString('<div style="min-width:40px;min-height:40px"></div>'.trim());

    const { x, y } = getMiddleOfElement(element);
    await sendMouse({ type: 'move', position: [x, y] });
    const hovered = element.matches(':hover');
    await resetMouse();
    assert.isTrue(hovered);
  });
});

cp file1.test.js file2.test.js npx web-test-runner "./*.test.js" --node-resolve --playwright --browsers firefox --concurrency 2

Tests will fail

npx web-test-runner "./*.test.js" --node-resolve --playwright --browsers firefox --concurrency 1

Will not fail.

clshortfuse avatar Jul 10 '23 20:07 clshortfuse

can confirm this. Our Firefox tests are failing until concurrency is set to 1.

msteller-connyun avatar Aug 24 '23 11:08 msteller-connyun

I'm fairly certain this has something to do with newer versions of Playwright as I too am running into this now; when I hadn't previously with Playwright 1.31.0. I've opened https://github.com/microsoft/playwright/issues/27717 to see if we can't get more information.

Westbrook avatar Oct 20 '23 00:10 Westbrook