gpt4 book ai didi

javascript - JS : Class extends value is not a function or null

转载 作者:行者123 更新时间:2023-11-29 19:03:20 27 4
gpt4 key购买 nike

这就是我尝试使用 WebdriverIO 构建用于登录测试的第一个页面对象的方式

但我收到错误 ERROR: Class extends value #<Page> is not a function or null login.page.js 第 3 行.

我不明白,我做错了什么...路径或文件名是否错误?

/tests/specs/login.specs.js

var expect = require('chai').expect
var LoginPage = require('../pageobjects/login.page')

describe('login form', function () {
it('should deny access with wrong creds', function () {
LoginPage.open()
LoginPage.username.setValue('foo')
LoginPage.password.setValue('bar')
LoginPage.submit()
expect(LoginPage.flash.getText()).to.contain('Your username is invalid!')
})
})

/tests/pageobjects/page

'use strict'
class Page {
constructor() {
this.title = 'My Page'
}
open(path) {
browser.url('/' + path)
}
}
module.exports = new Page()

/tests/pageobjects/login.page.js

'use strict'
var Page = require('./page')
class LoginPage extends Page {
get username () { return browser.element('#username') }
get password () { return browser.element('#password') }
get form () { return browser.element('#login') }
get flash () { return browser.element('#flash') }

open () {
super.open('login')
}

submit () {
this.form.submitForm()
}
}
module.exports = new LoginPage()

最佳答案

正如 Gerardo 所指出的,您正在导出该类的一个实例并记下该类本身。尝试以下更改:

/tests/pageobjects/page

module.exports = Page;

/tests/pageobjects/login.page.js

module.exports = LoginPage;

/tests/specs/login.specs.js

var LoginPage = new (require('../pageobjects/login.page'))();

var LoginPage = require('../pageobjects/login.page');
var instanceLoginPage = new LoginPage();

关于javascript - JS : Class extends value is not a function or null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45112570/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com