@@ -6,6 +6,7 @@ import Shadow = Cypress.Shadow;
66import 'cypress-wait-until' ;
77import { guidedTour } from '../views/tour' ;
88import { nav } from '../views/nav' ;
9+ import './nav' ;
910import { operatorHubPage } from '../views/operator-hub-page' ;
1011
1112
@@ -42,11 +43,6 @@ declare global {
4243 bySemanticElement ( element : string , text ?: string ) : Chainable < JQuery < HTMLElement > > ;
4344 byAriaLabel ( label : string , options ?: Partial < Loggable & Timeoutable & Withinable & Shadow > ) : Chainable < JQuery < HTMLElement > > ;
4445 byPFRole ( role : string , options ?: Partial < Loggable & Timeoutable & Withinable & Shadow > ) : Chainable < JQuery < HTMLElement > > ;
45- }
46- }
47-
48- declare global {
49- interface Chainable {
5046 switchPerspective ( perspective : string ) ;
5147 uiLogin ( provider : string , username : string , password : string ) ;
5248 uiLogout ( ) ;
@@ -55,6 +51,10 @@ declare global {
5551 adminCLI ( command : string , options ?) ;
5652 login ( provider ?: string , username ?: string , password ?: string ) : Chainable < Element > ;
5753 executeAndDelete ( command : string ) ;
54+ waitUntilWithCustomTimeout (
55+ fn : ( ) => any ,
56+ options : { interval : number ; timeout : number ; timeoutMessage : string }
57+ ) : Cypress . Chainable < any > ;
5858 }
5959}
6060
@@ -546,6 +546,7 @@ Cypress.Commands.add('beforeBlockCOO', (MCP: { namespace: string, operatorName:
546546 expect ( result . code ) . to . eq ( 0 ) ;
547547 cy . log ( `Monitoring plugin pod is now running in namespace: ${ MCP . namespace } ` ) ;
548548 } ) ;
549+ cy . exec ( `oc label namespace openshift-cluster-observability-operator openshift.io/cluster-monitoring="true" --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` )
549550 //TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - console reload and logout was happening more often
550551 // cy.get('.pf-v5-c-alert, .pf-v6-c-alert', { timeout: readyTimeoutMilliseconds })
551552 // .contains('Web console update is available')
@@ -612,6 +613,8 @@ Cypress.Commands.add('afterBlockCOO', (MCP: { namespace: string, operatorName: s
612613 `oc adm policy remove-cluster-role-from-user cluster-admin ${ Cypress . env ( 'LOGIN_USERNAME' ) } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
613614 ) ;
614615
616+ cy . executeAndDelete ( `oc label namespace openshift-cluster-observability-operator openshift.io/cluster-monitoring- --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` )
617+
615618 //TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - console reload and logout was happening more often
616619 // cy.get('.pf-v5-c-alert, .pf-v6-c-alert', { timeout: 120000 })
617620 // .contains('Web console update is available')
@@ -626,4 +629,83 @@ Cypress.Commands.add('afterBlockCOO', (MCP: { namespace: string, operatorName: s
626629
627630 }
628631 cy . log ( 'After block COO completed' ) ;
632+ } ) ;
633+
634+ // Apply incident fixture manifests to the cluster
635+ Cypress . Commands . add ( 'createKubePodCrashLoopingAlert' , ( ) => {
636+ const kubeconfigPath = Cypress . env ( 'KUBECONFIG_PATH' ) ;
637+
638+ // Generate a random alert name for this test run
639+ const randomAlertName = `CustomPodCrashLooping_${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) } ` ;
640+
641+ // Store the alert name globally so tests can access it
642+ Cypress . env ( 'CURRENT_ALERT_NAME' , randomAlertName ) ;
643+
644+ cy . log ( `Generated random alert name: ${ randomAlertName } ` ) ;
645+
646+ // Read the template and replace the placeholder
647+ cy . readFile ( './cypress/fixtures/incidents/prometheus_rule_pod_crash_loop.yaml' ) . then ( ( template ) => {
648+ const yamlContent = template . replace ( / \{ \{ A L E R T _ N A M E \} \} / g, randomAlertName ) ;
649+
650+ // Write the modified YAML to a temporary file
651+ cy . writeFile ( './cypress/fixtures/incidents/temp_prometheus_rule.yaml' , yamlContent ) . then ( ( ) => {
652+ // Apply the modified YAML
653+ cy . exec (
654+ `oc apply -f ./cypress/fixtures/incidents/temp_prometheus_rule.yaml --kubeconfig ${ kubeconfigPath } ` ,
655+ ) ;
656+
657+ // Clean up temporary file
658+ cy . exec ( 'rm ./cypress/fixtures/incidents/temp_prometheus_rule.yaml' ) ;
659+ } ) ;
660+ } ) ;
661+
662+ cy . exec (
663+ `oc apply -f ./cypress/fixtures/incidents/pod_crash_loop.yaml --kubeconfig ${ kubeconfigPath } ` ,
664+ ) ;
665+
666+ // Return the alert name for the test to use
667+ return cy . wrap ( randomAlertName ) ;
668+ } ) ;
669+
670+ // Clean up incident fixture manifests from the cluster
671+ Cypress . Commands . add ( 'cleanupIncidentPrometheusRules' , ( ) => {
672+ const kubeconfigPath = Cypress . env ( 'KUBECONFIG_PATH' ) ;
673+
674+ // Delete all PrometheusRules that match our pattern (kubernetes-monitoring-podcrash-rules)
675+ // This ensures cleanup before tests and after tests
676+ cy . exec (
677+ `oc delete prometheusrule kubernetes-monitoring-podcrash-rules -n openshift-monitoring --kubeconfig ${ kubeconfigPath } --ignore-not-found=true` ,
678+ ) ;
679+
680+ // Clear the environment variable if it exists
681+ if ( Cypress . env ( 'CURRENT_ALERT_NAME' ) ) {
682+ Cypress . env ( 'CURRENT_ALERT_NAME' , null ) ;
683+ }
684+
685+ cy . executeAndDelete (
686+ `oc delete -f ./cypress/fixtures/incidents/pod_crash_loop.yaml --ignore-not-found=true --kubeconfig ${ kubeconfigPath } ` ,
687+ ) ;
688+ } ) ;
689+
690+ // Custom waitUntil with timeout message
691+ Cypress . Commands . add ( 'waitUntilWithCustomTimeout' , (
692+ fn : ( ) => any ,
693+ options : { interval : number ; timeout : number ; timeoutMessage : string }
694+ ) => {
695+ const { timeoutMessage, ...waitOptions } = options ;
696+
697+ // Set up custom error handling before the waitUntil call
698+ cy . on ( 'fail' , ( err ) => {
699+ if ( err . message . includes ( 'Timed out retrying' ) ) {
700+ // Create a new error with the custom message
701+ const customError = new Error ( timeoutMessage ) ;
702+ customError . stack = err . stack ;
703+ throw customError ;
704+ }
705+ // For any other errors, re-throw them unchanged
706+ throw err ;
707+ } ) ;
708+
709+ // Execute the waitUntil with the original options (without timeoutMessage)
710+ return cy . waitUntil ( fn , waitOptions ) ;
629711} ) ;
0 commit comments