Forum Discussion

JBSoccerbrit's avatar
JBSoccerbrit
Contributor
10 years ago

Keyword test validate characters in input field.

Is it possible to validate using keyword tests how long a value is in an input field.

For example;

Input field 1 contains 123456789, I would like to confirm that the length is 9 characters long. The closest I have found is Property checkpoint doesn't appear to offer counting characters of the string itself.

Thanks,

  • To elaborate on Kamal's answer, you can use If..Then and aqString.GetLength to verify the string length, like this:

     

    keyword-checkpoint-for-string-length.png

     

     

    Another option is to use a property checkpoint with a regular expression for exact string length. Use the Matches condition, and this regular expression with the same number of dots as the expected string length (9 in your example):

     

    ^.........$

    Here, a dot (.) matches any character. ^ and $ mean the beginning and end of the string, to match exact string length (without using ^ and $ you will also get a match for strings of 10 and more characters.)

    The drawback of this method is that the checkpoint results do not include the string length as a number, so you won't see the number 9 in the log.

  • HKosova's avatar
    HKosova
    10 years ago

    Make sure to scroll to the end of the list:

     

    matches.png

  • Hi,

     

    You can use "aqString.GetLength" Instead of Property checkpoint

     

    1. Get the String From Object Property and Store into the "SetVariable" E.g., (String_Value = "123456789")

    2. Then get the Length using aqString.GetLength(String_Value)

    It may helpful :)

     

    Thanks, Kamal

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    To elaborate on Kamal's answer, you can use If..Then and aqString.GetLength to verify the string length, like this:

     

    keyword-checkpoint-for-string-length.png

     

     

    Another option is to use a property checkpoint with a regular expression for exact string length. Use the Matches condition, and this regular expression with the same number of dots as the expected string length (9 in your example):

     

    ^.........$

    Here, a dot (.) matches any character. ^ and $ mean the beginning and end of the string, to match exact string length (without using ^ and $ you will also get a match for strings of 10 and more characters.)

    The drawback of this method is that the checkpoint results do not include the string length as a number, so you won't see the number 9 in the log.

    • JBSoccerbrit's avatar
      JBSoccerbrit
      Contributor

      For the property checkpoint option I don't see "matches" as a selection?

      Equals
      Does not equal
      Greater than
      Less than
      Greater than or equal to
      Less than or equal to
      Contains
      Does not contain

      These are my only options?

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        Make sure to scroll to the end of the list:

         

        matches.png