Forum Discussion

prabhjot88singh's avatar
prabhjot88singh
Contributor
5 years ago

How to call a function in between 2 different scripts

Dear House,

 

I have 4 functions written inside one of the Script classes using TestComplete Script driven framework.

 

Now, I have another script class , i.e. Script 2, and I want to call all 4 or some methods from Script 1 to Script 2.

 

Pleas suggest the methods and ways to call it.

 

Best,

Prabhjot

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Prabhjot,

     

    Script units in TestComplete are not classes but just plain source code files. Depending on the script language that you use in your test project, you can declare classes and instantiate them in the same or another script unit. (Though this is not convenient in TestComplete due to some of its code editor specifics and thus is not recommended.)

    Go through the https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/index.html help section. It should answer your question.

     

  • Hi @prabhjot88singh ,

     

    if you want  to use the functions declared in unit1 to unit2 script files, you just have to give the "unit1" reference in "unit2"script file below the reference syntax.

     

    reference syntax and example:
    Vbscript: 
    syntax - " 'USEUNIT [scriptName] "
    example - (" 'USEUNIT Unit1 ") Javascript:
    syntax - " //USEUNIT [scriptName] "
    example - (" //USEUNIT Unit1 ")
    please add this in the beganning of the script where you want to use the functions (in script "Unit2")

    please find the below snippet for accessing the fumctions:

    syntax and example for accessing the function :
    Vbscript:    
        syntax - " [FIleName].[FunctionName] "
        example - " Unit1.samplefunction() "
    Javascript:    
        syntax - " [FIleName].[FunctionName] "
        example - " Unit1.samplefunction() "

    please let me know if i have answered yor answer or not