Forum Discussion
"If I have it defined as a straight module to execute, python execution fails.”
TestComplete supports Python with a few limitations. One of them: In TestComplete, a test run must start only from a function.
https://support.smartbear.com/testcomplete/docs/scripting/specifics/python.html
Can it be a reason of your issue?
I tried it both ways - as function and as straight code. Neither worked.
Also tried different floder structures and even all code under Project.Path + "\\Script"
- baxatob7 years agoCommunity Hero
Now I'm confused, because previously you said: "When I execute the code in Script\Smoke and it is defined as a function, I can select execute current routine and the code works."
Can you provide your project structure and the problem piece of code in screenshots?
- ray_mosley7 years agoFrequent Contributor
I apologize for the confusion; I have attached the project zip file.
The EMDSLoginProcedure.py executes correctly under TestComplete 12.20 when I use "Run current routine". The application starts. If EMDSLoginProcedure.py has successfully run, then I can execute TerminateEMDSProcedure.py when I use "Run current routine". The application terminates.
The Scripts\Smoke folders contains EMDSLogin.py & TerminateEMDS.py. The code is the same as the two in the above paragraph EXCEPT they are not defined as functions - just straight code. My TestComplete project executes Script\Drivers\QA_SSLLibrary.py function QATestDriver(). The intent is to find all the files under a given folder (Smoke in this case) and then iterate through the list, executing them one-by-one.
I repeat, The *Procedure.py files execute as desired when executed manually using "Run current routine". The QATestDriver() function locates all the tests in the folder, but I cannot execute them.
Thanks for your persistence in dragging information out of me. I appreciate the help.
- baxatob7 years agoCommunity Hero
No, this approach will not work, because to call one module from another, we need to import it first. So it should be defined before call using import keyword.
Now I can see the following possible solution:
1. You should define all your tests in functions. Let say each of your _Procedure modules will have one function test() and all testing steps would be implemented inside this function:
EMDSLoginProcedure def test(): # perform testing here...
TerminateEMDSProcedure def test(): # perform testing here...
2. Your QASSL_Library module should have small functions, which will be responsible to call appropriate test:
QASSL_Library def EMDSLoginProcedure(): import EMDSLoginProcedure EMDSLoginProcedure.test() def TerminateEMDSProcedure(): import TerminateEMDSProcedure TerminateEMDSProcedure.test()
3. Finally you should implement a kind of test_driver method, that will collect all required test modules by its names and launch them:
def test_driver(): searchDir = Project.Path + 'Script' searchDir += '\\Smoke' globPattern = '*Procedure.py' myTestList = aqFileSystem.FindFiles(searchDir, globPattern, False) while myTestList.HasNext(): f = myTestList.Next() test_to_execute = f.NameWithoutExtension eval('{}()'.format(test_to_execute))
To be honest I DON'T LIKE WHAT I WROTE ABOVE :) Because it use eval() function and working with strings instead of direct objects... It is not productive. However it should work.
I hope that somebody else will provide the better solution.
Related Content
- 13 years ago
Recent Discussions
- 47 minutes ago
- 5 hours ago