有时我在测试中遇到奇怪的错误,我想调试它。 我尝试使用 getAttribute() 或 getText() 之类的方法来执行此操作,但这些函数返回一个 promise 。 我发现如果不做出期望就很难兑现 promise 。 举个例子:
console.log(servicePage.services.get(0).getAttribute('class'));
我希望它只输出类的值,但返回了一个 promise 。我怎样才能解决这个 promise ? 我尝试使用 then(function(elem)... 函数,但下一步该怎么做? 当我在 elem 上执行像 getText() 这样的操作时,我再次陷入了 promise 。
提前致谢! 问候
最佳答案
servicePage.services.get(0).getAttribute('class')).then(function(result){
console.log(result);
});
//an example of a random function getting the text from a promise...
page.someElement.getText().then(function(txt){
console.log(txt);
});
关于javascript - 通过手动记录调试 Protractor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35310377/