I am writing Automation scripts using protractor. I have created a java script file in which I have created a function.
PlatformviewCnOPage is my JS file and searchCapabilityOfferingsName is function. I want to call this function in another function (in same file).
var PlatformviewCnOPage = function() {
this.searchCapabilityOfferingsName = function(){
coreutil.clickElement(objectrepo.platformView_Searchbox_EnterBtn,'xpath');
browser.sleep(2000);
var searchResult= coreutil.getTextofElement(objectrepo.platformView_SearchResult,'xpath');
return searchResult;
}
I want to use the above function ie searchCapabilityOfferingsName in another function in same java script file. I have tried some combinations but its not working.Basically I am new to java script.
this.verifySearchinCnO = function(){
this.searchCapabilityOfferingsName();// Failed-method not defined
searchCapabilityOfferingsName(); //Failed method not defined
Create object of same file and call the function. // Failed.
}
};
module.exports = PlatformviewCnOPage;
Could anyone suggest how can I call the function in another function in same JS file?
PlatformviewCnOPage is defined as object/function which contains the method searchCapabilityOfferingsName.
So you can easily call PlatformviewCnOPage.searchCapabilityOfferingsName()
There should be some mistake in your PlatformviewCnOPage.js which lead to some definitions missing even loaded by require
.
You can try below steps to figure out the wrong place:
Step 1 comment out other codes only except function: verifySearchinCnO
and searchCapabilityOfferingsName
Step 2 add a console.log(xxx)
as first line of the function: verifySearchinCnO
and searchCapabilityOfferingsName
Step 3 run your test script again, if the both console.log(xxx)
print out, means the wrong place in functions you commented out, then remove comment of some code lines and run test script again until find the correct place.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.