Forum Discussion

etienne_smith's avatar
etienne_smith
Occasional Contributor
12 years ago

Running or adding sub routines to Keyword tests

I am having trouble adding any sub routines to my keyword tests.  I can't even run them for debugging purposes.  I am sure there is a very simple answer to this but it has been driving me up the all. 

Any script which does not contain 'routines' as TestComplete refers to them is completely ignored and I cannot use them at all.



As an example here is a very basic sub routine which should just work:



Sub Test2()



Log.message("Why can't I use this script?")



End Sub

7 Replies

  • etienne_smith's avatar
    etienne_smith
    Occasional Contributor
    Looks like part of the problem may be related to the scripting language.  We had a contractor in who did some of the scripting and it looks like he used JScript instead of the default VBScript.



    As far as I am aware you cannot change the scripting language after a project has been created?  That would be a pain in that we would have to create a new project and convert the scripts he did to VBScript.  Fortunately there aren't too many of them.



    I will report back once I have established what language was specified when the project was created.



    Perhaps it is time I learnt JScript anyway. I have a book on the subject gathering dust on a shelf so perhaps it is time to broaden my skillset.  The trouble is I am not sure the other team members are familiar with Javascript either!
  • If I understand your problem correctly you are trying to run a script routine from a keyword test? If so, in your keyword test use the Test Action "Run Script Routine" located in the Operations menu. Once you drop the test action onto the keyword test you will be able to select any script routine located in the current project.

    Hope that helps.
  • etienne_smith's avatar
    etienne_smith
    Occasional Contributor
    That is exactly the problem.  I cannot do that.  I dragged the script onto the keyword test and it didn't even appear in the steps. 



    If however I drag in a function with routines then it works fine.  The relevant fact is that unless there are 'routines' in the sub routine or function then nothing happens.  The example I mentioned originally is a simple log message.  Since there are no routines present in that scenario it won't allow me to run it or add it to any tests.



    I am aware that for a one-liner like I can add it as a 'Code Snippet' but the script I am trying to use is about 50 lines so that is not a solution.



    When creating a script there is a 'Run' button which is always disabled, even when there are no syntax errors.  Why is that?  The scripts I am having issues with also do not appear in the list of Script Routines I can add to a keyword test so they are effectively useless to me.
  • chrisb's avatar
    chrisb
    Regular Contributor
    If I understand the second part of your question correctly you would like to know why you cannot run a script you are working on.

    Perhaps the problem is that the routine your are working on has parameters? Take a look at the 2 routines below.

    If you copy them into scripting and click inside routine_a you will see that the option to run is enabled. Then click inside routine_b and you will see the option to run is disabled. You can't run routine_b as it has parameters and is expecting the argument ''message'.

    You would need to write another routine to call routine_b.



    Does this help?






    Sub routine_a()


    log.message "hello"


    End Sub


     


    Sub routine_b (ByVal message)


    log.message message


    End Sub


     

  • chrisb's avatar
    chrisb
    Regular Contributor
    Try this -



    1. Go to the script containing the routine/s.

    2. Click on the drop down menu in the centre above your script.



    Do you see the routines available (highlighted in green) in the drop down menu?
  • chrisb's avatar
    chrisb
    Regular Contributor
    Yep, you can't mix the languages. If its started in JScript then you will have to continue with that or start again in another langauage of your choice.
  • etienne_smith's avatar
    etienne_smith
    Occasional Contributor
    OK.  Thanks everyone for your input, hopefully switching to VBScript will solve the problem.



    I will raise a separate thread for creating the new project without losing what has already been done in the current one.