Best Practices for Using the Web Recorder in Katalon

The Record and Playback approach (using the Web Recorder in Katalon Studio) is great for getting started with web UI test automation. However, using it without prior technical knowledge can cause a lot of stress for test maintenance in the long run. Below are some best practices for using the Web Recorder in Katalon that new users should know.

1. Understand the Pros and Cons of the Record and Playback Approach

The Web Recorder is helpful for two reasons:

  • It captures the manual actions performed on an Application Under Test (AUT) and automatically converts them into a test case
  • It automatically generates the locators to identify web elements/test objects

Since it’s easy to use, many new Katalon users have relied heavily on this solution to create automated web UI tests, especially non-programmers. However, there are limitations and risks that they need to be aware of.

The test recording approach offers minimal customization to cover complex test scenarios. Users often need to edit the test steps or modify the scripts after recording, which can be more complicated and time-consuming than just writing the scripts from scratch. Plus, the Web Recorder can create a lot of duplicated scripts and unorganized test objects if used carelessly.

Let’s say a user creates an automated test to verify a workflow in which a customer logs in, chooses an item to buy, checks their cart, and purchases. What happens if the user wants to test with 5 customers solely using the Web Recorder? They would create a 5x longer script with repeated steps or record 5 separate tests, each for a different customer.

Duplicated codes and test objects make test maintenance challenging to handle when the project scales up to dozens or hundreds of tests. Here is an example from one of our users, and we believe there are plenty of similar cases.

Another point users should know is that the locators generated by the Web Record are not always reliable. A typical example is when it has to capture a dynamic element that changes the attribute (ID, for example) every time a webpage loads. When the test is executed, it will fail since the generated locator no longer identifies the right element.

So, should users use Record and Playback? Yes, it’s an excellent way for non-programming users to get started with Katalon to automate simple web UI tests. But in the long run, to improve the test quality and maintenance, they should know how to use built-in keywords to modify tests in the Manual mode and ultimately get down to scripting to create automated test cases.

2. Learn How to Identify and Write Test Object Locators Manually

The Web Recorder works fine when the web UI is relatively stable or when the AUT is appropriately coded for testing purposes. If the HTML elements have ID attributes or custom attributes with fixed values, it will generate reliable locators to identify such elements.

Let’s look at the Facebook username input below that has both an ID attribute and a custom attribute for testing purposes.

By default, the Web Recorder will generate an Xpath locator:

//input[@id="email"]

You can also configure it to capture the custom attribute for the locator:

//input[@data-testid="royal_email"]

These locators are short, precise, easy to understand, and best used for web element identification.

However, not every web application is coded in an ideal way… In many cases, HTML elements don’t have ID attributes, or the IDs are dynamic. For these elements, the locators generated by the Web Recorder can be unreliable or break easily when the UI slightly changes.

Test automation beginners should learn how to identify and write solid locators for static and dynamic elements. They can start with the following resources, which our community’s experienced users recommend:

With a good understanding of web elements and locators, users can apply the Web Recorder or Spy Web utilities more effectively. They can check whether the generated locators are solid or not and make necessary changes to create solid test objects.

3. Organize Test Objects With Meaningful Names and a Clear Structure

Users can utilize the built-in Object Repository to keep the test objects neat and clean under their corresponding web pages. This is a good practice to reduce duplication and make maintenance easier.

Users should also have a naming convention for all of their test objects. For example, each one has a prefix to describe the element type, a name similar to the content shown on the UI, and follows the Camel-case principle. When looking at a test object in the repository, users should know what it is and where it belongs.

Tip: Users can rename objects and change their locators right after capturing them in the Web Recorder window by clicking on Show Captured Objects.

Key Takeaway

There’s no shortcut to creating quality automated tests. Beginners can use the Web Recorder to start with Katalon and test automation. But they should not depend solely on it, and should develop a good foundation and essential skills for test quality and maintenance because these are critical to improving their work quality over time.

If you want more articles like this, visit our Product Insights.

3 Likes