Passing variables between tests in Cypress

Testing business workflows end2end with cy.task()

Photo by Aaron Burden on Unsplash

Create a task

Getters and setters

setUserId: (val) => { return (userId = val); }
getUserId: () => { return userId; }

The task ahead

cy.get('User').then(($userId) => {   cy.task('setUserId', userId);});
cy.task('getUserId').then((userId) => {   cy.get('User').type(userId);});

Wrap up

IT entrepreneur, Test Automation Specialist, trainer, DJ, and father of three. Creator at heart.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store