我有一個元素定義爲量角器: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」)' –