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.
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