Feature Release: Roll Your Own Automated Commands

One of Toffee’s overriding design goals is to shrink the semantic distance from requirement to test to implementation. We are pleased to announce that we have achieved this goal by adding support for command aliases. This post explains the advantages of command aliases (tl;dr: skip to the demonstration video).

In real-world test automation, HTML syntax bleeds through many Toffee commands. XPath and CSS selector locators are as powerful as they are inscrutable to the uninitiated:

click element at xpath "//h5[text()='Rating']/following-sibling::fm-rating[1]/ul/li[#{rating}]"

Fast “by id” locators are more readable, but your audience doesn’t know or care what an HTML id attribute is:

test that dropdown with id "priority" equals "High"

“By label” locators are the most readable:

check checkbox "Send me a copy by email"

But even here, there is a problem: writing requirements using the language of user interfaces (“textbox,” “checkbox,” “dropdown,” etc.) is, for most purposes, a bad idea. Requirements describe these three commands in terms of the tested application’s functional domain: “When I select restaurants with 5 star ratings… ,” “…then the task priority changes to High,” and “When I ask for an emailed receipt… .” Your tests should, too.

This is why we created command aliases.

Command aliases allow you to roll your own commands using only the terms of your functional domain. As demonstrated in the video below (which tests a restaurant delivery application), you can define alias:

show only {rating} star restaurants

for the XPath example above:

click element at xpath "//h5[text()='Rating']/following-sibling::fm-rating[1]/ul/li[#{rating}]"

Add this alias to a script, and include that script wherever you need it. Then you can use the commands “show only 1 star restaurants” or “show only 5 star restaurants” to restrict the restaurants shown. Toffee extracts the rating number (1, 5, etc.) and injects it into the XPath expression behind the scenes.

Command aliases make your tests more readable, accessible, and robust:

  • Readable: Write test steps in the language of your functional domain – which your users and business analysts understand.
  • Accessible: Test authors don’t have to understand complex XPath or CSS selector expressions to use command aliases.
  • Robust: If your application changes, you only have to update these commands in one place, not the hundreds or thousands of scripts that use them.

The use and advantages of command aliases are described in the following video.

One thought on “Feature Release: Roll Your Own Automated Commands

Comments are closed.