我有一个元素定义为量角器:element.getText()返回一个对象,而不是字符串
this.clientRowName = element(by.id('CLIENT_NAME')); //page object file
我想读在这个元件,其是“ABC”的文字,但这样做的: VAR客户= page.clientRowName.getText();
返回一个对象而不是一个字符串。有没有办法,我可以得到元素
我有一个元素定义为量角器:element.getText()返回一个对象,而不是字符串
this.clientRowName = element(by.id('CLIENT_NAME')); //page object file
我想读在这个元件,其是“ABC”的文字,但这样做的: VAR客户= page.clientRowName.getText();
返回一个对象而不是一个字符串。有没有办法,我可以得到元素
getText()
返回一个承诺文本任何其他方式,你需要决心它:
page.clientRowName.getText().then(function (text) {
console.log(text);
});
或者,如果你只是想断言文,让expect()
解决承诺为您提供:
expect(page.clientRowName.getText()).toEqual("ABC");
Promises and the Control Flow文档页面应该明确的事情了。
另一种解决方案可以是使用async/await
。
class Page {
constructor() {
this.clientRowName = $('#CLIENT_NAME');
}
}
/****************/
it('should console.log client name', async() => {
const client = await Page.clientRowName.getText();
console.log(client);
});
如果您正在使用Chai期望值,它有一个'.eventually'方法来解析承诺并从里面获取值。 'expect(page.clientRowName.getText())。to.eventually.equal(“ABC”)' –