Script only gets called once
I have a problem with one of my scripts
import time import traceback dosomething connected = obj.Connect(login) def factory_reset(mode): dosomething def nextfunction(): dosomething
This is my script and when running a single test it works always - but the login data changes between 2 tests and when I run those 2 tests, which both call the function factory_reset, after another, it takes the same login data for both tests.
I included a Log.Warning("warning") before the obj.connect and it does not even write out this Warning in the second test, so it seems like it cached the run of the script in the first test somehow.
Is it possible to "close" this script file / kick it out of the cache so it initializes again
That's not exactly the best way to write code in TestComplete. Everything you want to execute should be part of a function and called explicitly. Implicit calls like that are only done when the code unit is first loaded.
[Hall of Fame]
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
Vegas Thrill Rider
My problem is, when I write it in functions it always says obj is used before being initialized ...
even though when I debug i see that it gets set and it has a value - but the moment I am using it and step over the error occurs ...
Is there a way to "throw away" a script during runtime, so it gets actively reloaded
I am not using Python and might miss something, but according to my knowledge and as Robert has said:
a) I never heard about any scripting language runtime that allows dynamic code load/unload;
b) All scripting language runtimes load script code, execute all statements that are out of any function and then execute the 'main' function.
Considering the above,
connected = obj.Connect(login)
lines are executed on test start before any test method is executed (i.e. even before your first test starts its execution).
connected variable in this case is a global one for the whole test run, it keeps the value returned by the obj.Connect(login) call and exists even between different tests until test run ends.
/Alex [Community Hero]
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
I have managed the problem and also found out what I did wrong.
for python i need the keyword
global obj global login
in the function where i initialize them, this way I can work even between multiple calls with the variables and make multiple connections.