Ask a Question

Comparing 2 numbers contained in different web objects

SOLVED
olosunsira12
Occasional 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:

 

number_rooms_withou_filters.pngfirst web object

 

number_rooms_after_applying_filters.pngsecond web object

 

I want to check if the first number (1270) is greather than the second one (514),after applying filters.

How can I do that by keyword test and also with scripting test?

 

For example if I use the property contentText to compare this 2 objects, TestComplete take the whole "Madrid: 514 encontrados" and I only want to compare the numbers inside the text (1270 v/s 514)

 

See pictures attached to get context, object spy, and Name Mapping

2 ACCEPTED SOLUTIONS

Accepted Solutions
Marsha_R
Community Hero

Re: Comparing 2 numbers contained in different web objects

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

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

View solution in original post

BenoitB
Community Hero

Re: Comparing 2 numbers contained in different web objects

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;

 

 

Un sourire et ça repart

View solution in original post

2 REPLIES 2
Marsha_R
Community Hero

Re: Comparing 2 numbers contained in different web objects

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

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

View solution in original post

BenoitB
Community Hero

Re: Comparing 2 numbers contained in different web objects

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;

 

 

Un sourire et ça repart

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: