0

I am trying to configure and use HTML Reporter for WebDriverIO as per the instructions here: https://webdriver.io/docs/rpii-wdio-html-reporter.html

It says that I need to add an import statement in my wdio.conf.js file like this:

// wdio.conf.js
import { ReportAggregator, HtmlReporter} from '@rpii/wdio-html-reporter' ;
module.exports = {

However, when I do that and try to run my tests I get the following error:

import { ReportAggregator, HtmlReporter} from '@rpii/wdio-html-reporter' ; ^

SyntaxError: Unexpected token {

It won't let me use any import statements here at all.

Does anybody know why not?

Here is my full wdio.conf.js content:

const config = require('./Lib/config')
// wdio.conf.js
import { ReportAggregator, HtmlReporter} from '@rpii/wdio-html-reporter' ;

exports.config = {

    runner: 'local',
   
    specs: [
        My tests here
    ],
  
    exclude: [

    ],
    
    maxInstances: 10,
    
    capabilities: [{
        
        maxInstances: config.maxInstance,
        //
        browserName: 'chrome',
        
    }],
    
    logLevel: config.logLevel,
  
    bail: config.bail,
   
    baseUrl: 'http://localhost',
   
    waitforTimeout: 15000,
    
    connectionRetryTimeout: 120000,
 
    connectionRetryCount: 3,
    
    services: [   'chromedriver'
      
    ],
    
   
    framework: 'mocha',
  
    reporters: ['spec']
    [HtmlReporter, {
        debug: true,
        outputDir: './reports/html-reports/',
        filename: 'report.html',
        reportTitle: 'Test Report Title',
        
        //to show the report in a browser when done       showInBrowser: true,

   
        useOnAfterCommandForScreenshot: false,

        
        LOG: log4j.getLogger("default")
    }
    ],
    
    mochaOpts: {
        // Babel setup
        require: ['@babel/register'],
        ui: 'bdd',
        timeout: 60000
    },
    
}
Matt
  • 773
  • 2
  • 15
  • 30

3 Answers3

2

instead of using

import { ReportAggregator, HtmlReporter} from '@rpii/wdio-html-reporter' ;

try using

const {ReportAggregator, HtmlReporter} = require('@rpii/wdio-html-reporter');

1

Try adding require('@babel/register'); at the top of the file.

Punit Gupta
  • 3,808
  • 1
  • 18
  • 22
0

This is ES6 import syntax so you need to compile your config with Babel first or use ES5 import with require. Also you've got a typo in your config, reporters should be an array and inside that array you can set a reporter with a string (with default options) or an array with a name of reporter and an option object like that:

reporters: [ 'spec', [HtmlReporter, { outputDir: './reports/html-reports/', ... } ] ]

beauvoir
  • 67
  • 1
  • 9