Handling dynamic objects in test automation

In a given test case, objects are components of an application upon which you perform an action. For example, the search box of a website where you search for specific information, a drop-down where you choose your preferred option or an edit box where you can write or make required changes. Each object has a unique property or attribute, such as name, Xpath, CSS, Tags, etc. A test automation tool identifies and fetches these object properties during test case creation.

However, test cases often fail when object properties change, and the automation tool can not identify them anymore. For example, a search box in the center of a website's UI might be moved to the top right, causing the relative property to change. Hence the test case execution will fail.

There are also objects captured in a test case that are generated during run time and hence have a unique property, such as an order id on an e-commerce website. 

Most test automation tools fail to capture these dynamic object properties. To overcome these challenges, and ensure test automation success, it is important to identify and handle dynamic objects or objects whose properties undergo frequent changes in test cases.

Object repositories in Opkey

While creating a test case using Opkey recorder the spy feature identifies objects and captures their multiple properties like name, Xpath, CSS, and tags, along with their values, and stores them in a repository. 

These object repositories are useful for testing dynamic objects of an application, as, during test case execution, object properties are fetched from these repositories. So, even when an object property changes, Opkey can still identify the object using the other unchanged properties and execute the test case. 

Handling dynamic objects generated at runtime

Opkey has specific keywords that handle runtime-generated objects like the order id explained in the example above. One such keyword is string_concat which can capture the newly generated object property during execution and pass it as input to the next step to validate. Using this keyword, even a unique object id can be captured and validated successfully.

Conclusion - This is how Opkey can handle dynamic objects whose properties keep changing by using the Object spy and repository feature. Opkey also captures objects generated at runtime along with their properties using specific keywords. Ensure uninterrupted test case execution using the above-mentioned methods.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article