olosunsira12
4 years agoOccasional Contributor
Comparing 2 numbers contained in different web objects
Hello!! I'm struggling trying to compare 2 numbers , each of them contained in different web objects: first web object second web object I want to check if the first number (1...
- 4 years ago
You will need to use aqString methods to pick out the numbers you need. They are actually still strings at that point, so then you'll need to use aqConvert to make them numbers and then you can compare them. There are keyword test and scripting examples in both of these.
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/methods.html
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/index.html
- 4 years ago
Convert both values in numbers with regEx.
See here (look for Getting numerical values from string)
function ExtractNumber(Str, DefaultValue) { var MatchArr, re; re = /[-+]?\d*\.?\d+([eE][-+]?\d+)?/gm; //Specify the regular expression MatchArr=Str.match(re); //Search for occurrences //If no numbers were found then return default value if (MatchArr==null) return DefaultValue //Else, convert a string with first occurrence into a number else return aqConvert.StrToFloat(MatchArr[0]); }
So you'll have something like that :
let value1 = ExtractNumber(WebObject1.Property, -1); let value2 = ExtractNumber(WebObject2.Property, -1); let value1IsGreaterThanValue2 = value1 > value2;