cancel
Showing results for 
Search instead for 
Did you mean: 

Compare data retrieved from excel (Num only) with UI (Num+Unit)

SOLVED
Highlighted
Frequent Visitor

Compare data retrieved from excel (Num only) with UI (Num+Unit)

I am trying to compare data between UI and data retrieved from excel

The data in excel is number only (40) and it displayed in the UI as number and unit (40 kg), how can I test it

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Compare data retrieved from excel (Num only) with UI (Num+Unit)

Is the unit always going to be the same?   If so, it's pretty easy.

 

This is pseudocode... not tested, not runable as is, presented here as concept.

 

var valueFromExcel

valueFromExcel = "40"

if Aliases.myApp.myField.wText = valueFromExcel + " kg" then
    Log.Message("Looks good")
else
    Log.Message("whoops, we have a problem")

Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

Re: Compare data retrieved from excel (Num only) with UI (Num+Unit)

Is the unit always going to be the same?   If so, it's pretty easy.

 

This is pseudocode... not tested, not runable as is, presented here as concept.

 

var valueFromExcel

valueFromExcel = "40"

if Aliases.myApp.myField.wText = valueFromExcel + " kg" then
    Log.Message("Looks good")
else
    Log.Message("whoops, we have a problem")

Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Highlighted
Staff

Re: Compare data retrieved from excel (Num only) with UI (Num+Unit)

Even if the value is dynamic and changing (let's say within your Excel spreadsheet, that 40 changes to 41 or etc.)

you could make the reference to that value and set it as a variable.

 

Then you can grab the on screen object of the UI element (i.e "40 kg") and set that as a variable as well. You can use this in conjunction with the builtin aqstring.trim method to cut out the trailing characters (i.e "kg") and check to see if the two variable's values match. https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/trim.html

Best,
Justin Kim
Community Hero

Re: Compare data retrieved from excel (Num only) with UI (Num+Unit)

Hi,

 

A little bit more advanced approach based on aqString.StrMatches():

Assuming that the number from Excel (e.g. 40) is stored in the variable named 'val' and the value in the UI control can be accessed as 'control.Text', I would use something like this (untested, regular expression (re) might require correction):

aqString.StrMatches("(^|\s)" + val + "\s", control.Text);

 

Comment: "(^|\s)" + val + "\s" after evaluation should be "(^|\s)40\s" which means that this re will match with the string that either contains '40' wrapped with spaces, or the string that starts with 40 and is followed by any space character. (I.e. any text before and after ' 40 ' is ignored.) This will prevent false positive match with, say, 401.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Highlighted
Community Manager

Re: Compare data retrieved from excel (Num only) with UI (Num+Unit)

Thank you everyone!

 

Hi @HaniJoudeh! Which of the suggestions did you choose to use?


Sonya Mihaljova
Community and Education Specialist

 Join the virtual SmartBear Connect user conference on April 27-28! Get your free virtual ticket today!