Forum Discussion

ekiza23's avatar
ekiza23
Contributor
12 years ago

Problem with Script Extension: Class doesn't support Automation

I have created a couple of script extensions successfully, but I am now working on another one that is giving me some troubles.



Whenever I call one of it's methods from my scripts, I get a "Class doesn't support Automation: 'Namespace.Name.method'" assertion.



I am running out of ideas on what could be the cause of this.



Could you please give me a hand?



I will attach the extension here.









20 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Christian,



    Could you post the body of the InstanceOf_LinuxLoginData() function?
  • Sure, these two are within another Unit with some other data structures




    Class LinuxLoginData


      Public host


      Public user


      Public password


    End Class




    Function InstanceOf_LinuxLoginData


      Set InstanceOf_LinuxLoginData = New LinuxLoginData 


    End Function

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Christian,



    Thank you for the code.

    Unfortunately, I'm getting exactly the same error as you do and I have no idea at the moment of what may cause this error.

    So I think that you should report the case to Support (http://support.smartbear.com/message/?prod=TestComplete) and see what they will reply.



    My guess is that something goes wrong with VBScript here because another script extension created using JScript still works fine for me.
  • I have other VBSCript Extensions that still work fine too... 
  • I notice that the class is defined in a different unit.  I vaguely remember this error when trying to instantiate new objects when the class is in a different unit.  I worked around this via a "constructor".



    Try creating a function such as the following outside of the class definition, but inside the Linux_Classes file.



    function create_data

     set l = new InstanceOf_LinuxLoginData

     create_data= l

    end function



    Use create_data when you need to create a new instance of the class.
  • Thanks,



    but  InstanceOf_LinuxLoginData is exactly that, a constructor for LinuxLoginData outside of the class but within the same unit. It is supposed to return the object (with a Set <FunctionName> command, and it is working well so far. The problem I am experiencing does not seem to be with the creation of that object, but rather with the invocation of the subs and functions in the Script Extension.



    Note that the exact same code works well if instead of a Script Extension it is used as an additional Unit of the project, but then I have to add this unit to all the projects that use it, instead of benefitting from the Script Extensions functionality.
  • Russel, you must be referring to:


    • Unlike TestComplete projects, references between script files in a script extension package are not allowed. Called routines must be located in the same script file as the caller ones.


    But the thing is:


    1. There are references to *other* script extensions, which are called using the corresponding Runtime Object. I could swear that I have done this in other extensions, but I will double-check it tomorrow.


    2. However, the Script Extension module does not complain about this, so I am assuming that failure for this reason would happen during runtime, once the execution gets to the actual point where it needs this Runtime Object, but it is instead failing before even entering the function.


    3. In the example that I provided, which has allowed other users to replicate the failure,  I deliberately commented out the use of other script extensions, since this was also one of the suspects I wanted to discard first.



    I am really running out of ideas, and I have this feeling that the answer will be either something really stupid (some capital letter, some key word that I shouldn't be using, ...) or something really esoteric.

  • rgratis's avatar
    rgratis
    Frequent Contributor
    You can definitely call other script extensions using their full names as you would in TestComplete.  What you cannot do inside script extensions is "USEUNIT"; all content for a given runtime object must be contained in one script file.
  • rgratis's avatar
    rgratis
    Frequent Contributor
    This works for me:

    - Move class definition for LinuxLoginData inside plink.vbs

    - Add InstanceOf_LinuxLoginData method to Plink object that returns New LinuxLoginData




    Sub Test_executeCommand


      command = "ls /dr01/files/db*.sqldump"


      Set linuxLoginData = Linux.Plink.InstanceOf_LinuxLoginData


      linuxLoginData.user = "testuser"


      linuxLoginData.host = "host20"


      linuxLoginData.password = "testpassword"


      


      data = Linux.Plink.executeCommand(command, linuxLoginData)


      log.message(data)


      


    End Sub



    What also seemed to work was making another script file and runtime object containing the class definition and InstanceOf_LinuxLoginData method and doing something like "Set linuxLoginData = Linux.<other-object>.InstanceOf_LinuxLoginData".

  • I think I have fixed it finally, although I am not entirely sure how. 



    Eventually, it seems that the problem had something to do with the name of the RuntimeObject starting with an Upper Case character instead with a Lower case (although in some other extensions this is not a problem). Changing the name from "Plink" to "plink" seemed work.



    Also, I added the LinuxLoginData class in another file to the same extension for convenience, but I this isn't what fixed the issue.



    Thanks all for your suggestions.



    It would be great, though, if someone on SmartBear could investigate the source of this problem and provide some documentation or rules on how to avoid it.