testingrequired / webdriver

A webdriver library
MIT License
0 stars 0 forks source link

await await #20

Open kyleect opened 4 years ago

kyleect commented 4 years ago

Getting elements and acting on them are both async actions. This requires two separate await statements. Element id caching won't work because it has to be assumed to be async regardless of cache status.

Example:

class LoginForm extends WebElement {
  get username() {
    return this.$("#username");
  }

  get password() {
    return this.$("#password");
  }

  get loginButton() {
    return this.$("#loginButton");
  }

  async fill(username, password) {
    await (await this.username).sendKeys(username);
    await (await this.password).sendKeys(password);
    await (await this.loginButton).click();
  }
}
kyleect commented 4 years ago

Api/syntax maybe?

await loginForm.do(
  $ => $.username.sendKeys("username"),
  $ => $.password.sendKeys("password"),
  $ => $.loginButton.click(),
)
kyleect commented 4 years ago

Or

await loginForm.do(
  $ => $.username.sendKeys("username")
    && $.password.sendKeys("password")
    && $.loginButton.click()
)