Ask a Question

Event Handlers and Variable Persistence

SOLVED
wmtan01
Contributor

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

image.png

 

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

4 REPLIES 4
sonya_m
SmartBear Alumni (Retired)

Let's ask Community!

 

@anupamchampati @tristaanogre @Marsha_R @Wamboo 

any suggestions?🙂


Sonya Mihaljova
Community and Education Specialist

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


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
Wamboo
Community Hero

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

Can You show us the code?

 

Hi,

 

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:

wmtan01_0-1598475864817.png

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.

 

cancel
Showing results for 
Search instead for 
Did you mean: