Skip to content

Commit

Permalink
fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjalKatiyar committed Jan 25, 2025
1 parent 992d164 commit dcecec5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions cypress/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
66 changes: 51 additions & 15 deletions cypress/support/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
});
Expand Down
17 changes: 13 additions & 4 deletions cypress/support/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ declare global {
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>
): Chainable<Element>;
byTestActionID(selector: string): Chainable<Element>;
byLegacyTestID(selector: string): Chainable<Element>;
byLegacyTestID(
selector: string,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>
): Chainable<Element>;
byTestDropDownMenu(selector: string): Chainable<Element>;
byTestOperandLink(selector: string): Chainable<Element>;
byTestRows(selector: string): Chainable<Element>;
Expand Down Expand Up @@ -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<Loggable & Timeoutable & Withinable & Shadow>
) => {
cy.get(`[data-test-id="${selector}"]`, options);
}
);

Cypress.Commands.add('byTestOperandLink', (selector: string) => {
cy.get(`[data-test-operand-link="${selector}"]`);
Expand Down
2 changes: 2 additions & 0 deletions test-prow-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dcecec5

Please sign in to comment.