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
Followed by taiko:
Install Gauge globally:
Driver method is not required in Taiko, we can directly use in-built functions for testing.
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:
The status of all the tests run can be viewed on a dashboard provided by Gauge as seen below.
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.