Skip to content

Commit

Permalink
feat(queries): pass options to "When I find buttons by text"
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Dec 7, 2023
1 parent 2977f89 commit e4695ee
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/queries/button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { When } from '@badeball/cypress-cucumber-preprocessor';
import { DataTable, When } from '@badeball/cypress-cucumber-preprocessor';

import { getCypressElement, setCypressElement } from '../utils';
import { getCypressElement, getOptions, setCypressElement } from '../utils';

/**
* When I find buttons by text:
Expand All @@ -15,6 +15,16 @@ import { getCypressElement, setCypressElement } from '../utils';
* When I find buttons by text "Button"
* ```
*
* With [options](https://docs.cypress.io/api/commands/get#Arguments):
*
* ```gherkin
* When I find buttons by text "Button"
* | log | true |
* | timeout | 4000 |
* | withinSubject | null |
* | includeShadowDom | false |
* ```
*
* @remarks
*
* This precedes steps like {@link When_I_click | "When I click"}. For example:
Expand All @@ -29,7 +39,7 @@ import { getCypressElement, setCypressElement } from '../utils';
*
* - {@link When_I_find_button_by_text | When I find button by text}
*/
export function When_I_find_buttons_by_text(text: string) {
export function When_I_find_buttons_by_text(text: string, options?: DataTable) {
const buttons = [
'button',
"[type='button']",
Expand All @@ -45,7 +55,7 @@ export function When_I_find_buttons_by_text(text: string) {
.map((selector) => `${selector}[value=${JSON.stringify(text)}]:visible`)
.join(',');

setCypressElement(cy.get(`${selector1},${selector2}`));
setCypressElement(cy.get(`${selector1},${selector2}`, getOptions(options)));
}

When('I find buttons by text {string}', When_I_find_buttons_by_text);
Expand All @@ -65,6 +75,16 @@ When('I find buttons by text {string}', When_I_find_buttons_by_text);
* When I find button by text "Button"
* ```
*
* With [options](https://docs.cypress.io/api/commands/get#Arguments):
*
* ```gherkin
* When I find button by text "Button"
* | log | true |
* | timeout | 4000 |
* | withinSubject | null |
* | includeShadowDom | false |
* ```
*
* @remarks
*
* This precedes steps like {@link When_I_click | "When I click"}. For example:
Expand All @@ -78,8 +98,8 @@ When('I find buttons by text {string}', When_I_find_buttons_by_text);
*
* - {@link When_I_find_buttons_by_text | When I find buttons by text}
*/
export function When_I_find_button_by_text(text: string) {
When_I_find_buttons_by_text(text);
export function When_I_find_button_by_text(text: string, options?: DataTable) {
When_I_find_buttons_by_text(text, options);
setCypressElement(getCypressElement().first());
}

Expand Down

0 comments on commit e4695ee

Please sign in to comment.