Skip to content

Commit

Permalink
cypress - better logging in headless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaylor113 committed Sep 21, 2020
1 parent 8059134 commit 66a08e0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
5 changes: 5 additions & 0 deletions frontend/packages/integration-tests-cypress/support/index.ts
Expand Up @@ -20,6 +20,11 @@ Cypress.Cookies.defaults({
preserve: ['openshift-session-token', 'csrf-token'],
});

Cypress.Commands.overwrite('log', (originalFn, message) => {
cy.task('log', ` ${message}`, { log: false }); // log:false means do not log task in runner GUI
originalFn(message); // calls original cy.log(message)
});

Cypress.Commands.add('logA11yViolations', (violations: Result[], target: string) => {
// pluck specific keys to keep the table readable
const violationData = violations.map(({ id, impact, description, nodes }) => ({
Expand Down
8 changes: 4 additions & 4 deletions frontend/packages/integration-tests-cypress/support/login.ts
Expand Up @@ -15,16 +15,16 @@ const KUBEADMIN_IDP = 'kube:admin';

// any command added below, must be added to global Cypress interface above

// This will add to 'login(provider, username, password)' to cy
// This will add 'cy.login(...)'
// ex: cy.login('test', 'test', 'test')
Cypress.Commands.add('login', (provider: string, username: string, password: string) => {
// if local, no need to login
if (!Cypress.env('BRIDGE_KUBEADMIN_PASSWORD')) {
cy.task('log', 'No BRIDGE_KUBEADMIN_PASSWORD set, skipping login');
cy.task('log', ' skipping login, no BRIDGE_KUBEADMIN_PASSWORD set');
return;
}
const idp = provider || KUBEADMIN_IDP;
cy.task('log', ` Logging into IDP ${idp}, using baseUrl ${Cypress.config('baseUrl')}`);
cy.task('log', ` Logging in as ${username || KUBEADMIN_USERNAME}`);
cy.visit(''); // visits baseUrl which is set in plugins/index.js
cy.byLegacyTestID('login').should('be.visible');
cy.contains(idp)
Expand All @@ -38,7 +38,7 @@ Cypress.Commands.add('login', (provider: string, username: string, password: str

Cypress.Commands.add('logout', () => {
if (!Cypress.env('BRIDGE_KUBEADMIN_PASSWORD')) {
cy.task('log', 'No BRIDGE_KUBEADMIN_PASSWORD set, skipping logout');
cy.task('log', ' skipping logout');
return;
}
cy.task('log', ' Logging out');
Expand Down
Expand Up @@ -16,6 +16,7 @@ declare global {
// This will add to 'createProject(...)' to cy
// ex: cy.createProject(name)
Cypress.Commands.add('createProject', (name: string) => {
cy.log(`create project`);
cy.visit(`/k8s/cluster/projects`);
listPage.clickCreateYAMLbutton();
modal.shouldBeOpened();
Expand All @@ -27,6 +28,7 @@ Cypress.Commands.add('createProject', (name: string) => {
});

Cypress.Commands.add('deleteProject', (name: string) => {
cy.log(`delete project`);
cy.visit(`/k8s/cluster/projects/${name}`);
detailsPage.clickPageActionFromDropdown('Delete Project');
modal.shouldBeOpened();
Expand Down
10 changes: 3 additions & 7 deletions frontend/packages/integration-tests-cypress/support/resources.ts
Expand Up @@ -41,16 +41,12 @@ Cypress.Commands.add(
)
.then((result) => {
if (result.code !== 0) {
if (result.stderr.includes('NotFound')) {
cy.log(
`'oc get -n ${namespace} ${resource}/${name}' returned 'NotFound' indicating resource was successfully deleted`,
);
} else {
// this typically would be a 'You must be logged in to the server (Unauthorized)'
// if stderr === NotFound, means resource was succesfully deleted
if (!result.stderr.includes('NotFound')) {
// error other than 'NotFound', this typically would be a 'You must be logged in to the server (Unauthorized)'
assert.fail('', '', `Error during 'oc get ${resource}/${name}', ${result.stderr} `);
}
} else {
cy.log(`expect ${resource}/${name} to have a deletionTimestamp`);
expect(result.stdout).not.toContain(`<no value>`);
}
}),
Expand Down
Expand Up @@ -93,7 +93,6 @@ describe('Kubernetes resource CRUD operations', () => {
{ metadata: { name, labels: { [testLabel]: testName } } },
safeLoad(content),
);
cy.log('creates a new resource instance');
yamlEditor.setEditorContent(safeDump(newContent, { sortKeys: true })).then(() => {
yamlEditor.clickSaveCreateButton();
cy.get(errorMessage).should('not.exist');
Expand All @@ -112,11 +111,11 @@ describe('Kubernetes resource CRUD operations', () => {
`${namespaced ? `/k8s/ns/${testName}` : '/k8s/cluster'}/${resource}?name=${testName}`,
);
if (namespaced) {
cy.log('has a working namespace dropdown on namespaced objects');
// should have a namespace dropdown for namespaced objects');
listPage.projectDropdownShouldExist();
listPage.projectDropdownShouldContain(testName);
} else {
cy.log('does not have a namespace dropdown on non-namespaced objects');
// should not have a namespace dropdown for non-namespaced objects');
listPage.projectDropdownShouldNotExist();
}
listPage.rows.shouldBeLoaded();
Expand All @@ -135,7 +134,7 @@ describe('Kubernetes resource CRUD operations', () => {
listPage.rows.shouldExist(name);
cy.testA11y(`Search page for ${kind}: ${name}`);

cy.log('link to to details page');
// link to to details page
listPage.rows.clickRowByName(name);
cy.url().should('include', `/${name}`);
detailsPage.titleShouldContain(name);
Expand Down
Expand Up @@ -39,7 +39,7 @@ describe('Monitoring: Alerts', () => {
});

it('displays and filters the Alerts list page, links to detail pages', () => {
cy.log('use vert. nav. menu to goto Monitoring -> Alerting');
cy.log('use sidebar nav to goto Monitoring -> Alerting');
nav.sidenav.clickNavLink(['Monitoring', 'Alerting']);
// TODO, switch to 'listPage.titleShouldHaveText('Alerting');', when we switch to new test id
cy.byLegacyTestID('resource-title').should('have.text', 'Alerting');
Expand Down
2 changes: 1 addition & 1 deletion test-prow-e2e.sh
Expand Up @@ -9,7 +9,7 @@ INSTALLER_DIR=${INSTALLER_DIR:=${ARTIFACT_DIR}/installer}
function copyArtifacts {
if [ -d "$ARTIFACT_DIR" ] && [ -d "$SCREENSHOTS_DIR" ]; then
echo "Copying artifacts from $(pwd)..."
cp -rv "$SCREENSHOTS_DIR" "${ARTIFACT_DIR}/gui_test_screenshots"
cp -r "$SCREENSHOTS_DIR" "${ARTIFACT_DIR}/gui_test_screenshots"
fi
}

Expand Down

0 comments on commit 66a08e0

Please sign in to comment.