Forum Discussion

veronica_glynn's avatar
veronica_glynn
Contributor
10 years ago

Needs guidance to set up JavaScript within Scripts

Good morning!



I am having some difficulties in understanding the provided help document: Executing JavaScript. I need to run several JavaScript functions in order to perform much needed user actions and content verification on my tested application. However, I am not making much sense of the help document. I created my MyScriptFile.js and placed it in a Scripts folder within my Test Complete directory. Within that files are my 2 JavaScript functions. Now what do I do? :-)



The help doc tells me to enter:



res = pageObj.contentDocument.Script.functionName(param1, ..., paramN)



So I have entered:



res = Aliases.browser.pageCogneroTestGenerator.contentDocument.Script.GetIDOfRightPaneElement(0)



My questions:

1. Should this be a 'Function' or a 'Sub' routine?

2. How do I let Test Complete know where my scripts file resides?

3. Can I just continuously add JS to this files as the need arises?

4. Can you please help me write my first successful method so that I can understand what the heck I am trying to do? :-D 

** The JS is created to pull object information and pass it back to a variable that I will then use in another method. The 2nd JS function will perform a user action (dbl click).



Thank you so much for your help. Please let me know if anything is unclear.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    It sounds like what you've done is written JavaScript code outside of TestComplete and you want to execute it within TestComplete.  Is that a correct assumption?



    The help file you reference is for executing JavaScript that is on a Web Page from within TestComplete so it doesn't apply to your scenario, best that I can tell.



    What you'll need to do is change the file extension on your script from js to sj.  Then, within your TestComplete project, right click on the "Script" item in your project explorer, select Add -> Existing Item and browse to your file.  This should bring your code unit into TestComplete and you should be able to execute it from there. (reference http://support.smartbear.com/viewarticle/56677/)



    Hope this helps.





  • Okay, that makes sense. When I add that file to my Project Suite it yells about the syntax of my code. I am not familiar enough with JS to fix it. I muddled my way through the first function; not entirely sure it is correct.



    If I attach the file, do you think you could take a look? I do not have much support from the Dev team here to help figure this out right now ...



    Thanks much!



    Veronica 
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I'll give it a what the hey... can't guarentee a rapid response but I'll see what I can do. :-)