Skip to content

Commit 858c257

Browse files
Adding a support command for selecting tabs
1 parent e8d8dec commit 858c257

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cypress/support/commands/tabs.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Selects and clicks a tab element by its label text.
3+
*
4+
* This command finds a tab element within a tablist that contains the specified label text
5+
* and automatically clicks it to navigate to the tab. It requires a tabLabel parameter and
6+
* will throw an error if none is provided.
7+
*
8+
* @param {Object} options - The options object
9+
* @param {string} options.tabLabel - The text content of the tab to select
10+
* @returns {Cypress.Chainable} - A Cypress chainable element representing the selected tab
11+
* @example
12+
* // Select and click the "Details" tab
13+
* cy.tabs({ tabLabel: 'Details' });
14+
*
15+
* // Select, click, and verify the "Settings" tab content appears
16+
* cy.tabs({ tabLabel: 'Settings' })
17+
* .then(() => {
18+
* cy.get('.settings-panel').should('be.visible');
19+
* });
20+
*
21+
* // Select a tab and verify it has the active class after clicking
22+
* cy.tabs({ tabLabel: 'Properties' })
23+
* .should('have.class', 'active');
24+
*/
25+
Cypress.Commands.add('tabs', ({ tabLabel = '' }) => {
26+
if (!tabLabel) {
27+
cy.logAndThrowError(`tabLabel is required`);
28+
}
29+
return cy.contains(`ul[role="tablist"] [role="tab"]`, tabLabel).click();
30+
});

cypress/support/e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import './commands/gtl.js';
4848
import './commands/login.js';
4949
import './commands/menu.js';
5050
import './commands/stub_notifications.js';
51+
import './commands/tabs.js';
5152
import './commands/throttle_response.js';
5253
import './commands/toolbar.js';
5354
import './commands/select.js';

0 commit comments

Comments
 (0)