How to call this.function in a same file where we create the fileHow do I include a JavaScript file in another JavaScript file?How do I return the response from an asynchronous call?Check if element is visible and than do the code below - Jasmine JSFailed: Cannot read property 'getWebElements' of undefinedGetting control flow error once I'm navigating back to webdriver methods after completing async operation using control flowProtractor - Getting “Runtime.executionContextCreated has invalid 'context” error when i run ProtractorElement is not clickable at point in protractorTypeError: Cannot read property 'getText' of undefinedjavascript return statement returning undefinedProtractor assert that an element is not visible
What is the opposite of 'gravitas'?
What will be the temperature on Earth when Sun finishes its main sequence?
Can a malicious addon access internet history and such in chrome/firefox?
How do I rename a LINUX host without needing to reboot for the rename to take effect?
Simple recursive Sudoku solver
Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?
Science Fiction story where a man invents a machine that can help him watch history unfold
Can a Bard use an arcane focus?
Adding empty element to declared container without declaring type of element
How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?
Who must act to prevent Brexit on March 29th?
Why are on-board computers allowed to change controls without notifying the pilots?
Why is delta-v is the most useful quantity for planning space travel?
Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)
Should my PhD thesis be submitted under my legal name?
Can I use my Chinese passport to enter China after I acquired another citizenship?
Why Were Madagascar and New Zealand Discovered So Late?
Simulating a probability of 1 of 2^N with less than N random bits
Can I Retrieve Email Addresses from BCC?
Lifted its hind leg on or lifted its hind leg towards?
A known event to a history junkie
Calculating the number of days between 2 dates in Excel
Invariance of results when scaling explanatory variables in logistic regression, is there a proof?
What to do when my ideas aren't chosen, when I strongly disagree with the chosen solution?
How to call this.function in a same file where we create the file
How do I include a JavaScript file in another JavaScript file?How do I return the response from an asynchronous call?Check if element is visible and than do the code below - Jasmine JSFailed: Cannot read property 'getWebElements' of undefinedGetting control flow error once I'm navigating back to webdriver methods after completing async operation using control flowProtractor - Getting “Runtime.executionContextCreated has invalid 'context” error when i run ProtractorElement is not clickable at point in protractorTypeError: Cannot read property 'getText' of undefinedjavascript return statement returning undefinedProtractor assert that an element is not visible
in my project we tried to build protractor framework. so in js file we create some functions using this.functionname syntax and we want to re use that function when it required in the function which is also present in the same file. for clear view i gave the code below...
this is my reusable functions JS file
var fb=require("H:/workspace/Protractor_PT/src/pages/FbPage.js");
var action=function()
beforeAll(function()
browser.ignoreSynchronization=true;
browser.get("https://facebook.com");
login();
);
this.clickElement=function(element)
element.click();
this.enterText=function(element,text)
element.sendKeys(text);
var login=function()
action.enterText(fb.emailField(),"dfdsfds");
action.enterText(fb.passfield(),"dfdsfds");
module.login=new action();
on top, you can find the functions this.clickElement and this.enterText.. i want to use those functions in the other function named login.. but when i called those functions with "action.enterText" - action is the main global variable of the file... i'm getting below error
Error Log
Message:
Failed: action.enterText is not a function
Stack:
TypeError: action.enterText is not a function
at login (H:workspaceProtractor_PTsrcpagesUtilities.js:19:13)
at UserContext.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:7:3)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:112:25
at new ManagedPromise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
at ControlFlow.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
at schedulerExecute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:95:18)
at TaskQueue.execute_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
at TaskQueue.executeNext_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
at asyncRun (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
From: Task: Run beforeAll in control flow
at UserContext.<anonymous> (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:94:19)
at Jasmine.execute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminelibjasmine.js:200:12)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractorbuiltframeworksjasmine.js:132:15
at Function.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesqq.js:682:9)
From asynchronous test:
Error
at new action (H:workspaceProtractor_PTsrcpagesUtilities.js:4:2)
at Object.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:23:14)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
1 spec, 1 failure
Finished in 0.049 seconds
[20:22:32] I/launcher - 0 instance(s) of WebDriver still running
[20:22:32] I/launcher - chrome #01 failed 1 test(s)
[20:22:32] I/launcher - overall: 1 failed spec(s)
[20:22:32] E/launcher - Process exited with error code 1
javascript node.js selenium-webdriver protractor
|
show 1 more comment
in my project we tried to build protractor framework. so in js file we create some functions using this.functionname syntax and we want to re use that function when it required in the function which is also present in the same file. for clear view i gave the code below...
this is my reusable functions JS file
var fb=require("H:/workspace/Protractor_PT/src/pages/FbPage.js");
var action=function()
beforeAll(function()
browser.ignoreSynchronization=true;
browser.get("https://facebook.com");
login();
);
this.clickElement=function(element)
element.click();
this.enterText=function(element,text)
element.sendKeys(text);
var login=function()
action.enterText(fb.emailField(),"dfdsfds");
action.enterText(fb.passfield(),"dfdsfds");
module.login=new action();
on top, you can find the functions this.clickElement and this.enterText.. i want to use those functions in the other function named login.. but when i called those functions with "action.enterText" - action is the main global variable of the file... i'm getting below error
Error Log
Message:
Failed: action.enterText is not a function
Stack:
TypeError: action.enterText is not a function
at login (H:workspaceProtractor_PTsrcpagesUtilities.js:19:13)
at UserContext.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:7:3)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:112:25
at new ManagedPromise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
at ControlFlow.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
at schedulerExecute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:95:18)
at TaskQueue.execute_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
at TaskQueue.executeNext_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
at asyncRun (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
From: Task: Run beforeAll in control flow
at UserContext.<anonymous> (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:94:19)
at Jasmine.execute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminelibjasmine.js:200:12)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractorbuiltframeworksjasmine.js:132:15
at Function.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesqq.js:682:9)
From asynchronous test:
Error
at new action (H:workspaceProtractor_PTsrcpagesUtilities.js:4:2)
at Object.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:23:14)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
1 spec, 1 failure
Finished in 0.049 seconds
[20:22:32] I/launcher - 0 instance(s) of WebDriver still running
[20:22:32] I/launcher - chrome #01 failed 1 test(s)
[20:22:32] I/launcher - overall: 1 failed spec(s)
[20:22:32] E/launcher - Process exited with error code 1
javascript node.js selenium-webdriver protractor
1
when the inner functions are created theaction
is unknown to them. you probably has to do a local variable which points the the action function and use it instead of action. like, first line of action function do this: localAction = this; then uselocalAction.enterText
– V. Sambor
Mar 21 at 14:56
kk..i will try and update it
– Satish Rongala
Mar 21 at 15:02
1
@V.Sambor - your comment seems like the answer - you should avoid answering the question in a comment and actually use an answer.
– DrCord
Mar 21 at 15:04
it is working...it is very helpful to me.. and also i have one more problem.. if want to use that login function how can i use that..
– Satish Rongala
Mar 21 at 15:05
Ok I will answer properly :)
– V. Sambor
Mar 21 at 15:08
|
show 1 more comment
in my project we tried to build protractor framework. so in js file we create some functions using this.functionname syntax and we want to re use that function when it required in the function which is also present in the same file. for clear view i gave the code below...
this is my reusable functions JS file
var fb=require("H:/workspace/Protractor_PT/src/pages/FbPage.js");
var action=function()
beforeAll(function()
browser.ignoreSynchronization=true;
browser.get("https://facebook.com");
login();
);
this.clickElement=function(element)
element.click();
this.enterText=function(element,text)
element.sendKeys(text);
var login=function()
action.enterText(fb.emailField(),"dfdsfds");
action.enterText(fb.passfield(),"dfdsfds");
module.login=new action();
on top, you can find the functions this.clickElement and this.enterText.. i want to use those functions in the other function named login.. but when i called those functions with "action.enterText" - action is the main global variable of the file... i'm getting below error
Error Log
Message:
Failed: action.enterText is not a function
Stack:
TypeError: action.enterText is not a function
at login (H:workspaceProtractor_PTsrcpagesUtilities.js:19:13)
at UserContext.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:7:3)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:112:25
at new ManagedPromise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
at ControlFlow.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
at schedulerExecute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:95:18)
at TaskQueue.execute_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
at TaskQueue.executeNext_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
at asyncRun (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
From: Task: Run beforeAll in control flow
at UserContext.<anonymous> (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:94:19)
at Jasmine.execute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminelibjasmine.js:200:12)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractorbuiltframeworksjasmine.js:132:15
at Function.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesqq.js:682:9)
From asynchronous test:
Error
at new action (H:workspaceProtractor_PTsrcpagesUtilities.js:4:2)
at Object.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:23:14)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
1 spec, 1 failure
Finished in 0.049 seconds
[20:22:32] I/launcher - 0 instance(s) of WebDriver still running
[20:22:32] I/launcher - chrome #01 failed 1 test(s)
[20:22:32] I/launcher - overall: 1 failed spec(s)
[20:22:32] E/launcher - Process exited with error code 1
javascript node.js selenium-webdriver protractor
in my project we tried to build protractor framework. so in js file we create some functions using this.functionname syntax and we want to re use that function when it required in the function which is also present in the same file. for clear view i gave the code below...
this is my reusable functions JS file
var fb=require("H:/workspace/Protractor_PT/src/pages/FbPage.js");
var action=function()
beforeAll(function()
browser.ignoreSynchronization=true;
browser.get("https://facebook.com");
login();
);
this.clickElement=function(element)
element.click();
this.enterText=function(element,text)
element.sendKeys(text);
var login=function()
action.enterText(fb.emailField(),"dfdsfds");
action.enterText(fb.passfield(),"dfdsfds");
module.login=new action();
on top, you can find the functions this.clickElement and this.enterText.. i want to use those functions in the other function named login.. but when i called those functions with "action.enterText" - action is the main global variable of the file... i'm getting below error
Error Log
Message:
Failed: action.enterText is not a function
Stack:
TypeError: action.enterText is not a function
at login (H:workspaceProtractor_PTsrcpagesUtilities.js:19:13)
at UserContext.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:7:3)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:112:25
at new ManagedPromise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
at ControlFlow.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
at schedulerExecute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:95:18)
at TaskQueue.execute_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
at TaskQueue.executeNext_ (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
at asyncRun (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
From: Task: Run beforeAll in control flow
at UserContext.<anonymous> (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminewd2index.js:94:19)
at Jasmine.execute (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesjasminelibjasmine.js:200:12)
at C:UsersDELLAppDataRoamingnpmnode_modulesprotractorbuiltframeworksjasmine.js:132:15
at Function.promise (C:UsersDELLAppDataRoamingnpmnode_modulesprotractornode_modulesqq.js:682:9)
From asynchronous test:
Error
at new action (H:workspaceProtractor_PTsrcpagesUtilities.js:4:2)
at Object.<anonymous> (H:workspaceProtractor_PTsrcpagesUtilities.js:23:14)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
1 spec, 1 failure
Finished in 0.049 seconds
[20:22:32] I/launcher - 0 instance(s) of WebDriver still running
[20:22:32] I/launcher - chrome #01 failed 1 test(s)
[20:22:32] I/launcher - overall: 1 failed spec(s)
[20:22:32] E/launcher - Process exited with error code 1
javascript node.js selenium-webdriver protractor
javascript node.js selenium-webdriver protractor
asked Mar 21 at 14:53
Satish RongalaSatish Rongala
457
457
1
when the inner functions are created theaction
is unknown to them. you probably has to do a local variable which points the the action function and use it instead of action. like, first line of action function do this: localAction = this; then uselocalAction.enterText
– V. Sambor
Mar 21 at 14:56
kk..i will try and update it
– Satish Rongala
Mar 21 at 15:02
1
@V.Sambor - your comment seems like the answer - you should avoid answering the question in a comment and actually use an answer.
– DrCord
Mar 21 at 15:04
it is working...it is very helpful to me.. and also i have one more problem.. if want to use that login function how can i use that..
– Satish Rongala
Mar 21 at 15:05
Ok I will answer properly :)
– V. Sambor
Mar 21 at 15:08
|
show 1 more comment
1
when the inner functions are created theaction
is unknown to them. you probably has to do a local variable which points the the action function and use it instead of action. like, first line of action function do this: localAction = this; then uselocalAction.enterText
– V. Sambor
Mar 21 at 14:56
kk..i will try and update it
– Satish Rongala
Mar 21 at 15:02
1
@V.Sambor - your comment seems like the answer - you should avoid answering the question in a comment and actually use an answer.
– DrCord
Mar 21 at 15:04
it is working...it is very helpful to me.. and also i have one more problem.. if want to use that login function how can i use that..
– Satish Rongala
Mar 21 at 15:05
Ok I will answer properly :)
– V. Sambor
Mar 21 at 15:08
1
1
when the inner functions are created the
action
is unknown to them. you probably has to do a local variable which points the the action function and use it instead of action. like, first line of action function do this: localAction = this; then use localAction.enterText
– V. Sambor
Mar 21 at 14:56
when the inner functions are created the
action
is unknown to them. you probably has to do a local variable which points the the action function and use it instead of action. like, first line of action function do this: localAction = this; then use localAction.enterText
– V. Sambor
Mar 21 at 14:56
kk..i will try and update it
– Satish Rongala
Mar 21 at 15:02
kk..i will try and update it
– Satish Rongala
Mar 21 at 15:02
1
1
@V.Sambor - your comment seems like the answer - you should avoid answering the question in a comment and actually use an answer.
– DrCord
Mar 21 at 15:04
@V.Sambor - your comment seems like the answer - you should avoid answering the question in a comment and actually use an answer.
– DrCord
Mar 21 at 15:04
it is working...it is very helpful to me.. and also i have one more problem.. if want to use that login function how can i use that..
– Satish Rongala
Mar 21 at 15:05
it is working...it is very helpful to me.. and also i have one more problem.. if want to use that login function how can i use that..
– Satish Rongala
Mar 21 at 15:05
Ok I will answer properly :)
– V. Sambor
Mar 21 at 15:08
Ok I will answer properly :)
– V. Sambor
Mar 21 at 15:08
|
show 1 more comment
1 Answer
1
active
oldest
votes
In your case when the inner functions are created the variable action is unknown to them.
You can do a local variable which points to the parent function and use it instead of the action.
You can do something like this:
var fb = require('H:/workspace/Protractor_PT/src/pages/FbPage.js')
var action = function ()
var localAction = this; // <<<----------- HERE
beforeAll(function ()
browser.ignoreSynchronization = true
browser.get('https://facebook.com')
login()
)
this.clickElement = function (element)
element.click()
this.enterText = function (element, text)
element.sendKeys(text)
var login = function ()
localAction.enterText(fb.emailField(), 'dfdsfds') // Use local var here.
localAction.enterText(fb.passfield(), 'dfdsfds')
module.login = new action()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283271%2fhow-to-call-this-function-in-a-same-file-where-we-create-the-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your case when the inner functions are created the variable action is unknown to them.
You can do a local variable which points to the parent function and use it instead of the action.
You can do something like this:
var fb = require('H:/workspace/Protractor_PT/src/pages/FbPage.js')
var action = function ()
var localAction = this; // <<<----------- HERE
beforeAll(function ()
browser.ignoreSynchronization = true
browser.get('https://facebook.com')
login()
)
this.clickElement = function (element)
element.click()
this.enterText = function (element, text)
element.sendKeys(text)
var login = function ()
localAction.enterText(fb.emailField(), 'dfdsfds') // Use local var here.
localAction.enterText(fb.passfield(), 'dfdsfds')
module.login = new action()
add a comment |
In your case when the inner functions are created the variable action is unknown to them.
You can do a local variable which points to the parent function and use it instead of the action.
You can do something like this:
var fb = require('H:/workspace/Protractor_PT/src/pages/FbPage.js')
var action = function ()
var localAction = this; // <<<----------- HERE
beforeAll(function ()
browser.ignoreSynchronization = true
browser.get('https://facebook.com')
login()
)
this.clickElement = function (element)
element.click()
this.enterText = function (element, text)
element.sendKeys(text)
var login = function ()
localAction.enterText(fb.emailField(), 'dfdsfds') // Use local var here.
localAction.enterText(fb.passfield(), 'dfdsfds')
module.login = new action()
add a comment |
In your case when the inner functions are created the variable action is unknown to them.
You can do a local variable which points to the parent function and use it instead of the action.
You can do something like this:
var fb = require('H:/workspace/Protractor_PT/src/pages/FbPage.js')
var action = function ()
var localAction = this; // <<<----------- HERE
beforeAll(function ()
browser.ignoreSynchronization = true
browser.get('https://facebook.com')
login()
)
this.clickElement = function (element)
element.click()
this.enterText = function (element, text)
element.sendKeys(text)
var login = function ()
localAction.enterText(fb.emailField(), 'dfdsfds') // Use local var here.
localAction.enterText(fb.passfield(), 'dfdsfds')
module.login = new action()
In your case when the inner functions are created the variable action is unknown to them.
You can do a local variable which points to the parent function and use it instead of the action.
You can do something like this:
var fb = require('H:/workspace/Protractor_PT/src/pages/FbPage.js')
var action = function ()
var localAction = this; // <<<----------- HERE
beforeAll(function ()
browser.ignoreSynchronization = true
browser.get('https://facebook.com')
login()
)
this.clickElement = function (element)
element.click()
this.enterText = function (element, text)
element.sendKeys(text)
var login = function ()
localAction.enterText(fb.emailField(), 'dfdsfds') // Use local var here.
localAction.enterText(fb.passfield(), 'dfdsfds')
module.login = new action()
edited Mar 21 at 15:39
answered Mar 21 at 15:13
V. SamborV. Sambor
2,0251229
2,0251229
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283271%2fhow-to-call-this-function-in-a-same-file-where-we-create-the-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
when the inner functions are created the
action
is unknown to them. you probably has to do a local variable which points the the action function and use it instead of action. like, first line of action function do this: localAction = this; then uselocalAction.enterText
– V. Sambor
Mar 21 at 14:56
kk..i will try and update it
– Satish Rongala
Mar 21 at 15:02
1
@V.Sambor - your comment seems like the answer - you should avoid answering the question in a comment and actually use an answer.
– DrCord
Mar 21 at 15:04
it is working...it is very helpful to me.. and also i have one more problem.. if want to use that login function how can i use that..
– Satish Rongala
Mar 21 at 15:05
Ok I will answer properly :)
– V. Sambor
Mar 21 at 15:08