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

Refining and Creating Data Visualizations with LIDA

Microsoft’s Language-Integrated Data Analysis (LIDA) is a game-changer, offering an advanced framework to refine and enhance data visualizations with seamless integration, automation, and intelligence. Let’s explore the key features and applications of LIDA, and its transformative impact on the data visualization landscape. LIDA is a powerful library designed to effortlessly generate data visualizations and create data-driven infographics with precision. What makes LIDA stand out is its grammar-agnostic approach, enabling compatibility with various programming languages and visualization libraries, including popular ones like matplotlib, seaborn, altair, and d3. Plus, it seamlessly integrates with multiple large language model providers such as OpenAI, Azure OpenAI, PaLM, Cohere, and Huggingface.

Refining and Creating Data Visualizations with LIDA

Core Web Vitals: How to Improve LCP and CLS for Optimal Site Performance

Optimizing a website for performance is essential to enhance user experience and boost search engine rankings. Two critical metrics from Google’s Core Web Vitals (CWV)—Largest Contentful Paint (LCP) and Cumulative Layout Shift (CLS)—play a significant role in measuring and improving a site’s performance. These metrics outline the key strategies for optimization and highlight the observed impact on both mobile and desktop performance.

Core Web Vitals: How to Improve LCP and CLS for Optimal Site Performance

From Frontend-Heavy to a Balanced Architecture: Enhancing System Efficiency

Building efficient and scalable applications often requires balancing responsibilities between the frontend and backend. When tasks like report generation are managed solely on the frontend, it can lead to performance bottlenecks, scalability issues, and user experience challenges. Transitioning to a balanced architecture can address these limitations while improving overall system efficiency.

From Frontend-Heavy to a Balanced Architecture: Enhancing System Efficiency

From Blinking LEDs to Real-Time AI: The Raspberry Pi’s Role in Innovation

The Raspberry Pi, launched in 2012, has entered the vocabulary of all doers and makers of the world. It was designed as an affordable, accessible microcomputer for students and hobbyists. Over the years, Raspberry Pi has evolved from a modest credit card-sized computer into a versatile platform that powers innovations in fields as diverse as home economics to IoT, AI, robotics and industrial automation. Raspberry Pis are single board computers that can be found in an assortment of variations with models ranging from anywhere between $4 to $70. Here, we’ll trace the journey of the Raspberry Pi’s evolution and explore some of the innovations that it has spurred with examples and code snippets.

From Blinking LEDs to Real-Time AI: The Raspberry Pi’s Role in Innovation

Exploring Different Text-to-Speech (TTS) Models: From Robotic to Natural Voices

Text-to-speech (TTS) technology has evolved significantly in the past few years, enabling one to convert simple text to spoken words with remarkable accuracy and naturalness. From simple robotic voices to sophisticated, human-like speech synthesis, models offer specialized capabilities applicable to different use cases. In this blog, we will explore how different TTS models generate speech from text as well as compare their capabilities, models explored include MARS-5, Parler-TTS, Tortoise-TTS, MetaVoice-1B, Coqui TTS among others. The TTS process generally involves several key steps discussed later in detail: input text and reference audio, text processing, voice synthesis and then the final audio is outputted. Some models enhance this process by supporting few-shot or zero-shot learning, where a new voice can be generated based on minimal reference audio. Let's delve into how some of the leading TTS models perform these tasks.

Exploring Different Text-to-Speech (TTS) Models: From Robotic to Natural Voices
Refining and Creating Data Visualizations with LIDA

Refining and Creating Data Visualizations with LIDA

Microsoft’s Language-Integrated Data Analysis (LIDA) is a game-changer, offering an advanced framework to refine and enhance data visualizations with seamless integration, automation, and intelligence. Let’s explore the key features and applications of LIDA, and its transformative impact on the data visualization landscape. LIDA is a powerful library designed to effortlessly generate data visualizations and create data-driven infographics with precision. What makes LIDA stand out is its grammar-agnostic approach, enabling compatibility with various programming languages and visualization libraries, including popular ones like matplotlib, seaborn, altair, and d3. Plus, it seamlessly integrates with multiple large language model providers such as OpenAI, Azure OpenAI, PaLM, Cohere, and Huggingface.

Core Web Vitals: How to Improve LCP and CLS for Optimal Site Performance

Core Web Vitals: How to Improve LCP and CLS for Optimal Site Performance

Optimizing a website for performance is essential to enhance user experience and boost search engine rankings. Two critical metrics from Google’s Core Web Vitals (CWV)—Largest Contentful Paint (LCP) and Cumulative Layout Shift (CLS)—play a significant role in measuring and improving a site’s performance. These metrics outline the key strategies for optimization and highlight the observed impact on both mobile and desktop performance.

From Frontend-Heavy to a Balanced Architecture: Enhancing System Efficiency

From Frontend-Heavy to a Balanced Architecture: Enhancing System Efficiency

Building efficient and scalable applications often requires balancing responsibilities between the frontend and backend. When tasks like report generation are managed solely on the frontend, it can lead to performance bottlenecks, scalability issues, and user experience challenges. Transitioning to a balanced architecture can address these limitations while improving overall system efficiency.

From Blinking LEDs to Real-Time AI: The Raspberry Pi’s Role in Innovation

From Blinking LEDs to Real-Time AI: The Raspberry Pi’s Role in Innovation

The Raspberry Pi, launched in 2012, has entered the vocabulary of all doers and makers of the world. It was designed as an affordable, accessible microcomputer for students and hobbyists. Over the years, Raspberry Pi has evolved from a modest credit card-sized computer into a versatile platform that powers innovations in fields as diverse as home economics to IoT, AI, robotics and industrial automation. Raspberry Pis are single board computers that can be found in an assortment of variations with models ranging from anywhere between $4 to $70. Here, we’ll trace the journey of the Raspberry Pi’s evolution and explore some of the innovations that it has spurred with examples and code snippets.

Exploring Different Text-to-Speech (TTS) Models: From Robotic to Natural Voices

Exploring Different Text-to-Speech (TTS) Models: From Robotic to Natural Voices

Text-to-speech (TTS) technology has evolved significantly in the past few years, enabling one to convert simple text to spoken words with remarkable accuracy and naturalness. From simple robotic voices to sophisticated, human-like speech synthesis, models offer specialized capabilities applicable to different use cases. In this blog, we will explore how different TTS models generate speech from text as well as compare their capabilities, models explored include MARS-5, Parler-TTS, Tortoise-TTS, MetaVoice-1B, Coqui TTS among others. The TTS process generally involves several key steps discussed later in detail: input text and reference audio, text processing, voice synthesis and then the final audio is outputted. Some models enhance this process by supporting few-shot or zero-shot learning, where a new voice can be generated based on minimal reference audio. Let's delve into how some of the leading TTS models perform these tasks.

Additional

Your Random Walk Towards AI Begins Now