Forum Discussion

thilakasiri1978's avatar
thilakasiri1978
Occasional Contributor
10 years ago
Solved

How should I call a TestComplete script at runtime ?

Hi,

I stored my test complete scripts names in an excel files and I need to call it in my driverscript. I used the below code and I'm getting and vb error. appreciate your help.




Sub DriverScript()



Call Project.Variables.DriverScript.Reset



While Not Project.Variables.DriverScript.IsEOF



 



If Project.Variables.DriverScript.Value("Run")="YES" then



Sc_ID = Project.Variables.DriverScript.Value("Sc_ID")



Sc_Name = Project.Variables.DriverScript.Value("Sc_Name")



 



call Sc_Name.sc_name()



End If



Call Project.Variables.DriverScript.Next



WEnd



 



End Sub


  • So does:



    Sc_Name = "TC8_CAMP_TerminalValidations.method1()"



    Eval(Sc_Name)



    Work OK?



    scriptCall = Project.Variables.DriverScript.Value("Sc_Name") & ".method1()"



    Eval(scriptCall)



    Should also work. As long as the value in the project variable is correct ....

8 Replies

  • So does:



    Sc_Name = "TC8_CAMP_TerminalValidations.method1()"



    Eval(Sc_Name)



    Work OK?



    scriptCall = Project.Variables.DriverScript.Value("Sc_Name") & ".method1()"



    Eval(scriptCall)



    Should also work. As long as the value in the project variable is correct ....

  • Eval(<function call as it would normally appear in your script here>)



     


  • thilakasiri1978's avatar
    thilakasiri1978
    Occasional Contributor
    Thanks for the reply.



    I tried with  eval( Sc_name.sc_name()) command. Now I'm getting the " Object required : 'Sc_Name' " error.


  • I don't know how you have your script units set up. If you have them in external projects you need to make your driver script aware of them using USEUNIT statement at the start of the driver script.



    All EVAL does is execute the command in parenthesis.



    So if you can manually get a function call working in script, just put that code in a string and then put the string in the EVAL parenthesis.



    That's what my driver script does and it works fine.



    So if the function call was:



    total = AddTogether(numberOne, numberTwo)



    This would simply be:



    functionString = "AddTogether(numberOne, numberTwo)"

    total = EVAL(functionString)



    You only make calls to functions. Not to script units. (Although you can include a reference to the script unit in the call if desired)



    If you're not understanding this, you need to have a read on how TestComplete uses script units and the functions within them:



    http://support.smartbear.com/viewarticle/56539/

  • thilakasiri1978's avatar
    thilakasiri1978
    Occasional Contributor
    Thanks for the details...



    I have used the USEUNIT commands.


    'USEUNIT TC6_CAMP_WebServices



    'USEUNIT TC8_CAMP_TerminalValidations



     



    If I use directly TC8_CAMP_TerminalValidations.method1() it is working fine.





    But issue is I have stored the unit script names in a separate excel sheet.

    Then I'm reading that excel sheet to get the script name and assign to a SC_name variable.



    Sc_Name = Project.Variables.DriverScript.Value("Sc_Name")





    Then if I try to use SC_name.method1() I'm getting a vb error.



     



     



     



     


  • thilakasiri1978's avatar
    thilakasiri1978
    Occasional Contributor
    Thanks for the details Colin,



    This is the problem.  'TC8_CAMP_TerminalValidations'  is a TC script object.  So if I simply assign the Project.Variables.DriverScript.Value("Sc_Name") value to a variable it is treat as a string variable and giving an error 'Object Required'.



    So I guess we need to create a TC script object and set the value to that. But I don't know how create a script object run time and assign it.