无法加载规范文件很可能是因为它们依赖于未完全初始化的“浏览器”对象

问题描述 投票:0回答:1

我有一个适用于 webdriverio 的测试,但是当我将浏览器移动到一个类中时,出现此错误:

Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.

班级:

/* eslint-disable require-jsdoc */
/* eslint-disable no-trailing-spaces */
/* eslint-disable indent */
/* eslint-disable linebreak-style */

//import {browser} from '@wdio/globals';
//const browser = require('@wdio/globals');

/**
 * A class that handles DashboardPage
 */
//export default class DashboardPage {
class DashboardPage {
    /**
    * Opens the browser.
    * @param {int} num1 The first number.
    * @param {int} num2 The second number.
    * @return {int} The sum of the two numbers.
    */
    async open() {  
        await browser.url('https://www.demoblaze.com');
        await browser.pause(200);
    }
}

// export default new DashboardPage();
module.exports = DashboardPage;

测试:

//const DashboardPage = require('../../po/pages/dashboard.page');
import {expect} from 'chai';
import DashboardPage from '../../po/pages/dashboard.page';

const dashboardPage = new DashboardPage();

describe('CSS selectors section', () => {
    describe('DemoBlaze Home Page', () => {
        beforeEach(async () => {              
            await dashboardPage.open();
            // await browser.url('https://www.demoblaze.com');    
            // await browser.pause(200); 
        });

        it('Sony vaio i7 title on card should exist', async () => { 
            const form = await $('div:nth-child(9) > div > div > h4 > a');
            expect(form).to.exist;
        });        
    });
});

wdio.conf.js 规范 './src/tests/specs/**/*.js',

package.json:

{
  "name": "automated-testing-with",
  "type": "module",
  "version": "1.0.0",
  "description": "init testing example",
  "main": "index.js",
  "scripts": {
    "test": "mocha",
    "wdio": "wdio run ./wdio.conf.js"
  },
  "repository": {
    "type": "git",
    "url": "https://git.epam.com/jhon_hernandez/automated-testing-with-js"
  },
  "author": "Jhon Hernandez",
  "license": "ISC",
  "devDependencies": {
    "@wdio/allure-reporter": "^8.15.0",
    "@wdio/browser-runner": "^8.14.6",
    "@wdio/cli": "^8.14.6",
    "@wdio/junit-reporter": "^8.15.0",
    "@wdio/local-runner": "^8.15.4",
    "@wdio/mocha-framework": "^8.14.0",
    "@wdio/spec-reporter": "^8.14.0",
    "eslint": "^8.46.0",
    "eslint-config-google": "^0.14.0",
    "geckodriver": "^4.2.0",
    "mocha": "^10.2.0",
    "wdio-geckodriver-service": "^5.0.2"
  },
  "dependencies": {
    "c8": "^8.0.1",
    "chai": "^4.3.7",
    "chromedriver": "^115.0.1",
    "husky": "^8.0.3",
    "mocha": "^10.2.0",
    "mochawesome": "^7.1.3",
    "wdio-chromedriver-service": "^8.1.1",
    "webdriverio": "^8.14.3"
  }
}

我检查了路线,尝试了几种导入类的方法,但错误仍然存在

控制台没有显示太多指导我的真实信息。

当您使用导入的文件时,如何操作?

javascript class testing chai webdriver-io
1个回答
0
投票

您是否尝试过 const DashboardPage = require('../../po/pages/dashboard.page');

我看到它被留下作为评论。

© www.soinside.com 2019 - 2024. All rights reserved.