Agile

Group Context – Dealing with reusable components in Test Automation

Google+ Pinterest LinkedIn Tumblr

What is Context?

“Context” is key in real life and in programming. You provide the necessary information in order to perform an action. For Example – Say you make a reservation at a restaurant for a party of four people, you would be required to provide a name for the reservation. Here the name is “contextual information” and you making a reservation is the “context”. Similarly, in test automation, it is important to know the context of elements from the DOM level in order to perform an action.

A Context in Test Automation

Context is all the more important when you have reusable components in your automation suite. For Example – let’s take the below web page.

 

It is a simple web page, containing a gallery of items. In this case, it has names of places with description and an option to book them as part of a reservation.

When inspecting the DOM, the gallery items looks like this

As you can see we have a gallery of items on a web page.

Also, if you notice each item in the gallery has similar elements such as an image, text, and button, this is because the code for generating those instances is the same. So, on a high level, all these gallery items are exactly the same except for the different data showing up for each element in the gallery item.

Say we create a reusable component called Clicking Gallery Item to:

  1. Validate whether an image and text is present in the gallery item 1 which is “Madan”
  2. Validate whether there is a “Book” button in the gallery item
  3. Click on the “Book” button
  4. Do some validations in the “Checkout” screen

It would look something like this:

 

Now, what if I want to use Clicking Gallery Item on Item 2 of the gallery which is “Shenji” instead of “Madan” (which was the 1st item) ?

 

Typically, we would have to create another reusable group to make it work for gallery item 2, which is time consuming and does not make sense when the whole gallery shares the same DOM structure.

When using code (e.g. Selenium), you can use the Page Object design pattern, and just pass the context in the constructor, either as a locator or a WebElement (see slides 40 and 41 here). In codeless/low-code platforms, this wasn’t possible until now with our new feature called “Group Context”. Now you can maximize reuse by assigning entire groups to different elements of the page and across pages within a single click. Taking the above example, you would not have to reassign all the elements/properties of Clicking Gallery Item when you want to perform same set of actions, on another item in the gallery, with the exact same DOM structure. This means, we can use Clicking Gallery Item on gallery item 2 which is “Shenji” without having to do any rework.

 

Use Cases for Group Context

Group Context can be used in many other scenarios, such as:

  • Repeating elements: when you have similar elements repeating in the page and want to execute the same steps on all of them.
  • Table rows: when you want to execute the same steps on different rows in a table.
  • Tabs or frames: when you want to use a group of steps recorded on one tab, in another tab.

Summary

We constantly keep working hard to improve the functionality and usability of our autonomous testing platform to support your software quality initiatives. We strongly believe this feature will benefit teams and help in making automation much smarter. Group Context is currently in beta and we would love your feedback.

Please use our chat support to give us feedback or e-mail us at <info@testim.io>. Happy Testing!!!

Raj Subramanian a former developer, moved to testing to focus on his passion. Raj currently works as a Developer Evangelist for Testim.io, that provides AI based software testing solutions for clients. He also provides mobile training and consulting for different clients. He actively contributes to the testing community by speaking at conferences, writing articles, blogging, making videos on his youtube channel and being directly involved in various testing-related activities. He currently resides in Chicago and can be reached at raj@testim.io. His website is www.rajsubra.com and twitter handle – @epsilon11. His videos on testing, leadership and productivity can be found here – http://www.rajsubra.com/my-youtube-channel/

Be smart & save time...
Simply automate.

Get Started Free