refs: #7782 Cypress features #891

Merged
alexm merged 5 commits from cypress_features into dev 2024-11-08 07:31:47 +00:00
3 changed files with 69 additions and 4 deletions
Showing only changes of commit ed8225bf6c - Show all commits

View File

@ -12,7 +12,7 @@ describe('VnLocation', () => {
cy.viewport(1280, 720);
cy.login('developer');
cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 });
cy.waitForElement('.q-card');
cy.domContentLoad();
cy.get(createLocationButton).click();
});
it('should filter provinces based on selected country', () => {

View File

@ -27,6 +27,10 @@
// DO NOT REMOVE
// Imports Quasar Cypress AE predefined commands
// import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
Cypress.Commands.add('waitUntil', { prevSubject: 'optional' }, require('./waitUntil'));
Cypress.Commands.add('resetDB', () => {
cy.exec('pnpm run resetDatabase');
});
Cypress.Commands.add('login', (user) => {
//cy.visit('/#/login');
cy.request({
@ -50,10 +54,12 @@ Cypress.Commands.add('login', (user) => {
});
});
Cypress.Commands.add('waitForElement', (element, timeout = 5000) => {
cy.get(element, { timeout }).should('be.visible');
Cypress.Commands.add('domContentLoad', (element, timeout = 5000) => {
cy.waitUntil(() => cy.document().then((doc) => doc.readyState === 'complete'));
});
Cypress.Commands.add('waitForElement', (element, timeout = 5000) => {
cy.waitUntil(() => cy.get(element).then(($el) => $el.is(':visible')));
});
Cypress.Commands.add('getValue', (selector) => {
cy.get(selector).then(($el) => {
if ($el.find('.q-checkbox__inner').length > 0) {

View File

@ -0,0 +1,59 @@
const waitUntil = (subject, checkFunction, originalOptions = {}) => {
if (!(checkFunction instanceof Function)) {
throw new Error(
'`checkFunction` parameter should be a function. Found: ' + checkFunction
);
}
const defaultOptions = {
// base options
interval: 200,
timeout: 5000,
errorMsg: 'Timed out retrying',
// log options
description: 'waitUntil',
log: true,
customMessage: undefined,
logger: Cypress.log,
verbose: false,
customCheckMessage: undefined,
};
const options = { ...defaultOptions, ...originalOptions };
// filter out a falsy passed "customMessage" value
options.customMessage = [options.customMessage, originalOptions].filter(Boolean);
const endTime = Date.now() + options.timeout;
const check = (result) => {
if (result) {
return result;
}
if (Date.now() >= endTime) {
const msg =
options.errorMsg instanceof Function
? options.errorMsg(result, options)
: options.errorMsg;
throw new Error(msg);
}
cy.wait(options.interval, { log: false }).then(() => {
return resolveValue();
});
};
const resolveValue = () => {
const result = checkFunction(subject);
const isAPromise = Boolean(result && result.then);
if (isAPromise) {
return result.then(check);
} else {
return check(result);
}
};
return resolveValue();
};
export default waitUntil;