You can share scripts between TestComplete projects, but you can’t share Object Stores that the script refers to. At least, not out of the box. Jump to the workaround at the end of the blog to see one possible alternative.
The Scope of Object Stores
ProjectA in the screenshot includes Stores > Objects with a store named NotepadWindow. The ObjectPropsUnit has a single script that refers to that store.
function checkNotepad(){ Objects.NotepadWindow.Check(Sys.Process("notepad").Window("Notepad", "*")); }
ProjectB has a link to ObjectPropsUnit by way of right-click and selecting Add > Existing Item… So far, so good.
Image may be NSFW.
Clik here to view.
Run the custom checkNotepad() function from ProjectA and the test is a green light. Run the same code from ProjectB and the test fails (see the error message screenshot below). Scripts run in the context of the project. ProjectB has no Stores defined, and no Objects node, so its not surprising it fails.
Image may be NSFW.
Clik here to view.
What You Can and Can’t Do
Can I add the entire Stores collection from ProjectA by right-clicking ProjectB and selecting Add > Existing Item… from the context menu? Not really. Although you can select the Stores.tcStores file from ProjectA, attempting to add it anywhere in the same project suite fails with a message that the store already exists somewhere in the project suite.
Image may be NSFW.
Clik here to view.
Can I create Stores and Objects nodes manually in ProjectB? You betcha. Can you right-click, select Add Existing and select a specific store from ProjectA? Nope, the option is disabled.
Image may be NSFW.
Clik here to view.
Workaround
Given that project suite variables can be shared, you can save a project store in a project suite variable and use that variable in a second project. You’ll need to create a temporary variable of type Object, like NotepadWindowStore in the screenshot.
Image may be NSFW.
Clik here to view.
In the shared script unit, create a function to save the store into the variable and a second function to extract the variable and run the Check() method.
function addStore(){ ProjectSuite.Variables.NotepadWindowStore = Objects.NotepadWindow; } function checkStore(){ var liveObject = Sys.Process("notepad").Window("Notepad", "*"); ProjectSuite.Variables.NotepadWindowStore.Check(liveObject); }
In the Test Items editor for ProjectA, add an item that calls the addStore() test. Add another test item in ProjectB to run checkStore().
Image may be NSFW.
Clik here to view.
Make sure that the Project Suite Test Items lists ProjectA before ProjectB. You can drag and drop the projects to change the order.
Image may be NSFW.
Clik here to view.
As long as ProjectA runs before ProjectB, the variable will be populated with the store, and the check will be successful.
Image may be NSFW.
Clik here to view.
Thanks to Lino Tadros for suggesting Project Suite variables to hold stores references.
The post Sharing TestComplete Object Stores Between Projects appeared first on Falafel Software Blog.