ferridriver-bdd 0.4.0

BDD/Cucumber test framework for ferridriver. 144 built-in Gherkin steps backed by the Page API.
Documentation
//! Keyboard step definitions.

use crate::step::StepError;
use crate::world::BrowserWorld;
use ferridriver_bdd_macros::when;

#[when("I press {string}")]
async fn press_key(world: &mut BrowserWorld, key: String) {
  world
    .page()
    .keyboard()
    .press(&key, None)
    .await
    .map_err(|e| StepError::wrap(format!("press \"{key}\""), e))?;
}

#[when("I press {string} on {string}")]
async fn press_key_on(world: &mut BrowserWorld, key: String, selector: String) {
  world
    .page()
    .locator(&selector, None)
    .press(&key, None)
    .await
    .map_err(|e| StepError::wrap(format!("press \"{key}\" on \"{selector}\""), e))?;
}

#[when("I type {string}")]
async fn type_text(world: &mut BrowserWorld, text: String) {
  world
    .page()
    .keyboard()
    .r#type(&text, None)
    .await
    .map_err(|e| StepError::wrap(format!("type \"{text}\""), e))?;
}

#[when("I press {string} with modifier {string}")]
async fn press_with_modifier(world: &mut BrowserWorld, key: String, modifier: String) {
  let combo = format!("{modifier}+{key}");
  world
    .page()
    .keyboard()
    .press(&combo, None)
    .await
    .map_err(|e| StepError::wrap(format!("press \"{combo}\""), e))?;
}