Files
odo/ui/cypress/support/commands.ts
Armel Soro c0af267fd5 Fix Dev UI Cypress E2E tests (#6967)
* Start the API Server from the UI component itself

* Store Cypress screenshots and videos as test artifacts upon test failures

This should make it easier to understand and investigate.

* Increase timeout to find element via getByDataCy

The default timeout used to cause certain flakiness at times.

* Install Terminal Report Plugin [1] to log useful information about Cypress runs

It outputs actions, intercepted requests, console messages and errors directly to stdout in a convenient format.

[1] https://github.com/archfz/cypress-terminal-report

* Revert "Increase timeout to find element via getByDataCy"

This reverts commit 410b5c6c3f.

* Intercept network calls when clearing or saving DevState and wait until we get successful responses

In some cases, clicking too quickly led to inconsistent behavior, where for example the Containers tab would not be up-to-date yet

* Disable Angular telemetry when running 'ng serve'
2023-07-15 11:56:29 +02:00

72 lines
2.5 KiB
TypeScript

/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
Cypress.Commands.add('getByDataCy', (value: string) => {
cy.get('[data-cy="'+value+'"]');
});
Cypress.Commands.add('selectTab', (n: number) => {
cy.get('div[role=tab]').eq(n).click();
});
Cypress.Commands.add('setDevfile', (devfile: string) => {
cy.intercept('GET', '/api/v1/devstate/chart').as('getDevStateChart');
cy.intercept('PUT', '/api/v1/devstate/devfile').as('applyDevState');
cy.get('[data-cy="yaml-input"]').type(devfile);
cy.get('[data-cy="yaml-save"]').click();
cy.wait(['@applyDevState', '@getDevStateChart']);
});
Cypress.Commands.add('clearDevfile', () => {
cy.intercept('GET', '/api/v1/devstate/chart').as('getDevStateChart');
cy.intercept('DELETE', '/api/v1/devstate/devfile').as('clearDevState');
cy.intercept('PUT', '/api/v1/devstate/devfile').as('applyDevState');
cy.get('[data-cy="yaml-clear"]', { timeout: 60000 }).click();
cy.wait(['@clearDevState', '@applyDevState', '@getDevStateChart']);
});
declare namespace Cypress {
interface Chainable {
getByDataCy(value: string): Chainable<void>
selectTab(n: number): Chainable<void>
setDevfile(devfile: string): Chainable<void>
clearDevfile(): Chainable<void>
}
}