var Test1 = function (testcases) {
var testData = testcases
var testResult = false;
var startTime;
var endTime;
var day = currentDate();
describe(`Test Case: ${testData[0].testname}`, function () {
this.timeout(40000);
this.slow(100);
console.log(testData.length);
before(function* () {
nightmare = Nightmare(testSetting.nightmare);
});
for (var i = 0; i < testData.length; i++) {
console.log("At least we make it here,line27");
it('Check page ' + testData[i].testname, function* () {
console.log("At least we make it here,line29");
startTime = currentTime();
var folderNameforResult = `TestResultJSONs`;
var folderNameforCaseByCase = `TestResultJSONs/${testData[i].testname}`;
JSONFolderCreate(folderNameforResult);
JSONFolderCreate(folderNameforCaseByCase);
console.log("At least we make it here,line35");
yield nightmare
.goto(testData[i].loc)
.wait(testData[i].SEL) // Coverage search box
.then(() => {
console.log(testData[i].testname + ' Landing page is loaded.');
testResult = true;
endTime = currentTime();
console.log(startTime, endTime, day);
OutputJSON(testData[i].testname, testResult, startTime, endTime, testData[i].SEL, testData[i].loc, day);
})
.catch(error => {
console.log(testData[i].testname + ' Landing page fail.');
testResult = false;
endTime = currentTime();
mailFail(testData[i].testname, testData[i].loc);
console.log(startTime, endTime, day);
OutputJSON(testData[i].testname, testResult, startTime, endTime, testData[i].SEL, testData[i].loc, day);
})
});
}
after(function* () {
yield nightmare.end();
})
})
}
Result: 125 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27 At least we make it here,line27
Test Case: personal_home_tc_ At least we make it here,line29 1) Check page personal_home_tc_
0 passing (29ms) 1 failing
1) Test Case: personal_home_tc_ Check page personal_home_tc_: TypeError: Cannot read property 'testname' of undefined at Context. (test_template1.js:32:78) at Generator.next () at onFulfilled (node_modules\co\index.js:65:19) at C:\Users\robert.lui\Documents\nightmare\node_modules\co\index.js:54:5 at new Promise () at co (node_modules\co\index.js:50:10) at Context.args.(anonymous function) (node_modules\mocha-generators\index.js:25:6)
Seems like the for loop run line27 for 125 times first and simply skip all the content in the it(), which are the most important part. How can I make it run normally, which means run line27,then get to then or then to get result, then go back to line27 for 125 times?
Actually, it's not wierd. Jest runs test asynchronously. So, when you call it('...', () => { ... })
it won't run it, but just schedule. Since you're using var
to define variable, you have the same value when test executed. Use it.each()
for such cases, or at least you should switch to let
in your loop.