You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jasmine2-HTML-Reporter异常:仅生成首个Spec报告且自动清理失效

解决Jasmine2-HTML-Reporter仅生成第一个Spec报告且无法自动清理旧报告的问题

我一眼就发现了你的配置里藏着关键问题,结合你描述的症状,咱们一步步来解决:

1. 修正配置结构错误(核心原因)

你的capabilities对象里错误地嵌套了specs、framework、showColors等全局配置项——这些属性本该属于exports.config的根级别,而不是放在浏览器能力配置里。这种结构混乱会导致Protractor无法正确识别多Spec的执行流程,自然只会生成第一个Spec的报告。

2. 添加自动清理旧报告的配置项

Jasmine2HtmlReporter默认不会自动删除旧报告/截图,需要手动开启cleanDestination和cleanOnStart两个选项来实现自动清理。

修正后的完整conf.js配置

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
    // seleniumAddress: 'http://localhost:444/wd/hub',
    params: require('Models/Baths.js'),
    directConnect: true,
    // 全局配置项移到根级别
    specs: ['Specs/001-First.js', 'Specs/003-Exp.js'],
    allScriptsTimeout: 120000,
    getPageTimeout: 30000,
    framework: 'jasmine2',
    showColors: true,
    isVerbose: true,
    // 浏览器能力配置只保留浏览器相关属性
    capabilities: {
        cssSelectorsEnabled: true,
        browserName: 'chrome'
    },
    onPrepare: function() {
        jasmine.getEnv().addReporter(
            new Jasmine2HtmlReporter({
                takeScreenshots: true,
                savePath: './Reports',
                fileName: 'B&Q',
                // 开启自动清理旧报告
                cleanDestination: true,
                cleanOnStart: true
            })
        );
        var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
        jasmine.getEnv().addReporter(
            new SpecReporter({
                displayStacktrace: true,
                displayFailureSummary: true,
                displayPendingSummary: true,
                displaySuccessfulSpec: true,
                displayFailedSpec: true,
                displaySpecDuration: true,
                displaySuiteNumber: false,
                colors: {
                    success: 'green',
                    failure: 'red',
                    pending: 'yellow'
                },
                customProcessors: []
            })
        );
    }
};

额外排查建议

  • 如果修正后还是有问题,建议检查依赖版本兼容性:确保protractor、protractor-jasmine2-html-reporter、jasmine-spec-reporter的版本相互匹配,可以尝试删除node_modules和package-lock.json后重新执行npm install。
  • 确认你的Protractor版本是否支持当前的reporter版本,比如较新的Protractor可能需要更新对应的reporter包。

内容的提问来源于stack exchange,提问作者David Redmayne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:19:33