My test include steps which need to be repeated for every test.
Tests are something like this:
- Open Login Dialog (click login button)
- Login (enter username and password)
- Navigate to private page (click menu point)
Each of the tests depends on the previous tests.
Id like to use a function like "execute previous test code" which when called within test 3, call test 2 and therefore test 1. It is also important that hooks are not executed at this point.
For hand-written tests, this is not an issue: I'd define the tests as seperate functions and call them accordingly, instead of defining then as anonymous function within the test() call.
For TestCafe Studio I felt "hacky" calling internal APIs and created this function:
function executePreviousTestCode(t) {
const id = t.testRun.test.id;
const tests = t.testRun.test.testFile.collectedTests;
const prevTestIndex = tests.findIndex(t => t.id === id) -1;
if(prevTestIndex < 0) return;
const prevTest = tests[prevTestIndex];
return prevTest.fn(t)
}
It works for normal TestCafe but I dont know how to include it in a TestCafe Studio test.
Maybe someone came up with a better solution than copy&paste or one single big test.
Aucun commentaire:
Enregistrer un commentaire