简体   繁体   中英

How to avoid that Playwright ignore multiple key press

I have a test that is structured as follows.

1. Press Enter 10x.
2. check that element XYZ is in focus.

The keyboard.press is inside a for loop.

The problem is that due to the press speed, the browser does not recognize all of them.

At the end of the test, ENTER was pressed only 8-9 times. I solved it with a sleep function inside the for loop.

for(...){
 this.page.keyboard.press(enter)
 sleep(300)
}

Is it possible to avoid a sleep function here and still get a stable test?

You can add a delay as option in your page.keyboard.press() . So something like this might work for you:

await page.keyboard.press('Enter', { delay: 10 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM