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
Solved! Go to Solution.
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")
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")
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
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.
Thank you everyone!
Hi @HaniJoudeh! Which of the suggestions did you choose to use?
Subject | Author | Latest Post |
---|---|---|