top of page

"Streamlining QA: The Power of Reusable Functions in Test Automation"

Writer's picture: Prashant BelladPrashant Bellad


In the world of software development, efficiency and quality go hand in hand. As applications grow more complex, ensuring every component works flawlessly across various use cases becomes a Herculean task. Enter the hero of our story: reusable functions in test automation.

For example, consider the below case

Say you have a reusable UI component in your application. This UI component has elements/attributes whose data varies based on different use cases. eg an Alert component has below attributes that vary


  • Icon as an image

  • Alert message

  • Actionable buttons


These attributes can be text copy on the component, a button to click or even an icon.

You want to create automated tests to cover these different use cases…

You would create a test script for asserting the component attributes. The script would be somewhat along the following lines…

Note: This is a Cypress script


For all the use cases involving this component you would have a separate test case per use case. These could be component tests or E2E tests (what is the best way is an entirely different discussion)

It is not prudent to duplicate these assertion scripts for each of the test cases… instead we can create a parameterized reusable function. The parameters can be “text copy”, “icon (image) on the component”, “button that needs to be clicked” and so on…

Now let's move the above code to a reusable function. In Cypress it is known as Custom Command.


The above illustration is a simple one which can be extrapolated for more complex cases as well however it is important to understand the fundamentals of this practice…

The obvious benefits are:


  • No script duplicity

  • Improved script maintainability

  • Engineers will follow standardized practices


Can there be any practical examples of catching issues?

Absolutely Yes…

An engineer while coding for a new feature creates a new component instead of reusing the existing one. In the process he may miss adding some elements such as icon image.

A Test Engineer testing this feature may not realize that this component should have been created from an existing template or reusable component and thus could miss noticing the icon which your test script can easily catch

Hope you find the article a useful resource. Do share your feedback with me at prashant@PristineProtech.com, visit www.PristineProtech.com to know more about our offerings and services...

0 views0 comments

Comments


bottom of page