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]: Using modifier keys prevents clicking on MacOS and Chrome/Webkit in Github Actions #30891

Closed
pekspro opened this issue May 18, 2024 · 3 comments

Comments

@pekspro
Copy link

pekspro commented May 18, 2024

Version

1.44.0

Steps to reproduce

If you are using modifier keys when clicking on a button in MacOS in Chrome or Webkit, the clicks are never processed. At least when I run code in Github actions, I cannot test on a real device. The same tests work fine in Ubuntu and Windows in all browsers.

  1. Clone this repro (branch Issue30891-ModifierKeys) https://github.com/pekspro/PlaywrightIssues/tree/Issue30891-ModifierKeys
  2. Run the Github actions

Expected behavior

All tests should succeed on all platforms and all browsers.

Actual behavior

The tests fail on MacOS with the browser Chrome and Webkit.

Additional context

I’m having this simple page https://firefoxmodifierkeystest.azurewebsites.net/:

<body>
    <h1>Test</h1>
    <button class="btn btn-primary" id="counterButton">Click me</button>
    <p id="status" role="status">Hello, world!</p>

    <script>
        let currentCount = 0;
        const statusElement = document.getElementById('status');
        const buttonElement = document.getElementById('counterButton');

        buttonElement.addEventListener('click', (event) => {
            currentCount++;
            const shift = event.shiftKey;
            const ctrl = event.ctrlKey;
            const alt = event.altKey;
            const meta = event.metaKey;
            statusElement.textContent = `${currentCount} clicks. Shift: ${shift} Ctrl: ${ctrl} Alt: ${alt} Meta: ${meta}`;
        });
    </script>
</body>

With this test in NUnit:

  [Test]
  public async Task ModifierKeys()
  {
      await Page.GotoAsync("https://firefoxmodifierkeystest.azurewebsites.net/");
      await Expect(Page.Locator("#status")).ToContainTextAsync("Hello, world!", new LocatorAssertionsToContainTextOptions()
      {
          Timeout = 10000
      });

      await Page.GetByRole(AriaRole.Button, new() { Name = "Click me" }).ClickAsync();
      await Expect(Page.Locator("#status")).ToContainTextAsync("1 clicks. Shift: false Ctrl: false Alt: false Meta: false");
      
      await Page.GetByRole(AriaRole.Button, new() { Name = "Click me" }).ClickAsync(new LocatorClickOptions
      {
          Modifiers = new[] { KeyboardModifier.Control },
      });
      await Expect(Page.Locator("#status")).ToContainTextAsync("2 clicks. Shift: false Ctrl: true Alt: false Meta: false");
}         

And it fails in Gibhub actions with this error message:

Microsoft.Playwright.PlaywrightException : Locator expected to contain text '2 clicks. Shift: false Ctrl: true Alt: false Meta: false'
...
 unexpected value "1 clicks. Shift: false Ctrl: false Alt: false Meta: false"

Environment

Github actions, with ubuntu-latest, windows-latest and macos-latest
@pavelfeldman
Copy link
Member

If you have access to macOS, try opening that page (https://firefoxmodifierkeystest.azurewebsites.net/) and click Ctrl + Click. You'll see that it triggers the context menu instead of producing the click. Did you mean to press Meta + Click on macOS? You can use ControlOrMeta too.

@pekspro
Copy link
Author

pekspro commented May 20, 2024

Thanks @pavelfeldman, I didn't know that. I don't have access to any such device so is unable to test.

Anyway, I guess I should avoid modifier keys in my applications, seems to be unreliable 😁

@pavelfeldman
Copy link
Member

I don't see anything unreliable here, things seem to work as expected. Control and Meta are different key...

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