All About Aliases - dn0000001/test-automation GitHub Wiki
What are Aliases
In the framework, an alias is a convention that can be used to reference the same test data field in multiple places in the test data source (XML but can be applied to other types.)
Why would you use an Alias
For GUI tests, aliases will be resolved each time it is used in the code. This may be used to shared information across page objects in the test data instead of passing variables between page objects that is based on the current run-time value.
For API tests, aliases are only resolved once upon loading the resource. So, this is mainly to make the test data more maintainable.
An example of this is if you need to generate certain dynamic data at run-time like the current date.
Scope of Aliases
When you create an alias it has a global scope for the test. Due to the global scope, this applies even to aliases created in other test data files used in the test. So, this means test data file A can create an alias that is referenced in test data file B as long as they are loaded together in the test.
Domain Level Aliases
In the framework, we have a some aliases that are predefined. (You can find them in the Global Aliases xml that is attached to the Allure Report.)
Duplicate Aliases
As aliases are global, if your test is using multiple test data files, then it may be possible to have duplicate aliases. It is recommended to manually ensure you do not have an duplicates. The reason for this is it may not be clear what the correct value should be. This could lead to the test failing and it being difficult to determine why.
If you do NOT follow the recommendations and there are duplicate aliases, then the load order of the test data is important. The last loaded test data file will set the alias values in the test which will determined by your code to load the test data files.
Jexl Expressions
When the aliases are defined, Jexl Expressions are supported. A Jexl Expression must start with ${
and end with }
where everything in between is evaluated as a Jexl Expression.
Jexl Expressions can be used to evaluate anything that is accessible when the data is loaded. Page Objects or Domain Objects and expose variables for use in the evaluation. However, you cannot evaluate expressions that use Selenium because most likely you are at a blank page as navigation to the initial page has not occurred.