diff --git a/cypress/plugin.js b/cypress/plugin.js index 98c524dd6..04b44b5dc 100644 --- a/cypress/plugin.js +++ b/cypress/plugin.js @@ -71,5 +71,6 @@ module.exports = (on, config) => { config.env.BRIDGE_HTPASSWD_USERNAME = process.env.BRIDGE_HTPASSWD_USERNAME; config.env.BRIDGE_HTPASSWD_PASSWORD = process.env.BRIDGE_HTPASSWD_PASSWORD; config.env.BRIDGE_KUBEADMIN_PASSWORD = process.env.BRIDGE_KUBEADMIN_PASSWORD; + config.env.OAUTH_BASE_ADDRESS = `https://${process.env.OAUTH_BASE_ADDRESS}`; return config; }; diff --git a/cypress/support/login.ts b/cypress/support/login.ts index 126a87500..17d5cca14 100644 --- a/cypress/support/login.ts +++ b/cypress/support/login.ts @@ -22,6 +22,7 @@ Cypress.Commands.add( () => { // Check if auth is disabled (for a local development environment). cy.visit(''); // visits baseUrl which is set in plugins.js + cy.window().then((win: any) => { if (win.SERVER_FLAGS?.authDisabled) { cy.task( @@ -31,24 +32,59 @@ Cypress.Commands.add( return; } - const idp = provider || KUBEADMIN_IDP; - cy.task('log', ` Logging in as ${username || KUBEADMIN_USERNAME}`); - cy.byLegacyTestID('login').should('be.visible'); - // eslint-disable-next-line cypress/require-data-selectors - cy.get('body').then(($body) => { - if ($body.text().includes(idp)) { - cy.contains(idp).should('be.visible').click(); - } - }); - /* eslint-disable cypress/require-data-selectors */ - cy.get('#inputUsername').type(username || KUBEADMIN_USERNAME); - cy.get('#inputPassword').type( - password || Cypress.env('BRIDGE_KUBEADMIN_PASSWORD'), + cy.origin( + Cypress.env('OAUTH_BASE_ADDRESS'), { - log: false, + args: { + provider, + username, + password, + KUBEADMIN_IDP, + KUBEADMIN_USERNAME, + submitButton, + }, + }, + ({ + /* eslint-disable @typescript-eslint/no-shadow, @typescript-eslint/naming-convention */ + provider, + username, + password, + KUBEADMIN_IDP, + KUBEADMIN_USERNAME, + submitButton, + /* eslint-enable @typescript-eslint/no-shadow, @typescript-eslint/naming-convention */ + }) => { + const idp = provider || KUBEADMIN_IDP; + + cy.task( + 'log', + ` Logging in as ${username || KUBEADMIN_USERNAME}` + ); + cy.get('[data-test-id="login"]', { timeout: 10000 }).should( + 'be.visible' + ); + + // eslint-disable-next-line cypress/require-data-selectors + cy.get('body').then(($body) => { + if ($body.text().includes(idp)) { + cy.contains(idp).should('be.visible').click(); + } + }); + + /* eslint-disable cypress/require-data-selectors */ + cy.get('#inputUsername').type(username || KUBEADMIN_USERNAME); + cy.get('#inputPassword').type( + password || Cypress.env('BRIDGE_KUBEADMIN_PASSWORD'), + { + log: false, + } + ); + cy.get(submitButton).click(); } ); - cy.get(submitButton).click(); + + // Back to the console's origin and ensure user is logged in. + cy.visit(''); /* eslint-enable cypress/require-data-selectors */ masthead.username.shouldBeVisible(); }); diff --git a/cypress/support/selectors.ts b/cypress/support/selectors.ts index 001ad0707..959000444 100644 --- a/cypress/support/selectors.ts +++ b/cypress/support/selectors.ts @@ -13,7 +13,10 @@ declare global { options?: Partial ): Chainable; byTestActionID(selector: string): Chainable; - byLegacyTestID(selector: string): Chainable; + byLegacyTestID( + selector: string, + options?: Partial + ): Chainable; byTestDropDownMenu(selector: string): Chainable; byTestOperandLink(selector: string): Chainable; byTestRows(selector: string): Chainable; @@ -47,9 +50,15 @@ Cypress.Commands.add( } ); -Cypress.Commands.add('byLegacyTestID', (selector: string) => { - cy.get(`[data-test-id="${selector}"]`); -}); +Cypress.Commands.add( + 'byLegacyTestID', + ( + selector: string, + options?: Partial + ) => { + cy.get(`[data-test-id="${selector}"]`, options); + } +); Cypress.Commands.add('byTestOperandLink', (selector: string) => { cy.get(`[data-test-operand-link="${selector}"]`); diff --git a/test-prow-e2e.sh b/test-prow-e2e.sh index 2be74fd90..a846eb584 100755 --- a/test-prow-e2e.sh +++ b/test-prow-e2e.sh @@ -143,6 +143,8 @@ BRIDGE_KUBEADMIN_PASSWORD="$(cat "${KUBEADMIN_PASSWORD_FILE:-${INSTALLER_DIR}/au export BRIDGE_KUBEADMIN_PASSWORD BRIDGE_BASE_ADDRESS="$(oc get consoles.config.openshift.io cluster -o jsonpath='{.status.consoleURL}')" export BRIDGE_BASE_ADDRESS +OAUTH_BASE_ADDRESS="$(oc get route -n openshift-authentication oauth-openshift -o jsonpath='{.spec.host}')" +export OAUTH_BASE_ADDRESS # Disable color codes in Cypress since they do not render well CI test logs. # https://docs.cypress.io/guides/guides/continuous-integration.html#Colors