Easy Web Testing with Open Source Tools

Casmir OnyekaniCasmir Onyekani
6 min read

Have you ever been impressed by the seamless user experience (UX) of modern websites and apps? The reason for this smooth performance is that they undergo rigorous testing using top-tier tools. Join me as I guide you with code snippets through how you can achieve the same level of quality for your own website or app.

Why Web Testing?

To ensure that websites and web applications work correctly across different devices, browsers, and networks—whether it's checking for broken links, performance issues, or verifying that the site looks and behaves consistently on both desktop and mobile—testing is a critical step in creating reliable and user-friendly websites.

Without proper testing, users may experience bugs, slow load times, or even crashes. These issues can drive them away from your site and tarnish its reputation. To prevent these, developers and testers use automated tools to ensure websites perform well across multiple environments.

Why Choose Open Source Testing Tools?

These are software testing tools whose source code is made publicly available for you to use, modify, and distribute. These tools are typically free and foster collaboration within the community, allowing developers to enhance their features and capabilities.

Open-source testing tools are often preferred for their flexibility, cost-effectiveness, and community support.

As a start-up with a low budget and likely a small project, one of the most popular approach is to use open source tools, which are free, customizable, and accessible to anyone.

Examples of Open Source Testing Tools:

  • Selenium: A widely used tool for automating web browsers. It supports various programming languages and can run tests across different browsers.

  • JUnit: A popular testing framework for Java applications, primarily used for unit testing.

  • TestNG: An advanced testing framework inspired by JUnit, designed for test configuration and running tests in parallel.

  • Apache JMeter: A performance testing tool used to test the performance of web applications and measure their behavior under different load conditions.

  • Appium: An open-source tool for automating mobile applications on Android and iOS platforms.

  • Cypress: A JavaScript-based end-to-end testing framework designed for modern web applications.

  • Postman (Open Source Edition): While Postman itself is not fully open source, its open source version allows for API testing and development.

  • Robot Framework: A generic test automation framework for acceptance testing and acceptance test-driven development (ATDD).

There are several other open source tools available, but I will choose Selenium WebDriver. Why?

Selenium is one of the most widely used open-source tools for automating web browsers. It allows you to write test scripts that simulate real user interactions with a website, like clicking buttons, filling out forms, or navigating between pages. It supports multiple browsers such as Chrome, Firefox, Safari, Edge, and can be used with several programming languages including JavaScript, Python, Java, and C#.

While Selenium WebDriver allows you to run tests locally on your machine, Selenium Grid takes this a step further by enabling you to run tests across multiple machines and multiple browsers in parallel.

In other words, Selenium Grid allows for distributed testing. This makes it ideal for larger projects where you need to test your application across different environments quickly.

How to Set Up Selenium Locally with JavaScript and Node.js

If you're using JavaScript with Node.js for backend development, you can run browser tests with Selenium by installing the appropriate WebDriver for the browser you're testing.

Here's how to set up WebDriver for Chrome:

  1. Download Chrome WebDriver

    • Make sure to download the correct version of ChromeDriver for your operating system (Windows, macOS, Linux) that corresponds with your Chrome version.

    • To check your Chrome version, go to Settings > About Chrome in your browser.

  2. Add WebDriver to Your System’s PATH:

    • After downloading, check if the WebDriver is in your system’s PATH.

    • If it's not, extract the WebDriver and manually add its location to your system’s PATH so that your scripts can access it.

  3. Install Selenium WebDriver Package. You can install the Selenium WebDriver in your project by running:

      npm install selenium-webdriver
    
  4. To test if a form can be successfully submitted, you'll typically simulate filling out the form, submitting it, and then verifying the result (for example, by checking for a success message or URL redirection). Example:

     // test.js as file name
     const { Builder, By, until } = require('selenium-webdriver');
    
     (async function testFormSubmission() {
         // Create a new instance of Chrome WebDriver
         let driver = await new Builder().forBrowser('chrome').build();
    
         try {
             // Navigate to the page with the form
             await driver.get('http://localhost:3000');  // Replace with the correct URL of your form page
    
             // Fill out the form fields
             await driver.findElement(By.name('username')).sendKeys('testuser');  // Replace 'username' with your form field 'username' name
             await driver.findElement(By.name('password')).sendKeys('password123');  // Replace 'password' with your form field 'password' name
    
             // Submit the form (assuming there is a submit button)
             await driver.findElement(By.css('button[type="submit"]')).click();
    
             // Optionally, wait for the next page or success message
             await driver.wait(until.urlContains('success'), 5000);  // Wait for the URL to change after submission
    
             // Verify that the form submission was successful (based on URL change or a success message)
             let successMessage = await driver.findElement(By.id('success-message')).getText();  // Replace 'success-message' with the html element ID
             console.log('Form submitted successfully:', successMessage);
    
         } catch (error) {
             console.error('Form submission failed:', error);
         } finally {
             // Close the browser
             await driver.quit();
         }
     })();
    

    Steps in the code:

    • Navigate to the form page and load the page where the form is located. In this case http://localhost:3000 .

    • Fill the form fields by using findElement to locate the form fields by name or ID and fill them with values using sendKeys.

    • Submit the form by clicking the submit button: findElement(By.css('button[type="submit"]')).

  5. Run the test using the following command:

     node test.js
    

    After running the command, check for success. Verify that the submission was successful by checking for a success message or a URL change.

    Note:

    • Adjust the By.name('username'), By.name('password'), and By.id('success-message') selectors to match the actual form field names and IDs on your webpage.

    • Depending on what you want your form submission to do, you may also need to modify the wait condition (until.urlContains('success')) to match the behavior of your form submission.

Repeat the process using Edge, Firefox, Safari, or any browser of your choice. Make sure to download its driver. In the test.js file, change 'chrome' to the name of the browser you are testing.

You can read more about Selenium here.

Benefits of Using Open Source Tools

  1. Cost-effective: Selenium and Selenium Grid are completely free to use, making them great for developers, startups, and businesses on a budget.

  2. Customizable: As open-source tools, they can be adapted to fit your testing needs, allowing for flexibility that commercial tools may not offer.

  3. Scalable: To scale your tests across multiple machines and environments. You can set up a selenium grid locally or choose a cloud-based solution if you want even more scalability.

  4. Community Support: Being open source, Selenium has a large and active community of developers who contribute updates, fixes, and features. There are also plenty of tutorials, forums, and resources to help you along the way

Conclusion

By using open-source tools like Selenium, you can build a solid, scalable, and cost-effective web testing solution. Whether you're running tests locally or scaling them across multiple environments with Selenium Grid, these tools provide the flexibility and power needed for thorough web application testing. As you grow, you can integrate cloud services like BrowserStack or LambdaTest to extend your testing capabilities even further.

With this setup, you can ensure that your web applications run smoothly across all browsers and devices, delivering a seamless experience for your users. Happy testing!

If you found this guide helpful and enjoyable, please give it a like. For more insightful tutorials, follow me on X for updates 🙏.

10
Subscribe to my newsletter

Read articles from Casmir Onyekani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Casmir Onyekani
Casmir Onyekani

I am a Software Developer who is so passionate about teaching and writing.