Many applications contain entities that must be unique. A common example is a customer or member identifier like email address. To prevent input errors, automated tests must be designed to ensure that these identifiers are unique. There are several techniques to achieve uniqueness, including appending date/time strings or a unique number to the entity name. This post describes the latter solution.
The image above displays source code for the Incrementer function. It takes as parameters the name, section and lValue of the .ini file that will be used to store the current value of the incrementer. It also takes a Boolean flag that specifies whether to increment the value on the current call. This is useful because some calls might want to get the current value of the incrementer without changing its value. The function outputs the current value of the incrementer as an out parameter of type integer. It also returns it as a string for convenience.
The function is quite simple. It opens the specified .ini file, gets the value of the incremeter specified by the IncrementerLValue parameter and converts it to an integer. If bIncrement is set to ‘true’, it increments the rValue and writes it back to the .ini file. Finally it sets the IncrementerValue and passes it to the calling function through both the out parameter and the return value.
The calling function can then append the retuned value to an entity name before inputting it to the target application.
If you have any questions about this approach or would like to obtain a copy of the function’s source code, please contact Zeenyx Support.