我将 Cypress 13.1.0 与 Allure 集成(allure-cypress v.3.0.4)。 生成的 html 报告中的每个测试步骤都会被截断为最多 132 个字符(请参阅附件)。
有没有办法在每个步骤中显示完整的响应和请求正文?
尝试使用 cy 日志并将请求/响应正文作为附件。没有运气。
发送请求功能:
const sendApiRequest = ({
method,
url,
headers = {},
body = null,
queryParams = {},
}) => {
return cy
.request({
method: method,
url: url,
headers: headers,
body: body,
qs: queryParams,
failOnStatusCode: false,
})
.then(response => {
if (response.status < 200 || response.status >= 300) {
cy.log(`Request failed with status: ${response.status}`);
cy.log(`Response body: ${JSON.stringify(response.body)}`);
throw new Error(
`API request failed with status: ${response.status} and response body: ${JSON.stringify(response.body)}`,
);
}
return cy.wrap(response);
});
};
cypress.config.js
const { defineConfig } = require('cypress');
const { allureCypress } = require('allure-cypress/reporter');
const allureWriter = require('@shelex/cypress-allure-plugin/writer');
module.exports = defineConfig({
reporterOptions: {
charts: true,
reportPageTitle: 'Test API',
embeddedScreenshots: false,
saveAllAttempts: false,
},
e2e: {
experimentalRunAllSpecs: true,
specPattern: 'cypress/api-specs/**/*.spec.{js,jsx,ts,tsx}',
setupNodeEvents(on, config) {
allureWriter(on, config);
allureCypress(on, config, {
resultsDir: 'allure-results',
});
require('@cypress/grep/src/plugin')(config);
return config;
},
},
trashAssetsBeforeRuns: true,
headless: true,
env: {
grepFilterSpec: true,
grepOmitFiltered: true,
allureReuseAfterSpec: true,
},
});
通过 cypress.config.js 中的选项解决了
stepsFromCommands: {
maxArgumentLength: 1500,
},