Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 量角器js,不通过';结果';_Javascript_Angularjs_Protractor - Fatal编程技术网

Javascript 量角器js,不通过';结果';

Javascript 量角器js,不通过';结果';,javascript,angularjs,protractor,Javascript,Angularjs,Protractor,在我的dragrator.test.js中 it('should make sure that there are listings on the page', function() { var count = element.all(by.repeater('res in result')); count.then(function(result){ expect(result.length).toBeGreaterThan(0); }, 5000); })

在我的dragrator.test.js中

it('should make sure that there are listings on the page', function()
{
    var count = element.all(by.repeater('res in result'));
    count.then(function(result){
    expect(result.length).toBeGreaterThan(0);
    }, 5000);

})
在我的index.html中

  <div class="item item-text-wrap" ng-click="post($event,res)"  ng-repeat="res in result"  ng-controller="recommendedJobsCtrl" ui-sref="menu.jobDetails" >


问题是它说0应该大于0。但当我在测试中把它改为res或者其他任何单词时,它仍然会给我相同的答案。我不认为它在读取我的结果

为什么不直接使用量角器的
count()
方法-

it('should make sure that there are listings on the page', function()
{
var EC = protractor.ExpectedConditions;
var el = element.all(by.repeater('res in result'));
browser.wait(EC.visibilityOf(el), 5000);
expect(el.count()).toBeGreaterThan(0);
})
我部分同意您应该使用
count()
,但您不能在元素上使用预期条件(这就是
元素返回的内容)

相反,您也可以尝试使用一个helper函数,该函数取自

用法:

var userNav = element.all(by.css('li.navbar-item'));
// wait for userNav to have 4 elements/buttons
Util.presenceOfAll(userNav, 4).then(function () {
    // your code
});
还要注意的是,量角器补丁程序
希望
隐式处理承诺,所以除非您正在做其他事情,否则不需要在
.count()
之后使用
.then()
。因此,将其应用到您的代码中,我将通过以下方式对其进行修改:

it('should make sure that there are listings on the page', function() {
    var count = element.all(by.repeater('res in result'));
    Util.presenceOfAll(count, 5); // change 5 for whatever number should be there
    expect(count.count()).toEqual(5);

    // could also have been written as this since presenceOfAll returns a promise
    Util.presenceOfAll(count, 5).then(function() { 
         expect(count.count()).toEqual(5);
    });
});

代码的唯一问题是,您从未实际计算所选的元素

it('should make sure that there are listings on the page', function()
{
    var results = element.all(by.repeater('res in result'));
    results.count().then(function(count){
    expect(count).toBeGreaterThan(0);
    }, 5000);

})

上面的例子应该适合您。请注意,为了清晰起见,我更改了一些变量名。

我看不出您的代码中有任何问题。在执行测试时,可能尚未创建元素。请尝试至少等待一个元素。@FlorentB。5000美元不是一个等待期吗?是否有其他方法来处理等待?第二个参数应该是可选的拒绝回调。所以不,它不会等待5000毫秒。看看
浏览器。等待
:@FlorentB。你能给我举个例子吗?你可以使用显式等待来确定可见性,更新我的答案!另外,请使用
浏览器。暂停
浏览器。调试程序
以了解该特定元素发生的情况。您应该尝试@Gunderson建议的方法+谢谢你纠正我。我假设EC将与
元素一起工作。所有
也是,是的,它返回一个
元素数组查找器
@我希望它能与work element一起使用。all:(将非常有用
it('should make sure that there are listings on the page', function()
{
    var results = element.all(by.repeater('res in result'));
    results.count().then(function(count){
    expect(count).toBeGreaterThan(0);
    }, 5000);

})