Forum Discussion

HaniJoudeh's avatar
HaniJoudeh
Frequent Visitor
5 years ago
Solved

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

 

  • 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")

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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")
    • hkim5's avatar
      hkim5
      Staff

      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

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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.

     

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thank you everyone!

       

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