Cloudinary Blog

MythBusters, Part 1: “Automated UI Tests Are Unstable”

Alexey Kagansky
By Alexey Kagansky
MythBusters, Part 1: “Automated UI Tests Are Unstable”

Even though most people agree that testing software UI is important, many believe that automated tests are slow and unstable. Consequently, many technology companies prefer manual testing. I'll convince you otherwise in this post: even though automating UI tests and ensuring that they are fast and reliable is tough to accomplish, it’s definitely doable.

Construction of Reliable Selectors

I once asked a friend why his company didn't automate UI testing. He replied, “Because the tests break easily. For example, if an engineer changes something in the DOM, it causes errors in the tests.”

However, that issue is solvable. For example, a popular question among automation engineers is which selectors are the best. The common answer is id or class, rather than XPath, which could fail. Let me bust this myth and explain how to render automation frameworks reliable.

Choosing id for selectors has a caveat: the value must be unique for the document, which means that it doesn’t work in the case of multiple identical UI components, such as the <input> element. As a resolution, our automation group at Cloudinary opted to identify locators with an attribute called data-test by leveraging standard data-* attributes. Instead of just picking the least risky attribute that exists, we added data-test to the application code. Not only do searches for the web element then become stable, developers are also free to change IDs and class names.

Additionally, as a rule, front-end developers add logic or styling with IDs or classes. Leveraging a unique attribute creates a convention that distinctly separates development and QA, leading to transparency and clarity.

Here’s another example:

metadata class name

Class names don’t work here because the styling libraries, which handle scoping, automatically generate the classes. Hence, classes are not a reliable source, and the component is not unique in the DOM.

However, adding the automation attribute data-test to the component leaves the UI intact, enabling QA engineers to build a stable and consistent selector.

Class name

Some of you wondered about the performance of having data attributes act as selectors. Assuringly, the lookup time between class and data attributes is usually the same.

Summary

To recap, if planned and executed correctly, E2E UI tests can be sound, efficient, and flexible. Front-end developers will be at liberty to tweak the DOM with no need for the QA automation team to make corresponding adjustments, saving time for everyone. Bottom line: this process makes it easier to look for the right selector.

Part 2 of this series will bust another myth: “Automating E2E is time-consuming.” Stay tuned.

Recent Blog Posts

Image-Editing Basics and a Tutorial for Automation With AI

You likely find yourself continually editing images for enhancement by eliminating flaws and tweaking the overall presentation, typically with software tools. Examples of basic editing are straightening, cleaning, and cropping images, as well as adjusting the contrast, exposure, and white balance. With advanced software like Cloudinary, you can automate not only editing tasks, such as quality adjustment and encoding, but also delivery.

Read more
Tips for Retaining Audience Through Engaging Videos

Measuring the level of interest your videos generate helps you produce compelling content. The measurement and optimization approach must, however, address the various aspects of each video, including the A/B test hypothesis and iterations. A high engagement rate spells effective videos; a low engagement rate calls for content improvement.

Read more
Forbes Cloud 100: When the Stars Align

In 2017, when Cloudinary first made the Forbes Cloud 100 as a ‘Rising Star,’ it was an incredibly proud moment for the company. In 2018 we graduated from Rising Star status to be acknowledged as part of the incredible Cloud 100, the top 100 SaaS companies in the world. Today marks our third consecutive year on this prestigious list.

Read more
A Cloudinary-Enhanced Student-ID App

I’m an instructional designer on Cloudinary’s Solutions and Training team. As the COVID-19 pandemic emerged in March, like other global organizations, we pivoted to set up virtual courses. As much as we looked forward to resuming in-person classes in the future, we switched gear to focus on the virtual way of learning.

Read more
Image Formats: Getting it Right

Image formats, which are standards for digital images, can be uncompressed, compressed, raster based, or vector based. You determine the DNA of your images with the formats you adopt, each of which offering different capabilities. For example, rasters generate images with pixels; vectors, with vectors or proportional formulas. PNGs can display logos without background; JPEGs always come with backgrounds. This article explains the main properties of the various image formats, including their basic concepts and pros and cons.

Read more