What is Jexl and How to use it? - dn0000001/test-automation GitHub Wiki
Basic Overview
JEXL is a library used to facilitate the implementation of dynamic and scripting features in Java. In the framework, it is used to evaluate or define some simple expressions like computation formulas in the test data files.
Note: JEXL supports the full Java language. However, in the framework only simple 1 line expressions are allows on purpose to prevent complex coding in the test data.
Purpose/Use Cases
It is ideal to kept the test (logic) separate from the data used/for the test. However, certain test data may be dynamic in nature or specific to the test environment and need to be looked up.
A simple example of this would be user names and/or passwords. A more complex example would be retrieving test data from a database or retrieving some expected result. Another example would be using an API to get expected results. Yet a more common example, it some sort of date calculation based on the current day.
In all these cases, it would be ideal to represent this in the test data instead of in the code. This is what JEXl is providing in the framework by allowing it to be done in the test data and evaluated once the test data is loaded.
How to use basic JEXL?
In your test data, define an alias and write the JEXL. See example here
How to do more advanced JEXL?
Override the initJexlContext method in your domain object which will load the test data. You can expose any objects you want to be used in JEXL. See example here If you want to see the entire process in action, then see the JEXL test
Other resources
See the Apache JEXL site