Osa*_*san 2 javascript integer count protractor
I want to count the elements in a list and then access the integer, not a Promise object. So starting with:
var questionList = questionContainer.all(by.className('someclass'));
Run Code Online (Sandbox Code Playgroud)
如果该类有三个子元素,我想console.log(questionList.count())输出整数3,而不是Promise对象.这甚至可能吗?即使它是一些操作上的Promise.
protractor有这样的count()方法ElementArrayFinder:
expect(questionList.count()).toEqual(3);
Run Code Online (Sandbox Code Playgroud)
注意,count()返回一个promise,expect()被"修补"以隐式解决promise.
例如,如果您需要在控制台上打印实际值,请使用以下方法明确解决承诺then():
questionList.count().then(function (count) {
console.log(count);
});
Run Code Online (Sandbox Code Playgroud)
或者,甚至更简单:
questionList.count().then(console.log);
Run Code Online (Sandbox Code Playgroud)