Upload request data
The plugin is able to record web requests executed by cy.request
which can then be added as execution evidence to the test execution issue during the results upload.
Setup
To upload your web requests and responses to Xray, you need to allow the plugin to overwrite the existing cy.request
command in your support file and enable the upload in its configuration:
- commands.js
- cypress.config.js
import "@csvtuda/cypress-xray-plugin/commands";
For details see uploadRequests
.
import { configureXrayPlugin } from "@csvtuda/cypress-xray-plugin";
async setupNodeEvents(on, config) {
await configureXrayPlugin(on, config, {
// ...
xray: {
uploadRequests: true
}
});
}
By default, requests and responses are uploaded as JSON data with the following naming scheme:
type | scheme |
---|---|
request | <method> <url> <timestamp> request.json |
response | <method> <url> <timestamp> response.json |
The plugin will only upload requests and responses as JSON evidence for tests that are associated with existing test issues.
cy.request
for other purposes?The plugin also exports its task queue so that you can invoke it manually, rather than letting the single import override all existing cy.request
behaviour.
This also allows for customisation of evidence file names.
- commands.js
- cypress.config.js
import {
enqueueTask,
PluginTask,
} from "@csvtuda/cypress-xray-plugin/commands/tasks";
Cypress.Commands.overwrite("request", (originalFn, request) => {
return enqueueTask(PluginTask.OUTGOING_REQUEST, "my-request.json", request)
.then((request) => {
// Do something with the request...
console.log(request);
return request;
})
.then(originalFn)
.then((response) => {
// Do something with the response...
console.log(response);
return enqueueTask(
PluginTask.INCOMING_RESPONSE,
"my-response.json",
response
);
});
});
You can also choose to only upload responses if you wish:
import {
enqueueTask,
PluginTask,
} from "@csvtuda/cypress-xray-plugin/commands/tasks";
Cypress.Commands.overwrite("request", (originalFn, request) => {
return originalFn(request).then((response) => {
return enqueueTask(
PluginTask.INCOMING_RESPONSE,
"my-response.json",
response
);
});
});
For details see uploadRequests
.
import { configureXrayPlugin } from "@csvtuda/cypress-xray-plugin";
async setupNodeEvents(on, config) {
await configureXrayPlugin(on, config, {
// ...
xray: {
uploadRequests: true
}
});
}