How to automatically increment a Local Variable

Hi. I want to update a numeric local variable every time I run the test, increasing its value by 1 and storing the new value into the same variable. How can that be done? An example would be very useful!!

Thanks!

The scope of a local variable is limited to the test case (or block of code) within which it is declared. In other words, a local variable has no access to what happens outside of its scope. Therefore, trying to increment a local variable based on the number of times the test case within which it was declared was run is not possible (it will always get re-initialized each time you run the test case).

However, you can store/increment this value in a larger scope using either:

1.) A global variable
2.) Test data

3 Likes

Brandon, thank you. I tried with a Global Variable and it worked perfectly.

1 Like

can u pls tell me wer to add this condition

Just as I said:

@Brandon_Hein - I Have a similar requirement that, I want to update/increment the form_sequence_number by 1 after executing the test. So that when the same test runs again will take the incremented value.

Could you please help with the Test_Data part.? Currently the form_sequence_number value stored in CSV file and iā€™m access through local variable.