我正在尝试将 Allure 报告与 Cypress 集成到我的项目中。正在创建 Allure 报告,但未生成 allure-results 文件夹。以下是我已采取的步骤和已设置的配置。 先决条件
cypress.config.ts
const { defineConfig } = require('cypress');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
require('@shelex/cypress-allure-plugin/writer')(on, config);
return config;
},
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
reporter: 'cypress-mochawesome-reporter',
reporterOptions: {
reportDir: 'cypress/reports',
overwrite: false,
html: false,
json: true,
},
env: {
allureReuseAfterSpec: true,
},
},
});
cypress/support/index.ts
import '.';
import './commands';
import '@shelex/cypress-allure-plugin';
我的测试文件示例,cypress/e2e/sample_test.cy.ts
describe('Sample Test', () => {
it('should pass', () => {
expect(true).to.equal(true);
});
});
package.json
"@shelex/cypress-allure-plugin": "^2.40.2",
"allure-commandline": "^2.29.0",
"cypress": "^13.13.1",
"cypress-mochawesome-reporter": "^3.8.2"
}, "dependencies": {
"typescript": "^5.5.4"
}
使用以下命令运行 Cypress 测试:
npx cypress run
或
npx cypress run --env allure=true --spec cypress/e2e/test/sample_test.cy.ts --browser electron --headed
问题:
采取的故障排除步骤:
注意:
任何帮助将不胜感激!
您的支持文件名为
cypress/support/index.ts
,但默认名称为 cypress/support/e2e.{js,jsx,ts,tsx}
,请参阅测试特定于类型的选项 - e2e。
如果您使用此配置更新
cypress.config.js
,
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
require('@shelex/cypress-allure-plugin/writer')(on, config);
return config;
},
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'cypress/support/index.ts',
...
},
})
它现在会调用
import '@shelex/cypress-allure-plugin'
。