-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Feature] Allow keyboard methods to be OS agnostic #12168
Comments
I just ran into something that should be taken into account when implementing this change - you can't just look at process.platform to figure out which key to use - we're now executing remotely to BrowserStack, running from linux on our CICD agent but the browser might be running on Mac or Windows - you need to query the browser -
|
First of all, yes this would make the testing more seamless so +1 for this addition or similar. As to your followup, I'm not sure if the browser check is correct as the commands might be coming from the OS. For instance I'm trying to copy some text then paste them back. To do the paste I use Running this test on the 3 browsers (FF, Chromium, Webkit) the user agent returns Windows for FF and Chromium, and Mac for Webkit. So for FF and Chrome it will pick So this may be further complicating how this could be implemented. |
Did anyone find a workaround for this in the meantime? Thanks for making the original suggestion. |
This was my solution. It worked for me. let macOS = process.platform === 'darwin' //darwin is macOS
let [newTab] = await Promise.all([
context.waitForEvent('page'),
macOS
? link.click({ modifiers: ['Meta'] })
: link.click({ modifiers: ['Control'] }),
]) |
Similar solution:
|
@nico-olivares @canopy-js-user aren't your answers fall into the trap @MartinP-Autopilot mentioned? His solution seems more robust IMHO. BTW @MartinP-Autopilot 's answer give false results on MacOS m1 chips in Playwright. |
This is the advice currently on https://playwright.dev/docs/api/class-keyboard
The script should not have to implement special handling to ensure that these methods work in the expected manner across each OS, the method should allow something like
and the method should handle the OS detection transparently.
The text was updated successfully, but these errors were encountered: