如何为具有多重性的量角器生成多个黄瓜报告?

时间:2017-12-11 03:03:39

标签: protractor cucumberjs

我正在使用多个浏览器并行运行针对BrowserStack的量角器。请参阅“https://www.browserstack.com/automate/protractor

中的'加速测试部分'

它工作得很好,但是如果我使用4个webdriver实例来并行运行相同的功能文件,它将会有1个html黄瓜报告。

我用Google搜索了这个:https://github.com/wswebcreation/protractor-multiple-cucumber-html-reporter-plugin,它似乎能够生成多个json文件,但是没有html文件。

我是量角器的新手。任何人都可以提出一些建议,或者一些可以实现这一目标的代码更改或插件吗?

感谢,

1 个答案:

答案 0 :(得分:0)

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var JasmineReporters = require('jasmine-reporters');

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    framework: 'jasmine2',
    multiCapabilities: [
        {
            browserName: 'chrome',
            shardTestFiles: false,
            maxInstances: 1,
            specs: [
                './tmp/specs1.spec.js',
                './tmp/specs2.spec.js'
            ],
            chromeOptions: {
                args: [
                    '--window-size=1920,1080'],
                prefs: {
                    download: {
                        prompt_for_download: false,
                        default_directory: './downloads',
                    }
                }
            }
        },
        {
            browserName: 'chrome',
            shardTestFiles: false,
            maxInstances: 1,
            specs: [
                './tmp/specs3.spec.js',
                './tmp/specs4.spec.js'
            ],
            chromeOptions: {
                args: [
                    '--window-size=1920,1080'],
                prefs: {
                    download: {
                        prompt_for_download: false,
                        default_directory: './downloads',
                    }
                }
            }
        }
    ],
    allScriptsTimeout: 600000,
    jasmineNodeOpts: {
        defaultTimeoutInterval: 600000,
        showColors: true
    },
    onPrepare: function() {
        browser.driver.getCapabilities().then(function(caps) {
            browser.browserName = caps.get('browserName');
        });

        var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
        browser.getProcessedConfig().then(function(config) {
            var capabilities = config.capabilities;
            jasmine.getEnv().addReporter(
                new Jasmine2HtmlReporter({
                    savePath: './reports/',
                    takeScreenshots: true,
                    screenshotsFolder: './screenshots',
                    filePrefix: 'protractor-demo-tests-report-' + capabilities.platform + '-' + capabilities.browserName,
                    consolidateAll: false,
                    takeScreenshotsOnlyOnFailures: true,
                })
            );
        });

        var jasmineReporters = require('jasmine-reporters');
        return browser.getProcessedConfig().then(function(config) {
            // you could use other properties here if you want, such as platform and version
            var browserName = config.capabilities.browserName;
            var junitReporter = new jasmineReporters.JUnitXmlReporter({
                consolidateAll: false,
                savePath: 'reports/jUnitXmlReporter',
                modifyReportFileName: function(generatedFileName, suite) {
                    return browserName + '.' + generatedFileName;
                }
            });
            jasmine.getEnv().addReporter(junitReporter);
            //set window size to max available
            setTimeout(function() {
                browser.driver.executeScript(function() {
                    return {
                        width: window.screen.availWidth,
                        height: window.screen.availHeight
                    };
                }).then(function(result) {
                    browser.driver.manage().window().setPosition(0,0);
                    browser.driver.manage().window().setSize(result.width, result.height);
                });
            });
        });
    }
};