Forum Discussion

wmtan01's avatar
wmtan01
Contributor
5 years ago
Solved

Event Handlers and Variable Persistence

We have been using an OnStartTest event handler to load some configuration files for our cases and these configuration values are saved into project Variables so that we can access them across all tests that will run as well as the OnStopTest even handler that we have.

 

It is working perfectly but I noticed one thing when I was making a new script and accidentally caused a Script Error. So here's the scenario:

At OnStartTest we set variable A to "Modern", default value is ""

At OnStop Test we use the variable A for some actions, if it is "Modern" then we log "Modern" if not we log "Basic"

 

During normal run: OnStopTest will use "Modern" and we see "Modern" in the logs

 

When a script fails because of "VBScript runtime error" we see that OnStopTest uses "" and we see "Basic" in the logs

 

My question is this, is this expected? I was thinking that variables should persist their values until OnStopTest Event Handler is done but apparently I was wrong. I guess one reason could be when the script runtime encountered an exception then it crashes the entire Runtime and during the OnStopTest it was already using a new instance of Runtime