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:
- Validate whether an image and text is present in the gallery item 1 which is “Madan”
- Validate whether there is a “Book” button in the gallery item
- Click on the “Book” button
- 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.
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 <email@example.com>. Happy Testing!!!