Back to blog
Jun 04, 2024
4 min read

Automated Testing of Web App with Selenium

Web application testing using test-driven development (TDD) with Selenium

The project aimed to build a web application that allows users to enter latitude and longitude coordinates and receive the calculated distance to the Sun. I implemented this using a test-driven approach, which required writing tests before the actual code. Here’s an overview of our experience and the test cases I developed.

The application is available here at cs458.gahmed.com

Test Cases

TC1: Invalid Input Handling

I started by testing invalid input scenarios for latitude and longitude. For instance, latitude values outside the range of -90 to 90 or incomplete data entries should trigger an error message. This test ensures the application can handle incorrect inputs gracefully.

TC2: Input Format Validation

Next, I verified that latitude and longitude inputs consist only of numbers. This test case was crucial to prevent format errors and ensure data integrity.

TC3: Button Functionality

I tested the functionality of all buttons in the application, ensuring each button performs its intended action without issues.

TC4: GPS Functionality

To check the application’s ability to automatically gather and display user coordinates, I implemented tests that validated GPS functionality.

TC5: Responsiveness

With the increasing use of diverse devices, ensuring responsiveness is critical. I tested the application across multiple screen sizes to verify that fields and buttons adjust correctly.

TC6: Successful Login

A vital part of our project was user authentication. I ensured that users could log in successfully with correct credentials.

TC7: Invalid Login Handling

Conversely, I also tested the system’s behavior with invalid login credentials to confirm appropriate error handling and messaging.

TC8: Login with Enter Key

I validated that users could log in by pressing the Enter key, providing a smooth and intuitive user experience.

TC9: Email Field Validation

This test case checked for validation messages when users entered an incorrectly formatted email.

TC10: Empty Field Validation

I ensured that the application displayed appropriate validation messages for empty fields during login attempts.

TC11: Google OAuth Login

Testing third-party login functionalities, such as Google OAuth, was also part of our scope to provide a seamless user experience.

TC12: UI Element Presence

I checked the presence of all UI elements on the login page to prevent any disconnection between the site and the project code.

TC13: Latitude and Longitude Fields Presence

I verified that latitude and longitude input fields are present on the distance calculation page.

TC14: Calculate Distance Button

This test ensured that the Calculate Distance button is present and clickable, facilitating the primary functionality of our application.

TC15: Auto-Populated Fields

I tested if the latitude and longitude fields are auto-populated based on the user’s location, enhancing user convenience.

TC16: Distance Calculation Format

I validated that the calculated distance to the Sun is displayed in the correct format, ensuring clear and understandable results.

TC17: Calculate Button Enablement

I tested that the Calculate Distance button remains enabled even when fields are empty, but triggers appropriate error messages.

TC18: GPS Disabled Handling

To ensure robustness, I tested the application’s behavior when GPS is disabled, confirming that it handles such scenarios gracefully.

TC19: Nearest Sea Section

Finally, I checked the presence of the Nearest Sea section on the home page, enhancing the application’s user interface and functionality.

TDD Experience

Adopting TDD had a profound impact on our development process. Initially, writing tests before the actual code seemed to slow us down. However, the long-term benefits, such as early bug detection, modular code, and improved maintainability, far outweighed the initial overhead.

Early Bug Detection

Implementing tests before writing functional code allowed us to catch errors early, reducing the time spent on debugging.

Modular and Maintainable Code

TDD encouraged a modular, loosely coupled architecture, improving testability and maintainability. Our codebase became more organized, readable, and easier to manage.

Refactoring and Optimization

With the safety net provided by thorough testing, I confidently engaged in refactoring to enhance design and performance without breaking existing features.

Feel free to check out the Source Code