The Random Walk Blog

2024-10-10

A Beginner’s Guide to Automated Testing

A Beginner’s Guide to Automated Testing

What is Automated Testing?

A cursory prompt to chatGPT asking for guidance into the world of automated testing, spits out the words Selenium and Taiko. This blog post will explore our hands-on experience with these tools and share insights into how they performed in real-world testing scenarios. But first what is automated testing? Automated testing refers to the process of using specialized tools to run predefined tests on software applications automatically. It differs from manual testing, where human testers interact with the software to validate functionality and identify bugs. The key USPs of automated testing are efficiency in terms of multiple repeat runs of test cases, integration with CI/CD pipelines like Github actions and reliability.

Selenium or Taiko: Which Fits Your Needs Best?

Selenium is one of the most popular, versatile frameworks suitable for various browser automation tasks. Selenium supports multiple programming languages - Java, Python, C#, Ruby, JavaScript, Kotlin and PHP, making it easy for teams to absorb the skill set necessary for automated testing. Selenium is flexible and supports different browsers and platforms including mobile, making it a powerful tool for UI testing. Compared to the other tools though Selenium comes with a steeper learning curve and more complexity. Being an open source software, Selenium has a strong, active open-source community with a wealth of documentation, tutorials and forums for troubleshooting. 

What ChatGPT does not tell you though is that before diving into automation, it’s essential to grasp the fundamentals of testing—functional vs. non-functional testing, test cases, test plans, and test strategies. A solid foundation ensures that automation is used effectively.

Simulate User Actions: Selenium allowed us to automate user actions such as clicking buttons, typing into fields, and navigating websites. This helped automate repetitive tasks, freeing us to focus on more complex testing scenarios.

Handle Dynamic Elements: Modern web applications often include dynamic content (e.g., loading elements or changing page layouts). Selenium's ability to wait for elements to load or change state was a lifesaver. Automating testing on a payments page was a real challenge and since Selenium allows for handling XPath elements, this enabled easier and quicker automation.

Parallel Testing: Running tests across multiple browsers at the same time was a significant boost to productivity.

Despite its power, Selenium had a learning curve. Handling dropdowns with all the country names, payment pages, dealing with complex web elements, and integrating it with different reporting tools were challenging, but the flexibility it provided was invaluable. 

Taiko, while newer than Selenium, stands out for its simple, human-readable syntax with an interactive REPL extension called Gauge that is simple to use. It helps testers write maintainable test scripts quickly and reduces the burden of managing test execution, especially when dealing with dynamic elements like pop-ups. 

Simple Syntax: The commands in Taiko felt more intuitive compared to other automation tools. For instance, typing openBrowser('https://example.com') and click('Sign In') was straightforward and easy to understand.

Reliable Locators: Instead of relying on brittle CSS selectors or XPaths, Taiko uses flexible locators like labels and text values, reducing test flakiness caused by UI changes.

Headless Mode: Like Selenium, Taiko supports headless testing, which runs browser automation tasks without opening a visible browser window. This is particularly useful for continuous integration and fast execution of tests. Out of the box Taiko, however, supports only the Chrome browser.

We automated one of our web apps’ payment checkout pages using Selenium and then switched to Taiko as we wanted to shift away from using XPaths as identifiers. Below is a walkthrough using Taiko to automate testing of a checkout page. 

Automating Testing of the Checkout Page

The checkout process typically involves multiple steps such as filling out forms, selecting payment methods, applying discounts, and confirming the purchase, which makes it a high-priority area for test automation.

The first step to automating the checkout page is to automate testing for valid fields and verifying the form behavior for invalid and risky card numbers and ensure if the correct validation messages provided by Stripe are shown. We need to verify if on applying a valid discount, the total amount reduces correctly. Finally on submitting a successful payment, test that the payment success page is displayed. The following steps can be followed to test out the payment checkout page. 

First we need to install node

npm init

Followed by taiko:

npm install taiko

Install Gauge globally:

npm install -g @getgauge/cli or gauge init js

Driver method is not required in Taiko, we can directly use in-built functions for testing. 

card 1.png

To implement in-built step functions use an  * ahead of the function name in the spec page. User defined comments can be used in steps to directly automate testing in the step_implementation file as shown above. 

We need to write step functions to automatically fill in the input fields in the payment page and to test using the gauge extension. 

In the specs page, write a list of functions to be run, for example: 

Spec 1.png

The status of all the tests run can be viewed on a dashboard provided by Gauge as seen below.

Taiko 1.png

For teams working with devops pipelines like github actions, integrating automated tests into CI/CD processes is critical, Taiko can be used speedily. Automated tests can run on each code commit, providing rapid feedback to developers. Automated tests are great for repetitive tasks, but exploratory testing and tests requiring human judgment still need to be done manually. For one off complex test cases, Selenium comes in handy. 

Automated testing is a trend that’s here to stay; it’s becoming a necessity for any company looking to scale its development and testing efforts. As we move into the age of AI-powered automation, testers need to adapt by embracing new tools and technologies while still honing their traditional testing skills. Whether you’re using Selenium for its flexibility or Taiko for its human readable syntax, understanding the landscape of automated testing will help one thrive in today’s rapidly evolving software industry.

Related Blogs

Top 5 AI Tools That Should Be Used in the UAE: Do you use any of these already?

The United Arab Emirates (UAE) is not only keeping pace with the AI revolution—it's leading the way. With forward-looking policies such as the **UAE Strategy for Artificial Intelligence 2031**, the nation has established itself as a global testbed for AI innovation**.

Top 5 AI Tools That Should Be Used in the UAE: Do you use any of these already?

The When, Why and for Whom: a comparison of Frontend Frameworks React, Svelte and Solid.js

As a developer, choosing the right frontend framework can significantly impact the performance, maintainability, and scalability of your web applications. This article provides an in-depth comparison of three popular frameworks: React, Svelte, and Solid.js, from a developer's perspective .

The When, Why and for Whom: a comparison of Frontend Frameworks React, Svelte and Solid.js

Matplotlib vs. Plotly: Choosing the Right Data Visualization Tool

In a data-driven world, effective visualization is essential for analyzing complex datasets. Well-crafted visuals simplify intricate information, enhance storytelling, and make insights more accessible. Among the many tools available, Matplotlib and Plotly stand out as two of the most widely used Python libraries for data visualization. Each offers distinct features catering to different user needs. Let's explore their strengths, differences, and ideal use cases.

Matplotlib vs. Plotly: Choosing the Right Data Visualization Tool

AI-Driven Social Listening: Decode Your Gamers' Minds & Boost Revenue

The gaming industry is a multi-billion-dollar battlefield where player sentiment shifts rapidly. Every day, millions of gamers voice their opinions, frustrations, and desires on platforms like Reddit, Twitter, Discord, and Twitch. But are you truly listening?

AI-Driven Social Listening: Decode Your Gamers' Minds & Boost Revenue

DeepSeek Rising: How an Open-Source Challenger Is Cracking OpenAI’s Fortress

The AI race has long been dominated by proprietary giants like OpenAI, but a new contender is making waves—DeepSeek. With its latest open-source models, DeepSeek V3 and DeepThink R1, this Chinese AI company is challenging OpenAI’s dominance by offering competitive performance at a fraction of the cost. DeepSeek’s Mixture of Experts (MoE) architecture, efficient GPU utilization, and strategic innovations have enabled it to deliver high-performance AI models with minimal computational expense. But how does it truly compare to OpenAI’s GPT-4o and GPT-o1? Let's break it down.

DeepSeek Rising: How an Open-Source Challenger Is Cracking OpenAI’s Fortress
Top 5 AI Tools That Should Be Used in the UAE: Do you use any of these already?

Top 5 AI Tools That Should Be Used in the UAE: Do you use any of these already?

The United Arab Emirates (UAE) is not only keeping pace with the AI revolution—it's leading the way. With forward-looking policies such as the **UAE Strategy for Artificial Intelligence 2031**, the nation has established itself as a global testbed for AI innovation**.

The When, Why and for Whom: a comparison of Frontend Frameworks React, Svelte and Solid.js

The When, Why and for Whom: a comparison of Frontend Frameworks React, Svelte and Solid.js

As a developer, choosing the right frontend framework can significantly impact the performance, maintainability, and scalability of your web applications. This article provides an in-depth comparison of three popular frameworks: React, Svelte, and Solid.js, from a developer's perspective .

Matplotlib vs. Plotly: Choosing the Right Data Visualization Tool

Matplotlib vs. Plotly: Choosing the Right Data Visualization Tool

In a data-driven world, effective visualization is essential for analyzing complex datasets. Well-crafted visuals simplify intricate information, enhance storytelling, and make insights more accessible. Among the many tools available, Matplotlib and Plotly stand out as two of the most widely used Python libraries for data visualization. Each offers distinct features catering to different user needs. Let's explore their strengths, differences, and ideal use cases.

AI-Driven Social Listening: Decode Your Gamers' Minds & Boost Revenue

AI-Driven Social Listening: Decode Your Gamers' Minds & Boost Revenue

The gaming industry is a multi-billion-dollar battlefield where player sentiment shifts rapidly. Every day, millions of gamers voice their opinions, frustrations, and desires on platforms like Reddit, Twitter, Discord, and Twitch. But are you truly listening?

DeepSeek Rising: How an Open-Source Challenger Is Cracking OpenAI’s Fortress

DeepSeek Rising: How an Open-Source Challenger Is Cracking OpenAI’s Fortress

The AI race has long been dominated by proprietary giants like OpenAI, but a new contender is making waves—DeepSeek. With its latest open-source models, DeepSeek V3 and DeepThink R1, this Chinese AI company is challenging OpenAI’s dominance by offering competitive performance at a fraction of the cost. DeepSeek’s Mixture of Experts (MoE) architecture, efficient GPU utilization, and strategic innovations have enabled it to deliver high-performance AI models with minimal computational expense. But how does it truly compare to OpenAI’s GPT-4o and GPT-o1? Let's break it down.

Additional

Your Random Walk Towards AI Begins Now