-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
support multiple cy.route methods at once #799
Comments
In the current state, with having to specify routes separately, is it possible to have a subsequent |
AFAIK, you can bind the same alias to different routes, and await them all by the same alias. Thus, you can make a simple helper: cy.routeMany = (routesOptions, alias) => {
routesOptions.forEach( routeOptions => {
cy.route(routeOptions).as(alias);
});
} example usage: cy.routeMany([
'/a',
'/b',
{ url: '/a', method: 'PATCH' }
], /* alias */ 'groupA' );
// make requests to test the behavior
cy.window().then(win => {
function makeRequest (method, url) {
let xhr = new win.XMLHttpRequest();
xhr.open(method, url);
xhr.send();
}
makeRequest('GET', '/a');
makeRequest('GET', '/b');
makeRequest('PATCH', '/a');
});
cy.wait('@groupA'); // 'GET /a'
cy.wait('@groupA'); // 'GET /b'
cy.wait('@groupA'); // 'PATCH /a' |
This is now possible using This is currently experimental and requires being enabled by passing Please see the So you can do: it('test', () => {
cy.route2("/folder").as("folderMod");
// so that later we can do
cy.get(selector).click(); // POST
cy.wait("@folderMod");
cy.get(selector).click(); // PATCH
cy.wait("@folderMod");
cy.get(selector).click(); // DELETE
cy.wait("@folderMod");
}) Full working example it('test cy.route()', () => {
cy.route2('/folder').as('folderMod')
cy.visit('https://example.com')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
xhr.open('POST', '/folder', {})
xhr.send()
})
cy.wait('@folderMod')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
xhr.open('PATCH', '/folder', {})
xhr.send()
})
cy.wait('@folderMod')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
xhr.open('DELETE', '/folder')
xhr.send()
})
cy.wait('@folderMod')
}) If you encounter any issues or unexpected behavior while using |
Current behavior:
currently, we need to specify routes separately:
Desired behavior:
specify several methods at once for easier management
The text was updated successfully, but these errors were encountered: