Forum Discussion

kcarpent's avatar
kcarpent
Occasional Contributor
16 years ago

Cannot get a keyword test that runs scripts to successfully convert to a script

I've made some scripts that work well when I run them from a keyword test using "run script routine". The problem is that I need to run some conditionally. I was going to try this using an if statement, but I cannot get the correct conditions in the keyword test. I can write the if statement myself, I think, but when I select "convert to script" on the keyword test containing the "run script routines", the script doesn't work. Unfortunately, my scripting isn't great and I am not sure how to call the scripts correctly, which is why I am trying to convert that particular keyword test to script. It looks like it should work to me, but instead it gives the following error: 



"An exception occurred in the script unit at line X: Microsoft JScript runtime error Object Expected"



Here is the code that it generates:




function Test3()


Test3()

{


Login();


SWA();


}




The names of these are correct, so I am not sure what the problem is. If anyone can tell me any way to get around this, I would appreciate it. Thanks.

6 Replies

  • Hi,



    I see two problems in your script. The first one is in these lines:

    function Test3()

    Test3()

    {




    Was it generated this way or is it just a typo? The expected code is:

    function Test3()

    {




    The second possible problem is that Login and SWA are located in another unit. If so, you need to add a USEUNIT reference to the current unit as it is described in the "Calling Routines and Variables Declared in Another Unit" help topic.
  • kcarpent's avatar
    kcarpent
    Occasional Contributor
    You're right, I'm not sure how the typo got in there since I thought I copied and pasted it. Anyway, the typo isn't in the actual code, but the code still doesn't work. Here is the code with no typos:




    function Test3()


    Test3()

    {


    Login();


    SWA();


    }


    So why do you think this isn't working. This is what TC 8.1 generates from a keyword test that only contains two items that tell it to run a script (Login and SWA).
  • kcarpent's avatar
    kcarpent
    Occasional Contributor
    Hmm, the "typo" in my posts may have something to do with what's going on here. On the screen in TC it doesn't show the "problem typo" you have stated, but when I copy and past the text from there into here it clearly shows up, but only after I hit "post". It doesn't show up in the text window. Even when editing the post this is the case.
  • kcarpent's avatar
    kcarpent
    Occasional Contributor

    This post I will try pasting the code again but using the code tags in the post. Maybe that's what is making it weird.




    function Test3()



     


    {


    Login();


    SWA();


    }








    As for the second problem, shouldn't the generated script know whether or not the "USEUNIT" is needed or not and use that? I'm not sure I understand why it wouldn't have it if it needs it.
  • Hi,



    USEUNIT statements are not added automatically. You need to insert them to your unit manually if you're calling functions from another unit.