Webdriver.io - Unable to load spec files quite likely because they rely on `browser` object

Viewed 17696

I'm using Webdriver.io to run tests on a large number of pages. Because all the specs for the pages are in a JSON file, I have a special class that sets up the test. It looks like this:

module.exports = class PageTester {
    suiteName = '';
    browser = {};

    constructor (suiteName, browser) {
        this.suiteName = suiteName;
        this.browser = browser;
    }

    testModel(currentModel) {

        describe(this.suiteName + ' endpoint ' + currentModel.url, () => {
            this.browser.url(currentModel.url);
    
            /* it() statements for the test */

        });
    }        
}

Then in my specs folder I have a file that loads the JSON and plugs it into the PageTester class, like this:

const PageTester = require('../modules/PageTester');

const models = require('/path/to/some/file.json');
const pageTester = new PageTester('Some Name', browser);

for (const modelName in models) {
    pageTester.testModel(models[modelName]);
}

When I run this code, WebdriverIO gives me the following warning:

WARN @wdio/mocha-framework: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
`browser` object has only `capabilities` and some flags like `isMobile`.
Helper files that use other `browser` commands have to be moved to `before` hook.
Spec file(s): /suite/test/specs/test.js

All the tests seem to run fine, so I don't actually understand what this warning is complaining about and what negative consequences ignoring it may have. So I would like to a) understand why this is happening and b) how it would be possible to get rid of this warning given the way my code is set up.

2 Answers

In my case, I resolve it by fixing the path for the require files. I noticed that my path was wrong. But the error that wdio throws is not really helpful. :/

Related