setValue 不是函数 webdriver io 7
setValue is not a function webdriver io 7
我正在尝试使用 webdriver io 7 setValue() 的功能,但我总是收到相同的结果。
我post我的代码。
这是主页对象
import Page from './page'
class Home extends Page {
get inputUsername () { return $('#user-name') }
async open () {
await super.open('https://www.saucedemo.com/')
}
async setUser () {
this.inputUsername.setValue('fakeName')
}
}
export default new Home()
这是页面对象Page
export default class Page {
open (path) {
browser.url(path)
}
}
这是规范
import Home from '../pageobjects/home'
describe('login form', () => {
it('first login', async () => {
await Home.open()
await Home.setUser()
})
})
这是错误:
TypeError: this.inputUsername.setValue 不是函数
它发生了,因为你必须先 await
元素,然后与它交互(在你的情况下设置值)。
因此,在获取元素之前添加await
。
// Home page object
async setUser () {
// ⤵ - missed await
return (await this.inputUsername).setValue('fakeName')
}
我正在尝试使用 webdriver io 7 setValue() 的功能,但我总是收到相同的结果。
我post我的代码。
这是主页对象
import Page from './page'
class Home extends Page {
get inputUsername () { return $('#user-name') }
async open () {
await super.open('https://www.saucedemo.com/')
}
async setUser () {
this.inputUsername.setValue('fakeName')
}
}
export default new Home()
这是页面对象Page
export default class Page {
open (path) {
browser.url(path)
}
}
这是规范
import Home from '../pageobjects/home'
describe('login form', () => {
it('first login', async () => {
await Home.open()
await Home.setUser()
})
})
这是错误:
TypeError: this.inputUsername.setValue 不是函数
它发生了,因为你必须先 await
元素,然后与它交互(在你的情况下设置值)。
因此,在获取元素之前添加await
。
// Home page object
async setUser () {
// ⤵ - missed await
return (await this.inputUsername).setValue('fakeName')
}