我用对象创建了一个数组,数组大小为10;在我的测试阶段,我需要输入带有对象的所有10个数组元素;点击按钮即可更新每个数据。
it('22 should create 10 new leads with valid inputs', function(){
asyncLoop({
length : 10,
functionToLoop : function(loop, i){
newLeadButton.click().then(function() {
expect(browser.getLocationAbsUrl()).toMatch('/create');
firstNameField.sendKeys( leadArray2[i+1].firstName );
lastNameField.sendKeys( leadArray2[i+1].lastName );
meetingTimeField.sendKeys( leadArray2[i+1].meetingTime );
emailField.sendKeys( leadArray2[i+1].email );
mobileField.sendKeys( leadArray2[i+1].mobileNumber );
phoneField.sendKeys( leadArray2[i+1].phoneNumber );
closeDateField.sendKeys( leadArray2[i+1].closeDate );
address1Field.sendKeys( leadArray2[i+1].address1 );
address2Field.sendKeys( leadArray2[i+1].address2 );
cityField.sendKeys( leadArray2[i+1].city );
createLeadButton.click().then(function() {
expect(browser.getLocationAbsUrl()).toMatch('/lead');
expect(leadListElems.count()).toMatch(i+6);
loop();
});
});
},
callback : function(){
expect(leadListElems.count()).toMatch(14);
}
});
});
// http://stackoverflow.com/questions/4288759/asynchronous-for-cycle-in-javascript
var asyncLoop = function(o){
var i=-1;
var loop = function(){
i++;
if(i==o.length){o.callback(); return;}
o.functionToLoop(loop, i);
}
loop();//init
}
此代码中的问题是我的第一个数组元素没有打印,我需要帮助打印所有10个数组元素及其对象。
var leadArray2=[
{
firstName : '1',
lastName : '1',
meetingTime : '01/12/2016 10:00 am',
email : 'yokname1@gmail.com',
mobileNumber : '9876543210',
phoneNumber : '7894561230',
closeDate : '01/01/2018',
address1 : 'Address Line 1 A',
address2 : 'Address Line 1 B',
city : 'City 1'
},
{
firstName : '2',
lastName : '2',
meetingTime : '02/12/2016 11:00 am',
email : 'yokname2@gmail.com',
mobileNumber : '9876543211',
phoneNumber : '7894561231',
closeDate : '02/01/2017',
address1 : 'Address Line 2 A',
address2 : 'Address Line 2 B',
city : 'City 2'
}, ...................];
答案 0 :(得分:0)
您正在调用o.functionToLoop(loop, i);
i = 0
,而您正在leadArray2[i+1]
,因此您获得的是元素1,而不是0。