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?
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?
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.
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....
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.
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.