Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I want to check the validation of an input field that what is the number of character it accepts?

Suppose an username field is allowed to accept 15 characters then how can I automate this test?

share|improve this question
    
Has the input field a length of 15 character or will throw a error message when you type more characters and submit it? –  Twaldigas Jun 20 at 12:10
    
The thing is I don't know how many character it will accept. Is it you want me to do hit and try? –  razizcool4all Jun 20 at 12:12
    
Why don't you either ask the devs or do a one-time manual test to find out? Are you trying to automate finding out how many characters it accepts? –  Phil Kirkham Jun 20 at 20:27
    
No I am trying to know what would be the exact no of character a given input field will accept so that I can automate with positive and negative test cases on basis of that. –  razizcool4all Jun 23 at 9:45

4 Answers 4

up vote 1 down vote accepted

It depends on implementation of input field.


1) All major browsers support maxlength attribute.
Look at source code of the page and verify if the input field has it.


2) Or you can enter very long text in the field and see what happens.

share|improve this answer

This is what I'd do:

  1. Insert a stupidly big number of characters (1000 for example)
  2. Click somewhere else in order to remove the focus from the input field (to let the app process, at least this is how our app works)
  3. Check the number of characters still in the input field, this way you'll now the max number.

Now, this is probably not the right approach, you should have some spec saying how many chars it should allow, but if you don't know....

share|improve this answer

Here is some pseudo code to find the max-length of an input field. After a form submit you can check the database indeed saved the data correctly.

function maxLength(input) {

    while ( current != length ) {
     current = input.value.length()
     value = input.value
     input.clear
     input.sendKeys(value + randomNewChar())
     length = input.value.length()
    }

    return length
}

Be careful the length could be infinite and crash your browser or test.

share|improve this answer

You should develop your test cases before you automate them. In this case, if you don't know the limit, you should check the requirements, check the spec, or ask a developer what the limit was intended to be. Otherwise, how would you know the limit you found was the one that was meant to be there?

Worst case, you can check it manually by typing until you hit a limit and then counting the number of characters, and use that number.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.