This is do around Cypress context. You want to constantly chain. Cypress denotes that you should follow this convention:
cy.then(() => assignSubjectValue);
Some of the reasoning is that during the test, the element assigned may no longer be visible in the DOM which can make the tests flaky.
describe('Eval Cycles', () => { describe('Listing page', () => { beforeEach(() => { cy.visit(url, { timeout: 120000 }); }); it('creates a new evaluation cycle by clicking the button', () => { cy.getByAutomationId(Aid.id, 0).click(); }); }); });
This isContext
value will help get the context ie "record", "playback" etc. We can use that value to then determine this works.
describe('Eval Cycles', () => { describe('Listing page', () => { beforeEach(() => { cy.visit(url, { timeout: 120000 }); }); it('creates a new evaluation cycle by clicking the button', () => { cy.getByAutomationId(Aid.id, 0).click().isContext("record").then(recording) => { if (recording) { cy.wait("@POST") } }; }); }); });
cy.setCookie('cookie', 'value');
cy.window().then(win => { win.localStorage.setTime('topNavTourComplete', 'true'); });
These will reset the subject.
Cypress has a list of recommended ways and ways that are not recommended.
Check in the cypress/support
file/folder.