definition variables when them are not exist yet
In my TC project I have created file "definition".
it contain such definitions of variables:
main_menu = Sys.Process("OptionsWorkshop").WPFObject("HwndSource: MainForm").WPFObject("MainForm").WPFObject("DockPanel", "", 1).WPFObject("ToolBarTray").WPFObject("FeaturesToolBar");
... and others.
So, when I run the first file of my test:
function PLZ_cnct()
{
TestedApps.OptionsWorkshop.Run();
or
TestedApps.OptionsWorkshop_Launcher.Run(1, true);
...some code...
}
... I have got an error in the line:
main_menu = Sys.Process("OptionsWorkshop").WPFObject("HwndSource: MainForm").WPFObject("MainForm").WPFObject("DockPanel", "", 1).WPFObject("ToolBarTray").WPFObject("FeaturesToolBar");
... in definition file.
The error means that test try to find main_menu object before starting the app.
How can I explain to TC that to find defined variables after starting?
- You cannot assign objects to a variable if the object does not exist in memory. So, you'll need to make sure that these assignments are wrapped in a script routine like
function AssignVariables()
{
main_menu = ...
main_form = ...
}
However, this may still cause problems if the objects are not created all up front. For example, say you have a form defined in AssignVariables the does not exist until you click a button. You'll still end up with your error in that case.
It sounds like you're trying to build an object repository on the fly. It is possible to do so but you need to do a lot more than just assigning variables. You need to make sure you relate things to other things and make sure that you refresh the variables on occasion in case the handles and such have shifted.
A better, solution, is to use the NameMapping feature of TestComplete as this will allow you to pre-defined all your objects and map them to Aliases ahead of time. Then you can just simply call things likeAliases.main_menu
Aliases.main_form
You can check out this video:
http://smartbear.com/support/screencasts/testcomplete/reliable-tests-for-dynamic-objects/
I'd also recommend reading the articles starting with
http://smartbear.com/support/viewarticle/11508/http://smartbear.com/support/viewarticle/11508/