I am new to protractor, because i dont have much knowledge on Javascript its becoming difficult to predict the script execution flow. I have very basic question on the behavior of the protractor promises and flow of data between js files.
I have one commonTC.js which has describe(),it() block. In this 'it' block i call functions at runtime. Means, i have functions such as open(),click(),enter() written in another js file which gets called dynamically at run time as per function call data is read from excel.
In protractor most browser interaction returns promise, thus when i do logic of browser calls in click()/enter() these return promise, i wanted to get the details of browser calls in commonTC.js which is the calling file.
So i made function call as promise() in commonTC.js
dynamicActions[enter()].then(()=>{
console.log("Success Activity:")
}).catch((err)=>{
console.log("Error on Activity():")
throw err;
});
In ActivityAction.js(), the function definition is as below
this.dynamicActions.enter = function () {
var deferred = protractor.promise.defer();
element(by.id("username")).sendKeys("abc").then(
function success() {
deferred.fulfill();
},
function error(reason) {
deferred.reject(reason);
});
return deferred.promise;
}
My question is- 1. Because of this architecture all the function calls are required to be returned as promise.If i do not return the promise, does the browser promise result will i be knowing in commonTC.js? 2. Also by this architecture, is all the function calls are synchronous. Because all the functions are made to return as promise, so will those promise execute serially? i mean after 1st promise resolve, is it guaranteed 2nd promise will be executed/ or it might pick 5th also? 3. if it picks promise execution randomly then how can i achieve serial execution of promises? 4. If am required to remove promise architecture in commonTC.js then how to make sure each function open()/enter() returns failure/success?