cancel
Showing results for 
Search instead for 
Did you mean: 

Sharing test scripts between multiple projects

SOLVED
Occasional Contributor

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!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Hero

Re: Sharing test scripts between multiple projects

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available

View solution in original post

Community Hero

Re: Sharing test scripts between multiple projects

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available

View solution in original post

6 REPLIES 6
Community Hero

Re: Sharing test scripts between multiple projects

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available

View solution in original post

Occasional Contributor

Re: Sharing test scripts between multiple projects

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
Community Hero

Re: Sharing test scripts between multiple projects

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Sharing test scripts between multiple projects

Hi Robert, 

 

Thanks for sharing the details. I have two different queries now:

 

1. I was just curious about one mre thing if that is a functionality of testcomplete. 

Is there a way to hide script reference file from TestComplete UI as reference files are only visible under Parent Project in folder hierarchy. 

Please refer to attached screenshot for reference.

 

2. Also, I found a post 'https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/...' for importing functions in JavaScript. 

 

Is this a reliable approach for importing methods in Python. Also, I cannot locate Import Functions dialog in TestComplete 12. 

Any help will be appreciated.

 

Regards
MWalia

Community Hero

Re: Sharing test scripts between multiple projects

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available

View solution in original post

Occasional Contributor

Re: Sharing test scripts between multiple projects

Hey Robert,

Thanks a lot for helping and providing your clarification on the issue!!

 

Regards
Mwalia

New Here?
Join us and watch the welcome video:
Final Interview in the Series
API_testing_mistake#7