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

[Feature]: Change the keyboard API to return Promise<this> #31791

Closed
trajano opened this issue Jul 22, 2024 · 2 comments
Closed

[Feature]: Change the keyboard API to return Promise<this> #31791

trajano opened this issue Jul 22, 2024 · 2 comments

Comments

@trajano
Copy link

trajano commented Jul 22, 2024

🚀 Feature Request

Presently the keyboard operations return Promise<void>. Can it be modified to return Promise<this> or Promise<Keyboard> so we can do something like a chain if we wanted

Example

This is from my post in https://stackoverflow.com/questions/78777386/how-do-i-avoid-then-or-repeated-await-when-chaining-promises-in-typescript but due to the limitations of typescript my concept would be

await page.keyboard.type("username")
  .then((k)=>k.press("Tab"))
  .then((k)=>k.type("password"))
  .then((k)=>k.press("Tab"))

Motivation

It's just to avoid too much repeated code and allow better visualization of how certain groups code code would work together. That is to avoid

await page.keyboard.type("username");
await page.keyboard.press("Tab"));
await page.keyboard.type("password");
await page.keyboard.press("Tab"));
@pavelfeldman
Copy link
Member

Chained APIs are discouraged in our API model.

@trajano
Copy link
Author

trajano commented Jul 23, 2024

OK FWIW https://stackoverflow.com/a/78777606/242042 shows how it could be done. It's nice to be able to write tests like this

    await myPage
      .type(programName)
      .tab()
      .type(shortName)
      .tab()
      .type(description)
      .tab()
      .type(fee)
      .enter();

Also I would only want it on keyboard anyway not the whole thing.

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