Ask a Question

Event Handlers and Variable Persistence


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

SmartBear Alumni (Retired)

Let's ask Community!


@anupamchampati @tristaanogre @Marsha_R @Wamboo 

any suggestions?🙂

Sonya Mihaljova
Community and Education Specialist

Champion Level 3

I don't know much about event handlers.  @AlexKaras might know.

Community Hero

What kind of variables are You using? Temporary or Persistent?

Can You show us the code?




We are using temporary variables as we do need Table types not just basic variable types.


I now discovered the issue when I was trying out the persistent variables that you suggested.


I seem to have missed that the function I accidentally broke and was causing the exception was also being called in my OnStartTest event handler so I never actually set the other variables as it already error-ed out there causing this behavior that I saw.


To answer the question though, it seems variables are still set to the values defined during execution and do not revert back to their default states during exception. It was my mistake that made me think something else was going on:


Default state for the temporary is ""

Old state of the Persistent variable is 154733



Thank you to everyone who took the time to think about this issue though. I greatly appreciate it.


Showing results for 
Search instead for 
Did you mean: