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

Identifying Errors in Customer Media Assets With an Internal Tool

I still remember well my first week as a DevOps at Cloudinary. The year was 2017. Everything was new to me—people, laptop, processes—all of which to become familiar with in short order. A mantra often repeated to me in those days was that, Cloudinary being a SaaS, continuous service uptime is its most important goal.

Read more
Transformation Management Made Easy With Cloudinary

Transforming images with Cloudinary is simple, right? You find the ones you want and add them to your URL, building them up and trying them out until they’re perfect. You can then save the transformations that you created as named transformations for reuse. That final step sounds straightforward, but up until now has been a little tricky. With Cloudinary’s slick and new UI, creating and managing transformations through the Management Console just got even simpler. That UI now includes—

Read more
Generate Personalized Video Slideshows Automatically

Slideshows. Though sometimes boring, they are an essential cog in the corporate wheel, having served for decades as the medium for presentations. For a more lively display, consider combining various media types into a single video slideshow, which could serve as compelling, personalized, and engaging content for your users. Additionally, you can apply sophisticated transition configurations and Cloudinary’s many transformation capabilities.

Read more
It’s High Time to Replace JPEG With a Next-Generation Image Codec

I can be quite passionate about image codecs. A “codec battle” is brewing, and I’m not the only one to have opinions about that. Obviously, as the chair of the JPEG XL ad hoc group in the JPEG Committee, I’m firmly in the camp of the codec I’ve been working on for years. Here in this post, however, I’ll strive to be fair and neutral.

Read more
Adopting New Image Format AVIF With Cloudinary

AVIF is a new image format for the web. Before I tell you all about it, let me show you what AVIF can do.

One way to compare image codecs is to encode the same image in different formats at matched file sizes and then compare the visual quality of the resulting images. For example, I rendered the AVIF below with a q_50 quality transformation. It weighs 12.3 KB and, compared to the lossless original it looks pretty good subjectively.

Read more