Protractor+Typescript框架并行执行Feature后Cucumber报告未更新
问题描述
- 已配置Protractor+Cucumber实现Feature文件并行执行,但执行完成后Cucumber报告始终仅显示最后一次执行结果
- 每个Feature执行后都会生成独立的JSON文件,怀疑是导致报告异常的诱因
解决方案
以下是针对你的config.ts需要调整的关键配置项:
1. 修正JSON报告的生成路径,避免并行时文件覆盖
在cucumberOpts的format配置中,将固定文件名改为带进程ID占位符的路径,确保每个并行实例生成唯一的JSON文件:
cucumberOpts: { // 其他配置不变 format: 'json:./reports/json/cucumber-report-<%= process.pid %>.json', require: [ './StepDefinitions/**/*.js' ] },
说明:<%= process.pid %>会自动替换为当前进程的ID,避免多个并行进程同时写入同一个JSON文件导致覆盖。
2. 统一使用protractor-multiple-cucumber-html-reporter-plugin生成合并报告
你当前同时启用了两种报告生成逻辑(onComplete中的cucumber-html-reporter和plugins中的多报告插件),这会导致冲突。建议保留后者,因为它专门针对并行执行场景设计:
- 移除
onComplete中的报告生成代码 - 调整
plugins中的配置,指定JSON文件的存放目录和报告输出路径:
plugins: [{ package: require.resolve('protractor-multiple-cucumber-html-reporter-plugin'), options: { automaticallyGenerateReport: true, removeExistingJsonReportFile: true, openReportInBrowser: true, jsonOutputPath: './reports/json/', // 指定JSON文件的存放目录 reportPath: './reports/html/', // 报告输出目录 pageTitle: "Project Report", pageFooter: "<div><p>Protractor with cucumber</p></div>", customData: { title: 'Offer Creation UI test report', data: [ { label: 'Project', value: 'Eternals UI Automation' }, { label: 'Created By', value: 'Drashti Gadhia' } ] } } }],
3. 修正报告目录的拼写错误
你当前代码中存在目录名拼写错误:TestExecutinReport应为TestExecutionReport,如果继续使用原逻辑,需要修正该拼写,否则会导致报告生成失败。
4. 移除冗余的afterLaunch合并逻辑
由于protractor-multiple-cucumber-html-reporter-plugin会自动合并所有JSON文件生成统一报告,因此可以移除afterLaunch中的手动合并HTML代码,避免重复操作。
修改后的完整config.ts示例
import { Config } from 'protractor'; import * as reporter from 'cucumber-html-reporter'; export let config: Config = { seleniumAddress: 'http://localhost:4444/wd/hub', framework: 'custom', frameworkPath: require.resolve('protractor-cucumber-framework'), capabilities: { browserName: 'chrome', acceptInsecureCerts: true, shardTestFiles: true, maxInstances: 2, chromeOptions: { args: ["--disable-site-isolation-trials"] } }, suites: { bau: '../FeatureFiles/BAU/**/*.feature', santoriniTest: '../FeatureFiles/Santorini/**/*.feature', installmentconfig: '../FeatureFiles/BAU/InstallmentConfig/*.feature', panlist: '../FeatureFiles/BAU/Panlist.feature', merchantlist: '../FeatureFiles/BAU/Merchantlist.feature', subaccount: '../FeatureFiles/Maintenance/subaccountrange.feature', all: '../FeatureFiles/**/*.feature', notification: '../FeatureFiles/notificationauto.feature' }, specs: ['../FeatureFiles/Santorini/ETAETGOfferCreation/TC2765844.feature', '../FeatureFiles/Santorini/SPPSPSOfferCreation/TC2796855.feature'], rootElement: '[ng-app]', cucumberOpts: { format: 'json:./reports/json/cucumber-report-<%= process.pid %>.json', require: [ './StepDefinitions/**/*.js' ] }, plugins: [{ package: require.resolve('protractor-multiple-cucumber-html-reporter-plugin'), options: { automaticallyGenerateReport: true, removeExistingJsonReportFile: true, openReportInBrowser: true, jsonOutputPath: './reports/json/', reportPath: './reports/html/', pageTitle: "Project Report", pageFooter: "<div><p>Protractor with cucumber</p></div>", customData: { title: 'Offer Creation UI test report', data: [ { label: 'Project', value: 'Eternals UI Automation' }, { label: 'Created By', value: 'Drashti Gadhia' } ] } } }] };
内容的提问来源于stack exchange,提问作者dggadhia
相关产品推荐
相关产品推荐

