Forum Discussion

dale_waterworth's avatar
dale_waterworth
Occasional Contributor
11 years ago
Solved

Calling function as keyword test parameter

How do you call a script function as a keyword test paramter?



Let say i have a keyword test that call a script routine :



function theTest(ref, magicNumber) {

 ...

}







Now we a new "Run Script Routine" to our keyword test that takes the 2 parameters.



When the operation parameters are selected i want both parameters to call a function being generateRef() and generateMagicNumber() which the results of both get passed to theTest(re, magicNumber) function. How is this possible?



I am aware of useLastResult but it doesn't suffice.



This means that everytime we need the use of more than one function result a new script has to written. 



Do you or anybody have any suggestions? How a have other got around this?

  • Hi Dezza,


     


    You'll need to call the Run Code Snippet operation and specify there the following:




    Runner.CallMethod("Unit1.theTest", Runner.CallMethod("Unit1.generateRef"), Runner.CallMethod("Unit1.generateMagicNumber"))




    *Unit1 is the name of the unit with your script files.


     


    Not a very elegant way, but it should work, though.


     

4 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Dezza,


     


    Does the Code Expression mode work for you? This will make TestComplete treat a parameter as a function name and call it.


     

  • dale_waterworth's avatar
    dale_waterworth
    Occasional Contributor
    No, the function is never picked up and i get the error:




    Unable to evaluate the operation's "attrType" parameter. Error: 'testFunctionParams' is undefined



    when trying to pass in my script function i've tried

    func

    func()


    testFunctionParams.func

    testFunctionParams.func()

    testFunctionParams["func"]




    but still get the same error.



    Thanks
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Dezza,


     


    You'll need to call the Run Code Snippet operation and specify there the following:




    Runner.CallMethod("Unit1.theTest", Runner.CallMethod("Unit1.generateRef"), Runner.CallMethod("Unit1.generateMagicNumber"))




    *Unit1 is the name of the unit with your script files.


     


    Not a very elegant way, but it should work, though.


     

  • dale_waterworth's avatar
    dale_waterworth
    Occasional Contributor
    Great this works. 



    Maybe a suggestion to add this as a new feature - would come in very handy.



    Thanks