-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(queries): add "When I find elements by role"
- Loading branch information
1 parent
1d1ad6e
commit 9f08b6b
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { DataTable, When } from '@badeball/cypress-cucumber-preprocessor'; | ||
|
||
import { getOptions, setCypressElement } from '../utils'; | ||
|
||
/** | ||
* When I find elements by role: | ||
* | ||
* ```gherkin | ||
* When I find elements by role {string} | ||
* ``` | ||
* | ||
* Queries for elements with the given role. | ||
* | ||
* @example | ||
* | ||
* ```gherkin | ||
* When I find elements by role "progressbar" | ||
* ``` | ||
* | ||
* With [options](https://docs.cypress.io/api/commands/get#Arguments): | ||
* | ||
* | ||
* ```gherkin | ||
* When I find elements by role "progressbar" | ||
* | log | true | | ||
* | timeout | 4000 | | ||
* | withinSubject | null | | ||
* | includeShadowDom | false | | ||
* ``` | ||
* | ||
* @remarks | ||
* | ||
* This precedes steps like {@link When_I_click | "When I click"}. For example: | ||
* | ||
* ```gherkin | ||
* When I find elements by role "progressbar" | ||
* And I get 1st element | ||
* And I click | ||
* ``` | ||
* | ||
* Inspired by Testing Library's [ByRole](https://testing-library.com/docs/queries/byrole/). | ||
*/ | ||
export function When_I_find_elements_by_role( | ||
role: string, | ||
options?: DataTable, | ||
) { | ||
setCypressElement( | ||
cy.get(`[role=${JSON.stringify(role)}]:visible`, getOptions(options)), | ||
); | ||
} | ||
|
||
When('I find elements by role {string}', When_I_find_elements_by_role); |