webdriverio-community/wdio-html-reporter

Error: Type check for option "reporters" failed: a reporter should be either a string in the format "wdio--reporter" or a function/class.

Closed this issue · 17 comments

get an error when i use HtmlReporter in my webdriverio config.

Here are the versions:

"@rpii/wdio-html-reporter": "^6.2.0",
"@wdio/allure-reporter": "^6.11.0",
"@wdio/cli": "^6.12.1",
"@wdio/cucumber-framework": "^6.11.1",
"@wdio/dot-reporter": "^6.11.0",
"@wdio/local-runner": "^6.12.1",
"@wdio/selenium-standalone-service": "^6.12.1",
"@wdio/spec-reporter": "^6.11.0",
"@wdio/sync": "^6.11.0",
"webdriverio": "6.12.1"

// ============
// Capabilities
// ============
//Defined a headless browser only
capabilities: [{
maxInstances: 0,
// //
browserName: 'chrome',
"goog:chromeOptions": {
headless: true
},
//binary: ./tools/chrome.exe,
acceptInsecureCerts: true
}],

//Reporter config in wdio config file:
let {ReportAggregator, HtmlReporter} = require('@rpii/wdio-html-reporter');
const log4j = require("log4js");
let localConfig = {
reporters: ["spec",
[HtmlReporter, {
debug: true,
outputDir: './tests/reports/output/html/',
filename: 'report.html',
reportTitle: 'Test Report Title',
showInBrowser: true,
useOnAfterCommandForScreenshot: false,
LOG: log4j.getLogger("default")
}
]
],
};
exports.config = override(localConfig, instanceConfig, true);

//Hooks:

onPrepare: function (config, capabilities) {
    let reportAggregator = new ReportAggregator({
        outputDir: './tests/reports/output/html/',
        filename: 'master-report.html',
        reportTitle: 'Master Report',
        browserName : capabilities.browserName,
        collapseTests: true,
        // to use the template override option, can point to your own file in the test project:
        // templateFilename: path.resolve(__dirname, '../template/wdio-html-reporter-alt-template.hbs')
    });
    reportAggregator.clean() ;

    global.reportAggregator = reportAggregator;
},

onComplete: function(exitCode, config, capabilities, results) {
    (async () => {
        await global.reportAggregator.createReport();
    })();
},

Errors are:

[0-0] 2021-01-22T10:48:27.990Z ERROR @wdio/runner: Error: Type check for option "reporters" failed: a reporter should be either a string in the format "wdio--reporter" or a function/class. Please see the docs for more information on custom reporters (https://webdriver.io/docs/customreporter.html)
at Object.validateConfig (./node_modules/@wdio/config/build/utils.js:118:27)

[0-1] 2021-01-22T10:48:28.011Z ERROR @wdio/local-runner: Failed launching test session: Error: Invalid reporters config
at BaseReporter.initReporter (./node_modules/@wdio/runner/build/reporter.js:103:15)

rpii commented

let localConfig = {
reporters: ["spec",
[HtmlReporter, {
debug: true,
outputDir: './tests/reports/output/html/',
filename: 'report.html',
reportTitle: 'Test Report Title',
showInBrowser: true,
useOnAfterCommandForScreenshot: false,
LOG: log4j.getLogger("default")
}
]
],
};
exports.config = override(localConfig, instanceConfig, true);

I have this defined..

rpii commented

I tried the below method as well:

My Complete config file:-
---------------------------------

let {ReportAggregator, HtmlReporter} = require('@rpii/wdio-html-reporter');
process.env.ff = (argv.ff) ? argv.ff : process.env.ff;
let featureFilePath = process.env.ff === "undefined" ? ./tests/features/featureFiles/**/*.feature : ./tests/features/featureFiles/**/${argv.ff}.feature;
exports.config = {
runner: "local",
// Patterns to exclude.
specs: [
featureFilePath
],
// ============
// Capabilities
// ============
//Defined a headless browser only
capabilities: [{
maxInstances: 0,
// //
browserName: 'chrome',
"goog:chromeOptions": {
headless: true
},
acceptInsecureCerts: true,
}],
//
// ===================
// Test Configurations
// ===================
logLevel: "error",
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
// Default request retries count
connectionRetryCount: 3,
// Test runner services
framework: "cucumber",
reporters: ['spec',
[HtmlReporter, {
debug: false,
outputDir: './tests/reports/output/html/',
filename: 'report.html',
reportTitle: 'Web Test Report',
showInBrowser: false,
useOnAfterCommandForScreenshot: false
}]
],
// If you are using Cucumber you need to specify the location of your step definitions.
cucumberOpts: {
// <string[]> (file/dir) require files before executing features
require: ["./tests/features/step_definitions/**/*.steps.js"],
strict: true,
// (expression) only execute the features or scenarios with tags matching the expression
tagExpression: "",
// timeout for step definitions
timeout: 60000,
},
};
console.log ("exportsConfig :- ",exports.config)

The Above Console.log is giving below result for the reporter part:-
---------------------------------------------------------------------

exportsConfig :- {
runner: 'local',
specs: [ './tests/features/featureFiles/**/pep-post-passingHeader.feature' ],
capabilities: [
{
maxInstances: 0,
browserName: 'chrome',
'goog:chromeOptions': [Object],
acceptInsecureCerts: true
}
],
logLevel: 'error',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
framework: 'cucumber',

reporters: [ 'spec', [ [class HtmlReporter extends WDIOReporter], [Object] ] ],

cucumberOpts: {
require: [ './tests/features/step_definitions/**/*.steps.js' ],
strict: true,
tagExpression: '',
timeout: 60000
},
}

Error message is still the same:-

[0-0] 2021-01-25T17:35:44.554Z ERROR @wdio/runner: Error: Type check for option "reporters" failed: a reporter should be either a string in the format "wdio--reporter" or a function/class. Please see the docs for more information on custom reporters (https://webdriver.io/docs/customreporter.html)
at Object.validateConfig (/node_modules/@wdio/config/build/utils.js:118:27)

[0-0] 2021-01-25T17:35:44.567Z ERROR @wdio/local-runner: Failed launching test session: Error: Invalid reporters config
at BaseReporter.initReporter (/node_modules/@wdio/runner/build/reporter.js:103:15)

rpii commented
rpii commented
rpii commented

Hi @rpii,
Do u think babel or typescript is mandatory to generate this report? Also do I need any mandatory services or Packages defined in my config and package.json respectively?

rpii commented

Thanks @rpii (Rich). I figured out the issue I guess. Need you help to understand though.
does this report work with gulp tasks?
I mean in my framework i use gulp command to execute the cases.. below is a sample:-

gulp.task('run-api', () => {
return gulp.src('tests/conf/wdio.conf.js').pipe(webdriver({
wdioBin: path.join(__dirname, 'node_modules', '.bin', cmd)
}));
});

When I run the wdio.conf.js directly without gulp task (command- npx wdio ./tests/conf/wdio.conf.js) the report is getting generated but when i use gulp command (gulp run-api ) its giving the reporter error.

Could you help me with resolving this?

rpii commented
rpii commented

obe