2015-04-06 96 views

回答

79

getText()返回一個承諾文本任何其他方式,你需要決心它:

page.clientRowName.getText().then(function (text) { 
    console.log(text); 
}); 

或者,如果你只是想斷言文,讓expect()解決承諾爲您提供:

expect(page.clientRowName.getText()).toEqual("ABC"); 

Promises and the Control Flow文檔頁面應該明確的事情了。

+1

如果您正在使用Chai期望值,它有一個'.eventually'方法來解析承諾並從裏面獲取值。 'expect(page.clientRowName.getText())。to.eventually.equal(「ABC」)' –

0

我通常使用element.getAttribute('value')

+6

這對'

ABC

'有效嗎? – LeeGee

2

另一種解決方案可以是使用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); 
}); 
相關問題