2015-04-06 163 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); 
}); 
相关问题