proud-ice-52191
04/18/2023, 5:47 AMCypress.Commands.add('createNewEntity', (entityType, entityData) => {
// Customize the API endpoint based on the entity type
let endpoint;
let modal;
// Code here to manage endpoint and the create form modal
// Intercept the create request
cy.intercept('POST', env.baseUrlAPI + endpoint).as('createRequest');
// Fill in the form fields based on the entity data
// cy.get(modal).within(() => {
Object.entries(entityData).forEach(([labelText, value]) => {
cy.fillField(modal, labelText, value);
});
cy.get('data-testId='create-button').click({ force: true });
// });
// Close the create modal and wait for the response
cy.get('.mdi-close').click();
cy.wait('@createRequest').its('response.status code).should('eq', 200);
// Verify that the entity was created
// extra assertions code goes here.
Now for instance I can now call this inside my tests using
// to be loaded by data from the customer fixture
// Create a new entity
cy.createNewEntity('customer', {
'first name': 'Test',
'last name': 'Tests',
'email': 'test001@test.com',
'phone': '0923823525',
'location': '32a Test',
'password': '12345678',
'confirm password': '12345678',
});
This works, however, I am not entirely sure if it is recommended, what are your thoughts?echoing-tent-95037
04/18/2023, 3:58 PMenough-truck-68085
04/18/2023, 5:00 PMcommands file clean since it can get really large over time. Here's an example
https://cdn.discordapp.com/attachments/1097760206483628062/1097929781066076301/image.png▾
echoing-tent-95037
04/18/2023, 5:08 PMproud-ice-52191
04/18/2023, 5:12 PM