Reputation: 1418
I am calling a function which has switch case statement and it returns a value. Now I am trying to pass this returned value to a second function in my protractor-cucumber test.
When(/^A function is callled$/, function(fields) {
obj.each(fields.hashes(), function(value) {
filePath = util.Function_1(value.a, value.b, value.c);
console.log(filePath);
response = util.Function_2(filePath);
});
});
Function in Util file:
Function_1(a, b, c){
var num =1;
switch (num) {
case "1": {
var filePath = "dummy path-1 to a file";
console.log("Inside case-1");
break;
}
case "2": {
var filePath = "Construct file path using a, b and c";
console.log("Inside case-2");
break;
}
}
return filePath;
}
Second function:
Function_2(filePath){
console.log("Inside second function");
//To Do
}
I am able to print the value returned from Function_1 in my When section. But the test is finishing right after printing the returned value. Its not calling the second function.
I tried creating a promise and returning it from Function_1. But couldn't make it work.
Upvotes: 0
Views: 166
Reputation: 2734
The problem is, that your variable "num" is actually a number and in the switch case statement you are looking for a string. Change your Function_1 as follows and it would work:
Function_1(a, b, c){
var num =1;
switch (num) {
case 1: {
var filePath = "dummy path-1 to a file";
console.log("Inside case-1");
break;
}
case 2: {
var filePath = "Construct file path using a, b and c";
console.log("Inside case-2");
break;
}
}
return filePath;
}
Either check for strings with content '1', '2' etc. Or numbers and then check for 1, 2 etc.
Upvotes: 1