2016-02-13 63 views
1

不执行我能够获得与下面的计数值:for循环量角器

element.all(by.options('type as type for type in types')).then(function(elems){ 
    return elems.length; 
}) 
.then(function(count){ 
    cnt = count; 
}); 

然后后面我想在使用cnt for循环,我也用封闭代码:

for(var x = 1;x < cnt; x++){ 
    search_options(x); 
} 

function test(y){ 
    console.log('input'+y); 
} 

function search_options(input){ 
    it('tess', function(){ 
     test(input); 

    }); 
} 

问题是for不执行。

任何提示或建议,指导表示赞赏或指出任何错误。 我已阅读关于IIFE,但我发现大多数样本使用阵列,我相信'cnt'已解决

不幸的是,我不得不使用for循环。 '每个'都不适合。

回答

1

问题是cnt只能在控制流程机制解决承诺时设置。 for循环将在之前执行

取而代之的是,cnt的承诺,在您的测试解决它:

cnt = element.all(by.options('type as type for type in types')).count(); 

cnt.then(function (actualCount) { 
    for(var x = 1; x < actualCount; x++){ 
     search_options(x); 
    } 
}); 

另见:Using protractor with loops

而且,我不能完全肯定,如果动态地创建it s此方式将实际工作,这里有一些相关的主题:

+0

嗨,THX一堆,我会尝试一下,让你知道它是如何发生的。 – edm

+0

嗨Alecxe,谢谢你的帮助。在'search_options(x)'中有几条语句,其中一条不执行/ resolve:'code' element.all(by.options('type as type for type in types'))。count()。then (function(e){ \te [input] .click(); }); '代码'任何帮助或反馈表示赞赏。 – edm

+0

@edmond好,很难说,因为我没有办法重现你的问题。你确定循环应该从1开始而不是0?谢谢。 – alecxe