Skip to content

Commit 569223d

Browse files
authored
Merge pull request #9602 from asirvadAbrahamVarghese/add-select-tab-command
Add select tab command
2 parents 7cefa15 + 3ef9964 commit 569223d

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

cypress/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ ManageIQ implements the following cypress extensions:
5252
* `cy.menu('primaryMenu', 'secondaryMenu', 'tertiaryMenu')` - navigates the side bar menu items. `primaryMenu`: String for the outer menu item on the side bar. `secondaryMenu`: String for the secondary menu when a side bar menu item is clicked. `tertiaryMenu`: String (optional) for the tertiary menu when a side bar secondary item is clicked. (e.g. `cy.menu('Overview', 'Dashboard')` will navigate to the Overview > Dashboard page while `cy.menu('Overview', 'Chargeback', 'Rates')` will navigate to the Overview > Chargeback > Rates page).
5353
* `cy.menuItems()` - returns an Array of `{ title: String, items: Array of { title: String, href: String, items: Array of { title: String, href: String } }}` for the menu items on the side bar. `title`: String for the menu item title. `href`: String for the url to navigate to, included when the menu item has no children. `items`: Array of the same object with `title` and `href`/`items`, this is included when the menu item has children menu items.
5454

55+
##### tabs
56+
57+
* `cy.tabs({ tabLabel })` - finds a tab element within a tablist that contains the specified label text and automatically clicks it to navigate to the tab. It requires a `tabLabel` parameter and will throw an error if none is provided. `tabLabel` is the text content of the tab to select. Returns a Cypress chainable element representing the selected tab. e.g. `cy.tabs({ tabLabel: 'Collect Logs' });`, `cy.tabs({ tabLabel: 'Settings' }).then(() => { cy.get('input#name').should('be.visible'); });`
58+
5559
##### toolbar
5660

5761
* `cy.toolbarItems(toolbarButton)` - returns an array of objects {text: String, disabled: Boolean} for the toolbar dropdown buttons for when a toolbar button is clicked. `toolbarButton` is the string for the text of the toolbar button that you want to click on.

cypress/e2e/ui/Settings/Application-Settings/edit_collect_logs.cy.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ function goToCollectLogsTab() {
3939
cy.interceptApi({
4040
alias: 'getCollectLogsTabInfo',
4141
urlPattern: '/ops/change_tab?tab_id=diagnostics_collect_logs',
42-
triggerFn: () =>
43-
cy
44-
.get(
45-
'#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_collect_logs_tab'
46-
)
47-
.click(),
42+
triggerFn: () => cy.tabs({ tabLabel: 'Collect Logs' }),
4843
});
4944
}
5045

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)