Skip to content

Commit 4b012b3

Browse files
Merge pull request #557 from etmurasaki/mp-injection
NO-JIRA: automation log and debug mode in headless mode
2 parents e869813 + aba4abb commit 4b012b3

File tree

6 files changed

+68
-10
lines changed

6 files changed

+68
-10
lines changed

web/cypress/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ Set the following var to enable Cypress session management for faster test execu
7272
export CYPRESS_SESSION=true
7373
```
7474

75+
Set the following var to enable Cypress debug mode to log in headless mode.
76+
```bash
77+
export CYPRESS_DEBUG=true
78+
```
79+
7580
Integration Testing variables
7681

7782
Set the var to skip Openshift Virtualization and all the required operators installation.

web/cypress/configure-env.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ print_current_config() {
174174
print_var "CYPRESS_MCP_CONSOLE_IMAGE" "${CYPRESS_MCP_CONSOLE_IMAGE-}"
175175
print_var "CYPRESS_TIMEZONE" "${CYPRESS_TIMEZONE-}"
176176
print_var "CYPRESS_SESSION" "${CYPRESS_SESSION-}"
177+
print_var "CYPRESS_DEBUG" "${CYPRESS_DEBUG-}"
177178
print_var "CYPRESS_SKIP_KBV_INSTALL" "${CYPRESS_SKIP_KBV_INSTALL-}"
178179
print_var "CYPRESS_KBV_UI_INSTALL" "${CYPRESS_KBV_UI_INSTALL-}"
179180
print_var "CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE" "${CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE-}"
@@ -221,6 +222,7 @@ main() {
221222
local def_mcp_console_image=${CYPRESS_MCP_CONSOLE_IMAGE-}
222223
local def_timezone=${CYPRESS_TIMEZONE-}
223224
local def_session=${CYPRESS_SESSION-}
225+
local def_debug=${CYPRESS_DEBUG-}
224226
local def_skip_kbv=${CYPRESS_SKIP_KBV_INSTALL-}
225227
local def_kbv_ui_install=${CYPRESS_KBV_UI_INSTALL-}
226228
local def_konflux_kbv_bundle=${CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE-}
@@ -421,6 +423,11 @@ main() {
421423
local session="false"
422424
[[ "$session_ans" == "y" ]] && session="true"
423425

426+
local debug_ans
427+
debug_ans=$(ask_yes_no "Enable Cypress debug mode? (sets CYPRESS_DEBUG)" "$(bool_to_default_yn "$def_debug")")
428+
local debug="false"
429+
[[ "$debug_ans" == "y" ]] && debug="true"
430+
424431
local skip_kbv_install_ans
425432
skip_kbv_install_ans=$(ask_yes_no "Skip Openshift Virtualization installation? (sets CYPRESS_SKIP_KBV_INSTALL)" "$(bool_to_default_yn "$def_skip_kbv")")
426433
local skip_kbv_install="false"
@@ -465,7 +472,7 @@ main() {
465472
export_lines+=("export CYPRESS_TIMEZONE='$(printf %s "$timezone" | escape_for_single_quotes)'" )
466473
fi
467474
export_lines+=("export CYPRESS_SESSION='$(printf %s "$session" | escape_for_single_quotes)'" )
468-
475+
export_lines+=("export CYPRESS_DEBUG='$(printf %s "$debug" | escape_for_single_quotes)'" )
469476
if [[ -n "$skip_kbv_install" ]]; then
470477
export_lines+=("export CYPRESS_SKIP_KBV_INSTALL='$(printf %s "$skip_kbv_install" | escape_for_single_quotes)'" )
471478
fi
@@ -512,6 +519,7 @@ main() {
512519
[[ -n "${CYPRESS_MCP_CONSOLE_IMAGE-}$mcp_console_image" ]] && echo " CYPRESS_MCP_CONSOLE_IMAGE=${CYPRESS_MCP_CONSOLE_IMAGE:-$mcp_console_image}"
513520
[[ -n "${CYPRESS_TIMEZONE-}$timezone" ]] && echo " CYPRESS_TIMEZONE=${CYPRESS_TIMEZONE:-$timezone}"
514521
echo " CYPRESS_SESSION=${CYPRESS_SESSION:-$session}"
522+
echo " CYPRESS_DEBUG=${CYPRESS_DEBUG:-$debug}"
515523
echo " CYPRESS_SKIP_KBV_INSTALL=${CYPRESS_SKIP_KBV_INSTALL:-$skip_kbv_install}"
516524
echo " CYPRESS_KBV_UI_INSTALL=${CYPRESS_KBV_UI_INSTALL:-$kbv_ui_install}"
517525
[[ -n "${CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE-}$konflux_kbv_bundle" ]] && echo " CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE=${CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE:-$konflux_kbv_bundle}"

web/cypress/e2e/monitoring/01.bvt_monitoring.cy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ describe('BVT: Monitoring', () => {
3232
commonPages.titleShouldHaveText('Alerting');
3333
cy.changeNamespace('All Projects');
3434
nav.tabs.switchTab('Silences');
35-
silencesListPage.firstTimeEmptyState();
3635
nav.sidenav.clickNavLink(['Observe', 'Metrics']);
3736
commonPages.titleShouldHaveText('Metrics');
3837
nav.sidenav.clickNavLink(['Observe', 'Dashboards']);

web/cypress/support/commands/operator-commands.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
480480
{
481481
cacheAcrossSpecs: true,
482482
validate() {
483-
cy.visit('/');
484-
cy.byTestID("username", {timeout: 120000}).should('be.visible');
483+
cy.validateLogin();
485484
},
486485
},
487486
);
@@ -493,6 +492,8 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
493492
cy.task('clearDownloads');
494493
cy.log('Before block (no session) completed');
495494
}
495+
cy.aboutModal();
496+
cy.podImage('monitoring-plugin', MP.namespace);
496497
});
497498

498499
Cypress.Commands.add('cleanupMP', (MP: { namespace: string, operatorName: string }) => {
@@ -528,8 +529,7 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
528529
{
529530
cacheAcrossSpecs: true,
530531
validate() {
531-
cy.visit('/');
532-
cy.byTestID("username", {timeout: 120000}).should('be.visible');
532+
cy.validateLogin();
533533
// Additional validation for COO setup
534534
cy.visit('/monitoring/v2/dashboards');
535535
cy.url().should('include', '/monitoring/v2/dashboards');
@@ -550,6 +550,9 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
550550
operatorUtils.RemoveClusterAdminRole();
551551
cy.log('Before block COO (no session) completed');
552552
}
553+
cy.aboutModal();
554+
cy.podImage('monitoring-plugin', MP.namespace);
555+
cy.podImage('monitoring', MCP.namespace);
553556
});
554557

555558
Cypress.Commands.add('cleanupCOO', (MCP: { namespace: string, operatorName: string, packageName: string }, MP: { namespace: string, operatorName: string }) => {
@@ -563,4 +566,4 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
563566
cy.log('Remove cluster-admin role from user.');
564567
operatorUtils.RemoveClusterAdminRole();
565568
cy.log('Remove cluster-admin role from user completed');
566-
});
569+
});

web/cypress/support/commands/utility-commands.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ declare global {
99
): Cypress.Chainable<any>;
1010
clickNavLink(path: string[]): Chainable<Element>;
1111
changeNamespace(namespace: string): Chainable<Element>;
12+
aboutModal(): Chainable<Element>;
13+
podImage(pod: string, namespace: string): Chainable<Element>;
1214
}
1315
}
1416
}
@@ -54,6 +56,7 @@ Cypress.Commands.add('waitUntilWithCustomTimeout', (
5456
});
5557

5658
Cypress.Commands.add('changeNamespace', (namespace: string) => {
59+
cy.log('Changing Namespace to: ' + namespace);
5760
cy.byLegacyTestID('namespace-bar-dropdown').find('button').scrollIntoView().should('be.visible').click();
5861
cy.get('[data-test="showSystemSwitch"]').then(($element)=> {
5962
if ($element.attr('data-checked-state') !== 'true') {
@@ -62,5 +65,46 @@ Cypress.Commands.add('waitUntilWithCustomTimeout', (
6265
});
6366
cy.byTestID('dropdown-text-filter').type(namespace);
6467
cy.byTestID('dropdown-menu-item-link').contains(namespace).should('be.visible').click();
65-
68+
cy.log('Namespace changed to: ' + namespace);
6669
});
70+
71+
Cypress.Commands.add('aboutModal', () => {
72+
cy.log('Getting OCP version');
73+
cy.byTestID('help-dropdown-toggle').should('be.visible').click();
74+
cy.byTestID('application-launcher-item').contains('About').should('be.visible').click();
75+
cy.byAriaLabel('About modal').find('div[class*="co-select-to-copy"]').eq(0).should('be.visible').then(($ocpversion) => {
76+
cy.log('OCP version: ' + $ocpversion.text());
77+
});
78+
cy.byAriaLabel('Close Dialog').should('be.visible').click();
79+
80+
});
81+
82+
Cypress.Commands.overwrite('log', (log, ...args) => {
83+
if (Cypress.browser.isHeadless && Cypress.env('DEBUG')) {
84+
// Log to the terminal using the custom task
85+
return cy.task('log', args, { log: false }).then(() => {
86+
// The original cy.log is still executed but its output is hidden from the
87+
// command log in headless mode
88+
return log(...args);
89+
});
90+
} else {
91+
// In headed mode, use the original cy.log behavior
92+
return log(...args);
93+
}
94+
});
95+
96+
Cypress.Commands.add('podImage', (pod: string, namespace: string) => {
97+
cy.log('Get pod image');
98+
cy.clickNavLink(['Workloads', 'Pods']);
99+
cy.changeNamespace(namespace);
100+
cy.byTestID('name-filter-input').should('be.visible').type(pod);
101+
cy.get(`a[data-test^="${pod}"]`).eq(0).as('podLink').click();
102+
cy.get('@podLink').should('be.visible').click();
103+
cy.byPFRole('rowgroup').find('td').eq(1).scrollIntoView().should('be.visible').then(($td) => {
104+
cy.log('Pod image: ' + $td.text());
105+
106+
});
107+
cy.log('Get pod image completed');
108+
});
109+
110+

web/cypress/support/commands/virtualization-commands.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ const virtualizationUtils = {
200200
{
201201
cacheAcrossSpecs: true,
202202
validate() {
203-
cy.visit('/');
204-
cy.byTestID("username", {timeout: 120000}).should('be.visible');
203+
cy.validateLogin();
205204
// Additional validation for Virtualization setup
206205
cy.visit('/k8s/all-namespaces/virtualization-overview');
207206
cy.url().should('include', '/k8s/all-namespaces/virtualization-overview');

0 commit comments

Comments
 (0)