Forum Discussion

farhanahmed's avatar
farhanahmed
Contributor
12 years ago

How to check that user can enter only ASCII characters in a text field.

hi

I am writing my script in Test Complete 8 by using VBScript i want to test that user can enter only ASCII characters in a text field, i have not found any way to do it by Check Points, is there any other way to test this functionality that "user can enter only ASCII characters in a text filed."



Regards

-farhan

6 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    Just try to enter non-ASCII character into the field and see what happens.

    Several notes regarding 'functionality that "user can enter only ASCII characters in a text
    filed."' requirement :

    -- Do you have a definition of non-ASCII character? Is Unicode, UTF-16 or something else assumed? (This because, for example, Carriage Return symbol has ASCII code 13d (0x0D). Likewise what about, for example ASCII(255) ? )

    -- According to the provided requirement, you should check whether or not it is possible just to enter the character. Nothing is said about what is expected in both cases.



    Your actual test code might be different depending on the answers to the above questions.
  • Hi karas,

    According to the requirements ASCII(255) are allowed, How should i write a script for this test in test complete?

    -farhan
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    Exact implementation depends on your application, but I would try something like

    Call <TestedInputControl>.Keys(Chr(255))

    Call aqObject.CheckProperty(<TestedInputControl>, "wText", cmpEqual, Chr(255))

    and

    Call <TestedInputControl>.Text = Chr(255)

    Call aqObject.CheckProperty(<TestedInputControl>, "wText", cmpEqual, Chr(255))
  • Hi

    When i enter text in text field by Call <TestedInputControl>.Keys(Chr(255)) and compare it with wText it does not work fine.(What i should do in this problem?)

    But when i enter text in text field by Call <TestedInputControl>.Settext(Chr(255)) and compare it with wText field it works fine.

    In thi scenario is it same thing to enter text in text field by .key() or .SetText ?

    -farhan


  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    First of all - thanks for the correction: sure I meant .SetText(), but not .Text.



    As for how to react on the behavior you are observing - this is a question to you and your developers.

    The case is .Keys() emulates as if it is user who types characters on the keyboard. And it is possible that control/developers implement the method for the OnKeyPress event (or the like) to process/filter/change characters as they are typed.

    Alternatively, the SetText() method assigns value directly, bypassing the OnKeyPress handler routine. In some cases for some applications this is acceptable, but in some cases it is not. Whether it is OK or not in your case - should be decided by you.