Placing NameMapping data into vars
Hey smartBear community!
I was wondering if it's possible to place a specific object's Alias inside a variable once and re-use that variable throughout several scripts.
For example, if I'm referencing the same object in three different scripts which run back to back, would it be possible to place it in a variable before running that "set" of scripts and simply do something like the following:
Place this somewhere initially,
header = Aliases...---------------------...label.
Then reference that variable in the scripts without redeclaring that same variable again in each script,
Script1: header.Click();
Script2: header.HoverMouse();
Script3 header.VisibleOnScreen();
In other words, I'm trying to create a bank of variables which I can freely choose upon within several scripts without having to type in the "Aliases..........." part over and over again, being that it becomes repetitive.
Thanks for the help!
Hi automTest
I have used a similar approach previously and can say that I won't recommend it. For example, I was storing a combobox in a variable because I was applying lots of operations on the same object. Inevitably though, somewhere through the test run, the handle to the object would be destroyed and you would get an error about not being able to find the object despite it obviously being on the page. You don't even need a page load for the mapping to change in some cases. This means that each time you want to work with the object - before Click(), HoverMouse() and VisibleOnScreen() - in your example, you first have to check that it exists AND remap it if it doesn't. If you keep it local to your script, you may still need to do the same, but you will find you don't need to refresh the mapping info as often, which means less of a performance hit, which will slow down your tests. Taking longer to type your code is better than taking longer to run your scripts. You will make up the difference after a few test runs.
What I could suggest to make the typing easier. You can assign the aliases object to a variable inside your script. You don't need to store it in a global variable, but you don't need to type as much either:
var myLabel = Aliases.MyApp.Panel1.Panel0.Panel2.Table.Cell1.Label; myLabel.Click(); myLabel.HoverMouse(); myLabel.VisibleOnScreen();
You only had to use that long Aliases... syntax once in the entire script. Slightly more typing than a global variable, lots less failed tests because of object recognition issues totally unrelated to what you are actually trying to test