Forum Discussion

vik33's avatar
vik33
Occasional Contributor
10 years ago

Trying to implement classes in my scripts.

I am trying to implement classes in my scripts but unable to do so. I see the follwing line on every page for testcomplete documentation for classes.
"The object-driven testing (ODT) functionality is deprecated. We do not recommend using it when creating new tests."

But i understand that TC won't support ODT (Object driven testing) approach in future but can i still define my own class in one script (vbscript class) and access the methods of the class from any other script. All i am trying to do is the following:
'In unit A
Class car
Private a
public function setA(a1)
a = a1
Log.Message(" success")
End function
End class


'In Unit B
sub mysub()
dim objcar
Set objcar = new car
objcar.setA(5)
end sub

So far, i am unable to do the above because line 2 ( Set objcar = new car) doesn't work because class car is not accessible in Unit B but the code works fine if class and Sub mysub() are both present in 1 unit or script. Is there a way to implement classes like this in TC verision 10.60

Please share some inputs.
Thanks,
vik

  • The solution is:

     

    In every script (unit) just make a function that returns a reference to that class and call that function from any other unit to make use of that class.

     

    Unit A

    Class A

     

    End class

    Function GetClassARef(obj A)

    objRef = new Class A

    GetClassARef = objRef

    End function

     

    Call above function from any other script.

    Thanks.

  • vik33's avatar
    vik33
    Occasional Contributor

    I finally got my answer in one of the posts. 

    Thanks for reading my post.

    • jeremyt's avatar
      jeremyt
      Contributor

      vik33 wrote:

      I finally got my answer in one of the posts. 

      Thanks for reading my post.


      Please read my signature!

      • vik33's avatar
        vik33
        Occasional Contributor

        The solution is:

         

        In every script (unit) just make a function that returns a reference to that class and call that function from any other unit to make use of that class.

         

        Unit A

        Class A

         

        End class

        Function GetClassARef(obj A)

        objRef = new Class A

        GetClassARef = objRef

        End function

         

        Call above function from any other script.

        Thanks.