Cloudinary Blog

Testing Functional UI the Cloudinary Way

Automated UI Testing with End-to-End JavaScript Tests

You may have heard that we recently launched our Digital Asset Management (DAM) system. On top of other challenges, that was our first launch targeted at the nondeveloper audience, to whom the UI is a central element of a product’s capabilities.

Releasing robust products on time require comprehensive automated testing at all levels: Unit , API, and UI testing. This post describes our solution for end-to-end UI automation testing, which serves both QA engineers and front-end developers in minimizing bugs in releases and in speeding up testing for faster development and shorter release cycles.

Objectives

Right off the bat, we had these objectives in mind:

  • Create a JavaScript-based test automation framework with Node.js so that developers can stay in their “comfort zone.”
  • Facilitate root-cause error analysis through informative reports for a thorough investigation of failed tests. The reports must be human friendly, containing as many relevant details as possible, such as logs, screenshots, and page sources.
  • Execute in parallel for fast, continuous integration feedback.
  • Build configurable test suites for various platforms and setups (deployment, pull requests, on demand, and such).
  • Enhance browser coverage by running tests on various browsers with local and remote setups.
  • Develop reusable components with a functional interface that mimics user actions and that supports test maintenance and readability.

Implementation

Let’s now introduce our new test automation framework wdio-allure-ts, which promises to help you quickly start authoring end-to-end JavaScript ui tests with a useful, informative report.

First, some background: We considered and tested many other leading testing solutions, such as Allure Reporter, which offers a pleasing and functional design. You can also easily integrate it with Node.js and Jenkins. However, Allure Reporter falls short in several ways:

  • The Reporter logs WebDriver commands (GET and POST) that give no clues on failures.
  • Page-source and browser-console logs of failed tests are absent in the reports.
  • Most of the errors reflect timeouts only. No clear failure reasons. WebdriverIO, a Node.js testing utility, meets our needs. With a sizable community coupled with simple setups for configuration and customization, WebdriverIO supports third-party integrations (automation testing reports, test runners), Page Object Model, and synchronous execution. Also, we chose TypeScript instead of plain JavaScript for IntelliSense support, which spells fast and seamless development with typed variables.. Subsequently, we blended those tools into our new, open-source solution for end-to-end functional testing: wdio-allure-ts.That solution wraps the most common WebdriverIO actions, generating intuitive error messages in case of failure, custom logs for the Allure Reporter, more validations for enhanced stability, and last, but not least, IntelliSense.

Example With Pure WebdriverIO

Now take a look at an example of an action that, after validating that a particular element is visible, clicks it, logs every step to the Reporter, and throws meaningful errors for failures, if any.

   const selector: string = "someSelector";
   logger(`Click an element with selector: ${selector}`);
   try {
     logger(`Validate element with selector ${selector} is visible`);
     browser.isVisible(selector);
   } catch (error) {
     throw new Error(`Tried to click not visible element, ${error}`);
   }

   try {
     logger("Perform click action");
     browser.click(selector);
   } catch (error) {
     throw new Error(
       `Failed to click an element by given selector ${selector}. ${error}`
     );
   }

Example with wdio-allure-ts:

const selector: string = "someSelector";
BrowserUtils.click(selector);

You can see that our new framework offers the same capabilities with much cleaner code. Because the framework automatically handles logging and error reporting, automation developers can focus on testing the business logic. You can add more report logs with a simple Reporter API for log levels: step, debug, error, info, and warning. The logs are displayed on the terminal and reflected in the report. Example:

import { Reporter } from 'wdio-allure-ts';
Reporter.step('Step log entry');
Reporter.error('Error log entry');

Terminal Output

Terminal Output
Note the difference in the highlighted areas between the original report and the one created with wdio-allure-ts. Original Report

Original Report

wdio-allure-ts Report(live report example):

`wdio-allure-ts` Report

That's It. Ready to Try?

For you to take a crack at it, we've created a sample project with a quick introduction to our framework and its usage on a real-world application The project contains examples for the following:

Just clone the repo, read the README, and create new tests according to the examples. We'd love to hear your thoughts and ideas for integrating wdio-allure-ts into your testing workflow. Send them to us in the Comments section below please.

Recent Blog Posts

Mobile Optimization: Optimize Your Mobile-Web User Experience

TL;DR

We live in a visual world, often while on the go, and consumers expect media-rich web content. Accordingly, the loading speed of images and videos is a big factor in user experience. To optimize customer satisfaction with your mobile content, you must focus on the quality, format, and size of your digital assets. With Cloudinary, optimization is simple, not only enhancing your mobile web and app performance, but also upping your SEO game and boosting customer experience.

Read more
Multi Codec Adaptive Bitrate Streaming

In Part I of this series, we discussed the optimal way to deliver progressive video streams, taking advantage of modern, efficient codecs. That approach works great for short-form videos (under 20 seconds) and for videos that are displayed at a low resolution (such as ads and previews). But what if you're delivering videos that are longer than 20 seconds for a higher-resolution experience? You can certainly still deliver them as a single file (progressive streaming), but you might run into issues, such as buffering or too high a resolution.

Read more
Why Visual Storytelling Matters

In my communications role here at Cloudinary, I get to speak to a lot of experts across a variety of subject matter areas, technology and not, about what it takes to connect to today’s consumer. The power of images and other forms of digital content is often at the center of these conversations given our focus at Cloudinary. And as a hobbyist and professional photographer for more than 20 years, I care deeply about images and their role in creating authentic connections and engagement.

Read more
How to Automatically Generate alt Text for Images

Images and videos are critical for ensuring user engagement on the web. For instance, on a retail website, images of a product from different angles or a 360-degree video of the product can lead to higher conversion rates. For a news website, users are more likely to read articles with visual media accompanying the content. It has been reported that posts that include images produce a 650-percent higher user-engagement rate than text-only posts.

Read more