I am testing 2 products. 1 for users and 1 for employees. The user creates a request and then it is processed by the employee. I generate an object with random test data. Based on this data, I create a request on product 1 and want to process it on product 2. Firstly, to find it, and secondly, to check the correctness of the data transfer. My problem is that different data is generated for each “it” function, despite the fact that I generate them outside the “it” functions. As I understand it, the problem is that I call “cy.visit” in each “it” function, because I am testing 2 products. And because of this, the state is reset between tests. The object itself does not change during the tests, only data is pulled from there.
Schematically my code looks like this:
describe('Creating request as a new client', () => {
const testUserData: TestUserData = TestDataGeneration.generateTestUserData();
beforeEach(() => {
cy.clearCookies();
cy.clearLocalStorage();
});
it('User creating a request', () => {
createRequestByUser(testUserData);
});
it('Request processing by an employee', () => {
approveRequestByEmployee(testUserData);
});
});
Tried creating an object in the “before” function.
let testUserData: TestUserData;
before(() => {
testUserData = TestDataGeneration.generateTestUserData();
});
Tried saving it in the “cy.session” session
beforeEach(() => {
cy.session('testUserData', () => {
const testUserData = TestDataGeneration.generateTestUserData();
return testUserData;
});
});
...
it('', () => {
cy.session('testUserData').then((testUserData) => {
Tried saving it in the “cy.env” environment
before(() => {
const data = TestDataGeneration.generateTestUserData();
Cypress.env('testUserData', data);
});
...
it('', () => {
const testUserData = Cypress.env('testUserData');
Tried saving it in local storage
before(() => {
const testUserData = TestDataGeneration.generateTestUserData();
cy.window().then((win) => {
win.localStorage.setItem('testUserData', JSON.stringify(testUserData));
});
});
...
it('', () => {
cy.window().then((win) => {
const testUserData = JSON.parse(win.localStorage.getItem('testUserData') || '{}');
registrationAndCreateApplication(testUserData);
});
});
None of this helped. What other options could there be? Thanks in advance for your help.