Untitled
unknown
plain_text
8 months ago
954 B
4
Indexable
Never
Cypress.Commands.add('setMethod', (method) => { Cypress.state('requestMethod') = method; }); Cypress.Commands.add('setEndpoint', (endpoint) => { Cypress.state('endpoint') = endpoint; }); Cypress.Commands.add('addBody', (key, value) => { if (!Cypress.state('requestBody')) { Cypress.state('requestBody', {}); } Cypress.state('requestBody')[key] = value; }); Cypress.Commands.add('addHeader', (key, value) => { if (!Cypress.state('requestHeaders')) { Cypress.state('requestHeaders', {}); } Cypress.state('requestHeaders')[key] = value; }); Cypress.Commands.add('sendRequest', () => { const requestBody = Cypress.state('requestBody'); const requestHeaders = Cypress.state('requestHeaders'); const requestMethod = Cypress.state('requestMethod'); const endpoint = Cypress.state('endpoint'); return cy.request({ method: requestMethod, url: endpoint, headers: requestHeaders, body: requestBody }); });
Leave a Comment