How to automate web application form testing using Selenium

All web applications require some data from their customers. And the developer integrates the input form for entering the data information. The form may be a login form, registration form, request form, contact form, or any other form.

The developer usually adds a validation and verification mechanism behind the form action to ensure the customer has entered the correct information. And that’s where all the processing happens.

Your task is to automate web application form testing. How are you going to do it?

If you have done manual testing, you start by creating different test scenarios for the testing form. And then, you will collect test data from various sources according to form fields.

And you start the manual testing.

  1. You open the web application form.
  2. You enter the form information from data files.
  3. You submit the request and review the result.
  4. You compare it against the expected output and tick the spreadsheet.
  5. You send the report to your peer.

You, as a software tester, want to test all features. And this way, you could help in creating robust and reliable software. And the Selenium framework is here to help you.

Selenium is the testing automation framework, and you can perform end-to-end testing using it. You can repeat the same set of test scenarios against different web browsers, over various platforms, and many times. The best part you don’t need to add any extra effort to verify the changes.

The question is how you are going to integrate the Selenium framework in your testing work. I have been using Selenium for a long time and have used it in many web applications.

And You could follow the below steps to perform form testing using the selenium framework;

  1. You create test scenarios.
  2. You collect test data according to form fields.
  3. You create a page model with all the required methods.
  4. You create unit test files for testing the scenario. You can split the test scenarios into multiple test files.
  5. You verify the actual results against the expected results.

I have been using the Selenium framework for the last two years and have integrated it into my client websites. And therefore, I am sure the following example will help you in the selenium framework integration in any website.

I am assuming you have a good understanding of the programming concepts. Otherwise, you may not write correct test cases using Selenium. Programming knowledge is essential for integrating any testing framework.

And if you do not have programming knowledge, my advice is to start learning it before you are in trouble.

Let’s start integrating the form testing using the Selenium framework. I am taking the login form as an input form example and using Python language for writing test cases.

Website login form

I am writing a summary of the login form and what we need to test in it.

The login form has two fields; username and password. And following is their specification;

  1. The username could have a maximum of 20 characters.
  2. The username could not have any special symbols.
  3. The password could have a maximum of 10 characters.
  4. The password could have characters and numbers. 
  5. On failure, the login page shows invalid credentials message.
  6. On username validation failure, the login page shows an invalid username message.
  7. On password validation failure, the login page shows an invalid password message.
  8. On login success, the system navigates to the home page. And it has a welcome username title.

In the following sections, I will add automation testing for the login form.

I prefer to use a page model pattern. It requires you to separate test cases and page-related features. And they won’t have any adverse effect during the further update. 

Create test scenarios for the login form

Using the above specification, I could create the following test scenarios. In a live web application login form, you may have many other test scenarios. For learning purposes, I am adding some basic test scenarios.

  1. Username failure:
  2. Password failure:
  3. Login credentials failure:
  4. Login success:

And to accommodate these test scenarios, I created the following test file.

Create test data for the login form

The next step is to collect the test data for the login form. You could create a separate data file in another directory. And other testing methods could use these data files as well.

And I have created the following data file for it;

username.json

password.json

valid_login_credentials.json

invalid_login_credentials.json

 

Any non-technical person can update the data files without affecting any one of the testing files. And these serve the purpose for later use as well.

We can also send these data files for client approval.

Create page model

Now is the time to create a page model. We created test files and data files. These two files help a page model to perform some actions.

Following is the page model screenshot.

You see, I created methods, and other test files could use them. And these methods are accessing Selenium web-driver API for getting form elements and HTML identities.

The benefits of using page model patterns are clear from the context. You can change the page element without affecting the test scenarios. And you can change the test scenarios by changing the test files.

And in a situation where some complex tests need to be separated, you can create multiple test files without affecting the page logic.

And yes, you don’t need to create test data for other kinds of testing. Other testing methods can use the same data file without affecting the automation testing.

The above example is part of a big project, and I modified it for this blog and your learning. The actual files have different business logic and methods. But the ideas are the same.

One last thing, software testing automation is the future of testing. And therefore, you should start learning automation testing by using any available testing framework like Selenium. You won’t regret your decision in the future.

If you are unsure as to how to integrate the selenium framework, you can further contact me. I will try my best to reach you in time.

Subscribe to our weekly newsletter

processing ...