Search code examples
seleniumselenium-webdriverphpunitautomated-testsfunctional-testing

What is the proper way to test mandatory field in selenium


I am testing my web application using Selenium. All the form validation in the web application is done by HTML5 and some JS(for safari browser). I want to know what is the proper way to test the form validation.

Currently I am using one approach, i.e Before I filled up a mandatory field I clicked on the submit button. If the page is not refreshed then I assume the form validation working correctly. But I think there should be a better approach to do it. I am unable to find any proper solution. Any suggestion will be highly appreciated.

I also go through this link. But it is not working for me because it is not enough to have required attribute (eg required attribute does not work in older Safari browser).


Solution

  • Rather than checking if the page is refreshed or not, you should instead expect that it is not and that a certain error message or field highlighting or something is applied to the current page. When in an error state, the input fields probably get given an extra class, or an error div/span might be added to the DOM, try checking for that sort of thing