Allure html 报告与 Cypress 集成,截断请求和响应正文数据

问题描述 投票:0回答:1

我将 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,
  },
});

javascript automated-tests cypress allure
1个回答
0
投票

通过 cypress.config.js 中的选项解决了

    stepsFromCommands: {
          maxArgumentLength: 1500,
        },

© www.soinside.com 2019 - 2024. All rights reserved.