Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Can a margin of error be set in SilkTest when comparing values which will be similar to a certain degree?

Can a margin of error be set in SilkTest when comparing values which will be similar to a certain degree?

SilkTest has functions and methods already defined to verify that the actual, on-screen value is exactly what you expect it to be.
However, there is nothing built into the 4Test language to make sure that a value in the application under test (AUT) is close enough. For example, in a great number of engineering and scientific applications there"s an acceptable margin of error. That is, "3.8" is considered a right answer if the expected value is "4" and there"s a margin of error of .2. Additionally, verifying if some text that has a date and time stamp in it has the right text except for the date and time.

VerifyNear

To verify if a number is close enough, a new function can be used called VerifyNear that closely resembles the Verify function that we all know.

Note the tolerance level to be passed in as defined as number. This will allow both real or integer to be passed in.

The last argument, the description, will be much like the last argument to the Verify function.

To test whether or not the two values, nActual and nExpected are within the acceptable tolerance level, they can just subtract one from the other, get the absolute value of the result, and compare whether or not the difference is less than or equal to the tolerance, nTolerance:

And, if the difference is greater than the tolerance, raise our own error.

VerifyFuzzy

The above VerifyNear function works great for verifying that two numerical values are close to one another (or not), but there are also times that string expression may require verified to see if it is close enough (or not). This can be done by pretty much duplicating the functionality of the Verify function, but using wildcards in the expected value for the function.

The VerifyFuzzy function is shown here.

By using the MatchStr function rather than checking for an exact match, calling the VerifyFuzzy function allows for wildcards to be put into the expected value. Wildcards for single characters (?) or multiple characters (*) can be used.

Hidecalls

The Hidecalls statement removes the function from the call stack if/when an error occurs inside of that function. So, for example, if VerifyFuzzy raises an error above, double-clicking on the error in the results file will display the line where the function was called rather than the raise statement inside of the function, which is really where the error occurred.

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:24
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.