Hi experts, how do you make a certain test to run ...
# help
w
Hi experts, how do you make a certain test to run only once per execution? If it is placed in support/index.js, it runs once for each spec. I want to create users for testing (which should also be a test reported as any other 'it') and then use these users in all the specs. Currently I do it using a parameter and 2 auxiliary tasks I defined in plugins/index.js (see below) and then I use them in the test defined in support/index.js using condition. The condition is true for the first spec only but the test is still counted for every spec (even if the condition is false and the main part of the test is not executed, since the condition is part of the test, the test is entered and therefore counted). I wonder if there is a better approach. Thanks!
plugins/index.js: const crossSpecsParams = {}; on('task', { saveCrossSpecsParam({key, value}) { crossSpecsParams[key] = value; return null; }, loadCrossSpecsParams(key): string { return crossSpecsParams[key] || null; },
support/index.js: it('Users creation', () => { // this test should run once per execution of all specs, not at the beginning of each spec which is Cypress's default behavior upon npm run const crossSpecsParamName = 'usersCreated'; cy.task('loadCrossSpecsParams', crossSpecsParamName).then(savedValue => { if (savedValue !== null) { return; } // create users... cy.task('saveCrossSpecsParam', {key: crossSpecsParamName, value: true}) }) })
Also, is there a better way to define parameters to be used in multiple specs than the way I do it above?
4 Views