I am working on a diagnostic application which can ask the user quite a large number of questions (100+). I had been using a recursive function to deal with the questions and their answering but i noticed over time the tests would slow down to a crawl and after a lot of research I've come to realize that its probably the recursion that's doing it. Any help would be much appreciated.
The current solution is this:
Cypress.Commands.add('intro_Questions', (data) => {
const intro_Questions_Loop = () => {
cy.get('@question_tree').then(question_tree => {//gets the current question tree
cy.get('@link').then(link => { //get the question number
if (action == 'LAST') {
return;
}
cy.Question({q: link, qt: question_tree, question_log: data.fixture}) //checks the question on screen vs question tree
cy.Answer({q: link, qt: question_tree}) //picks a random answer and wraps action with the next question code
cy.editAnswer({}) //edits questions at random dependant on set percentage
intro_Questions_Loop();
})
})
}
intro_Questions_Loop();
})
Any help to improve, make it more efficient or just to write it in a different way would be much appreciated!