Forum Discussion

conehead's avatar
conehead
Occasional Contributor
8 years ago

Math Calculation with On Screen values.

I need to do a simple calculation using four screen values and pass the results to an If Then statement for a Log Message.

 

I added four string variables to my test. For each I set the Mode: 'Object Property', set variable value Object Type to 'Onscreen object' and pointed with the target glyph. Then I selected the property of the object 'Text'.

 

Afterwards, I added an If Then statement comparing two code expressions (VAR1 + VAR2) != (VAR3 + VAR4). The if statement doesn't work properly because the '+' only concatenates the two strings, does not do a math calculation.
When I change the code expressions to (number(VAR1) + number(VAR2)) != (number(VAR3) + NUMBER(vAR4)), the Run Test can't handle it and issues an Exception with Additional Info: Reference Error number is not defined.

 

Can someone please tell me if I'm missing something obvious or if there's a way to do the simple calculation with the screen values.

Thanks,
Steve

  • Thank you both for the replies. Using the 'aqConvert.StrToInt' function was key to solving my problem. *I'm not sure where I was coming up with a 'Number' function:)

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I'm not entirely sure I understand this part.

    I added four string variables to my test. For each I set the Mode: 'Object Property', set variable value Object Type to 'Onscreen object' and pointed with the target glyph. Then I selected the property of the object 'Text'.

     

    If you're setting a variable using the Set Variable statement, you select the variable and then you can select Object Property...  So, I'm a bit confused here.  However, if you're grabbing the text property just fine, then you're good with that.

     

    The rest of your problem... I'm not familiar with the "number" method you're trying to use.  If you want to convert the value of VAR1 to an integer value, use

     

    aqConvert.StrToInt(VAR1)

    • conehead's avatar
      conehead
      Occasional Contributor

      You nailed it. Two thumbs up for you:) Thanks for the help!

  • conehead's avatar
    conehead
    Occasional Contributor

    Thank you both for the replies. Using the 'aqConvert.StrToInt' function was key to solving my problem. *I'm not sure where I was coming up with a 'Number' function:)

  • brumazz's avatar
    brumazz
    SmartBear Alumni (Retired)

    Hi Steve, 

     

    I read your question and decided to attempt this myself. 

    Looks like I am late to the party......but this was one way I got it to work.

    I am using a combination of KeywordTests and Scripting (in python).

      

     

     

     

     

     

     

     

    I browsed to our internal hotsauce page and grabbed 4 on-screen dollar amounts and stored them as variables with a type of 'string'

    I used the Object Property and then looked for the dollar amount, which I found under contentText.

     

    I then used the strip function to remove the dollar sign so I could add the values.

     

     

    def Mathproblem ():
    Mathprob1 = '$4.99'
    Mathprob2 = '$12.99'
    Mathprob3 = '$4.99'
    Mathprob4 = '$12.99'
    Mathprob1 = ( Mathprob1.strip( '$' ))
    Mathprob2 = ( Mathprob2.strip( '$' ))
    Mathprob3 = ( Mathprob3.strip( '$' ))
    Mathprob4 = ( Mathprob4.strip( '$' ))
    total = float(Mathprob1) + float(Mathprob2) + float(Mathprob3) + float(Mathprob4)
    Log.Message(total)

     

    I don't know if this will answer your question entirely, but hopefully it helps point you in the right direction.