I am new to Selenium, Can anybody explain the validation for numeric fields? I am struck in that validation. I want to validate a phone number field.
-
Selenium IDE or a language using the selenium bindings ? – Michael Durrant Nov 9 '16 at 12:47
-
IDE validation info at stackoverflow.com/q/5466031/631619 – Michael Durrant Nov 9 '16 at 12:47
-
Programming example (java) at stackoverflow.com/questions/12856036/… – Michael Durrant Nov 9 '16 at 12:48
Yes, A phone number field should take only numeric data and must have min and maxi length. Here we do following: (The below example includes script written in C#)
- Identify way to access field - through ID/ Xpath/ Class...
E.g: - IWebElement phoneNumberfield= browser.FindElement(By.Id("txtPhoneNumber"));
Validate by entering a non-numeric input.
Try with alphabets then with special characters. Error should come on blur and/or on save. E.g:
phoneNumberfield.SendKeys("alpha");
IWebElement inlineError = browser.FindElement(By.Path("\\span");
(This you need to identify as every field will have an inline error space, and on save a big message may come on top/bottom of page)
bool isErrorShown=false;
if(inline.Text.Contains(ExpectedMsg) //(ExpectedMsg should be like "Phone Number is invalid")
{
isErrorShown = true;
}
Assert.AreEqual(true,isFound);
(First parameter is expected result)
---This line should add pass/fail to your result excel.
- Validate by entering numeric input. There should not be any error.
phoneNumberfield.SendKeys("9032350749");
if(inline.Text.Contains(ExpectedMsg) //( ExpectedMsg should be like "Phone Number is invalid")
{
isErrorShown = true;
}
Assert.AreEqual(false,isFound); //(First parameter is expected result which is false because there should not be any error)
---This line should add pass/fail to your result excel.
- Validate minimum length for input -Enter input less than 8-10(depending on standard minimum phone number length). Error should come on blur and/or on save.
phoneNumberfield.SendKeys("232");
if(inline.Text.Contains(ExpectedMsg) //(ExpectedMsg should be like "Phone Number is invalid")
{
isErrorShown = true;
}
Assert.AreEqual(true,isFound); (First parameter is expected result)
---This line should add pass/fail to your result excel.
- Validate maximum length of input - Enter input exceeding 10 digits. Field should stop accepting input after 10 chars.
bool MaxLengthCheck = false;
phoneNumberfield.SendKeys("90323507499");
if(phoneNumberfield.GetAttribut("value").Count ==10)
{
MaxLengthCheck = true;
}
Assert.AreEqual(true,MaxLengthCheck); //(First parameter is expected result)
---This line should add pass/fail to your result excel.
- Some of the above steps can be removed if few of these validations are not generic in nature based on the requirement of the form you are automating.
NOTE: Different approach may be followed to validate pass/fail results.Instead of messages, you can set different criteria to finalize your test result.
Thanks. I hope the above steps helps you.
It may help break this question into three parts, as follows.
How do I manually test validation for a phone number field?
Trying Googling for phrases like "phone number validation" or "phone number syntax". Conventions for phone numbers vary by country; see for example this Wikipedia page.
How do I manually test fields in a user interface?
If you can't answer this, you might try talking with someone in your company who manually tests user interfaces for a living. This is too broad of a subject to answer here. You might also try buying a book on manual testing or Googling for "testing field validation".
How do I test field values in Selenium?
This boils down to setting a field value, taking an action that causes the field value to be processed (e.g. submitting the form), and then checking whether the action produced the expected results.