From fa95e5410497f082563199f491eda0c9057b8072 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 10 Dec 2022 14:42:17 -0500 Subject: [PATCH] feat(actions): add "When I type" --- src/actions/index.ts | 1 + src/actions/type.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/actions/type.ts diff --git a/src/actions/index.ts b/src/actions/index.ts index 13b596681..60a0094f3 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -1,4 +1,5 @@ export * from './click'; export * from './reload'; +export * from './type'; export * from './visit'; export * from './wait'; diff --git a/src/actions/type.ts b/src/actions/type.ts new file mode 100644 index 000000000..0606abb96 --- /dev/null +++ b/src/actions/type.ts @@ -0,0 +1,31 @@ +import { When } from '@badeball/cypress-cucumber-preprocessor'; + +import { getCypressElement } from '../utils'; + +/** + * When I type: + * + * ```gherkin + * When I type {string} + * ``` + * + * @example + * + * ```gherkin + * When I type "Hello, world!" + * ``` + * + * @remarks + * + * This requires a preceding step like query {@link When_I_get_element_by_label_text | "When I get element by label text"}. E.g.: + * + * ```gherkin + * When I get element by label text "Email" + * And I type "user@example.com" + * ``` + */ +export function When_I_type(text: string) { + getCypressElement(this).type(text); +} + +When('I type {string}', When_I_type);