Forum Discussion

elenavivequi's avatar
elenavivequi
New Contributor
15 years ago

JUnit: Calling a function from another file

Hi All,



I'm running TestComplete 8 and I'm testing using Script tests, rather than Keyword tests. I'm using JScript as my language and am testing a .NET website. My goal is to create a test that can work across browsers. I've followed the Cross-Browser script example here and it works successfully for running the example web test provided by TestComplete. However, I want to replace the example web test with my own web test and the way I can think to achieve this is to use the example file and replace the function that creates and runs the web test with a function call to my own web test in another file.



Specifically:

Using the example project XBrowserScript (links you to a ZIP file FYI), I'd like to use the "JUunit1_NM" script, but modify it by replacing the function 'function DoWebTest(browser)' with a function call to my own web test in another script (.pjs) file. Then I'll run it from the main() function and it should make my test cross-browser compatible.



What I need help with:

I'm not sure how to write a function call to a function in another web file using JScript. I know that my function in the separate file will need to pass a variable, too, but I'm not sure which variable either.



Please let me know if you can help and let me know what other information you need.



Thanks!!

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You'll have two units of code, essentially.  One will contain the function to be called, the other will do the calling.  The file doing the calling, add at the top of the file a //USEUNIT call.



    //USEUNIT MyUnitName




    You can then call any functions in MyUnitName from the calling unit.



    See this topic for more information.



    http://smartbear.com/support/viewarticle/11452/
  • Thanks for the quick reply Robert I'm trying out those resources you linked.