Action and Validation
One of the key principles of automation in Eggplant is ensuring that every action that is performed on the SUT, is validated with an expectation. A validation can simply be a resulting text or image being found. In effect, this is the same as a real user waiting for an event to complete before interacting with it.
The key benefits of this are
- Ensures the automation does not get ahead of itself or out of sync.
- Allows for variations in performance of the SUT (Network speed, system resources etc.)
- Provides a simple assertion ensuring the correctness of a test.
The video below, demonstrates what happens when validations aren't applied to the code:
- The user attempts to start with clicks followed by type texts etc.
- As each line of code is executed instantly - no consideration is made towards the behaviour of the system under test - and quickly fails (launching browser and entering url)
- To remedy this, the user tries to add waits to pre-empt loads times etc. This is bad as waits are always the worst case scenario, therefore causing slow execution.
- Hard Waits are a useful tool - but can negatively impact the speed of the script and are not flexible to differing load speeds and behaviours of the SUT - leading too a maintenance cost.
The video below, shows a significant improvement in robustness and speed of the automation, by implementing the techniques demonstrated in the Good Code example:
- The user has added "Dynamic Waits" (e.g. 'WaitFor 10,...').
- The approach will yield far more robust results.
- The solution will handle best and worst case SUT performance.
- The long term maintenance will be significantly less.
For a detailed breakdown of Image and OCR Searches, including Dynamic Wait commands, please refer to this link.
A Summary of What You Have Learned
Using Validations after each action not only ensures the correctness in the test, but it also is a key technique to ensure that the automation is in sync with what is being displayed during the test.
// Step 1
click image:"chrome"
wait 5
typetext "https://demo.nopcommerce.com/",returnkey
wait 10
// Step 2
moveto image:"Computers"
wait 1
click image:"Desktops"
wait 10
// Step 3
click image:"DigitalStormVANQUISH"
wait 10
// Step 4
click image:"ADDTOCART"
wait 4
// Step 5
moveto image:"Basket"
wait 1
click image:"GOTOCART"
assert that imagefound(0,"DigitalStormVANQUISH3CustomPerformance")
// Step 1
click image:"chrome"
waitfor 20, image:"refresh"
typetext "https://demo.nopcommerce.com/",returnkey
waitfor 20, image:"nopCommerce"
// Step 2
moveto image:"Computers"
click image:"Desktops"
waitfor 20, "HomeComputersDesktops"
// Step 3
click image:"DigitalStormVANQUISH"
waitfor 20, image:"DigitalStormVANQUISH3CustomPerformancePC"
// Step 4
click image:"ADDTOCART"
waitfor 20,image:"Succesfully Added to Cart"
// Step 5
moveto image:"Basket"
click image:"GOTOCART"
waitfor 20, image:"Shoppingcart"
assert that imagefound(0,"DigitalStormVANQUISH3CustomPerformance")