Forum Discussion

mwalia's avatar
mwalia
Occasional Contributor
6 years ago
Solved

Sharing test scripts between multiple projects

Hi,

I am trying to create two projects say Project 1 and Project 2 using Python in TestComplete 12.

I want to achieve method calling that is created in Project 1 into my Project 2.

 

e.g. Project 1 has method M1()

I want to call method M1() from Project 2 in test complete. 

 

Please let me know in case this is feasible.

 

I have tried the following:

1. Adding a script reference of M1 to Project2 and using 'from M1 import *' and it is working. However the code is not hidden in case we need to share the framework althogh changed made to M1() method can only be done via Project1

 

2. Added USEUNIT but not able to import or use the M1() in project 2 as it says Object reference not callable or Project1 module not found.

 

Any help will be appreciated!

  • The most reliable way of sharing a code unit between projects is to Add -> Existing item a script unit.  This is the tried and true way.  While using "import" allows you to import the code without having to share the file, as noted, it's not always visible that the file is in use.  Additionally, the "import" needs to make sure that the necessary file is in the same path.  Adding the existing item brings the file into both projects which allows you to edit it in both places.... with a caveat... that you need to make sure that any edits you make don't adversely affect the other project.

     

    See https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-project.html

  • 1) No... they part of the project, therefore they are visible somewhere.  Please keep in mind, there is no concept of a "parent" project in TestComplete.  You have a project where you're developing the shared code, and projects that consume it.  There's no parent/child relationship between the two there's no basis for hiding it.

     

    2) There is no "import" dialog available for Python.  This is a JavaScript only feature of TestComplete.  To share code between units IN THE SAME PROJECT for python, see https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/python.html

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The most reliable way of sharing a code unit between projects is to Add -> Existing item a script unit.  This is the tried and true way.  While using "import" allows you to import the code without having to share the file, as noted, it's not always visible that the file is in use.  Additionally, the "import" needs to make sure that the necessary file is in the same path.  Adding the existing item brings the file into both projects which allows you to edit it in both places.... with a caveat... that you need to make sure that any edits you make don't adversely affect the other project.

     

    See https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-project.html

    • mwalia's avatar
      mwalia
      Occasional Contributor
      Hi Robert,

      Thanks for sharing the details.

      Is there any other way apart from adding script units to the Project2 for calling method M1() from Project1.

      When I try to import using this statement :
      from Project1 import *
      Or
      from Project1.M1 import M1

      Then, error no module found : Project1 is displayed.

      If we have a way to handle it in TestComplete without adding existing Script unit, than please share the code in any language( great if it is in python) that can help me.

      Regards
      Mwalia
      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        There really isn't...

        Think of it like this....

         

        You're developing an application in, like, Java or Delphi, and want to bring in code from some other application... shared modules or something, you still need to "add" the code to the application... you need to put in some sort of "include" statement or point your IDE to some module or library that brings code in....  There's still that step to "add existing" stuff to your project.  

        Automated test in TestComplete are not applications and aren't "pre-compiled" so EVERYTHING needs to be present in the project from the start.  All script code needs to be available to the project.

         

        For utilities and such, you can create Script Extensions of runtime objects and checkpoints that may help with this, but for actually adding an existing test to another project, there's no other way currently.