-
-
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.
fix(queries): include value and escape text in button steps
- Loading branch information
1 parent
de85821
commit 2c9e170
Showing
3 changed files
with
81 additions
and
7 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,74 @@ | ||
/* eslint-disable tsdoc/syntax */ | ||
|
||
import { setCypressElement } from '../utils'; | ||
|
||
/** | ||
* Set Cypress elements by button text: | ||
* | ||
* ```ts | ||
* setCypressElementsByButtonText('...'); | ||
* ``` | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* setCypressElementsByButtonText('Text'); | ||
* ``` | ||
* | ||
* @see | ||
* | ||
* - {@link getCypressElement} | ||
* - {@link setCypressElement} | ||
* | ||
* @param text - Button text. | ||
* @returns - Cypress element. | ||
* | ||
* @private | ||
*/ | ||
export function setCypressElementsByButtonText(text: string) { | ||
const buttons = [ | ||
'button', | ||
"[type='button']", | ||
"[type='submit']", | ||
"[role='button']", | ||
]; | ||
const selector1 = buttons | ||
.map((selector) => `${selector}:contains(${JSON.stringify(text)}):visible`) | ||
.join(','); | ||
const selector2 = buttons | ||
.map((selector) => `${selector}[value=${JSON.stringify(text)}]:visible`) | ||
.join(','); | ||
const elements = cy.get(`${selector1},${selector2}`); | ||
setCypressElement(elements); | ||
return elements; | ||
} | ||
|
||
/** | ||
* Set Cypress element by button text: | ||
* | ||
* ```ts | ||
* setCypressElementByButtonText('...'); | ||
* ``` | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* setCypressElementByButtonText('Text'); | ||
* ``` | ||
* | ||
* @see | ||
* | ||
* - {@link getCypressElement} | ||
* - {@link setCypressElement} | ||
* | ||
* @param text - Button text. | ||
* @returns - Cypress element. | ||
* | ||
* @private | ||
*/ | ||
export function setCypressElementByButtonText(text: string) { | ||
const elements = setCypressElementsByButtonText(text); | ||
const element = elements.first(); | ||
setCypressElement(element); | ||
return element; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './button'; | ||
export * from './display-value'; | ||
export * from './element'; | ||
export * from './label'; | ||
|