Article Overview:
This article will cover how you can achieve the following:
The article will describe the techniques for accessing properties within a variable and storing them in a new variable.
Problem Statement:
When dealing with complex data structures like JSON in automated testing, users often need to extract specific data from these structures to perform further validations or operations. However, the challenge arises when navigating through different types of property names within the JSONāsome of which may be straightforward, while others may be dynamic or contain special characters. Users require an efficient method to extract and store these values in new variables for subsequent actions.
This article provides a solution to access and extract data from JSON structures stored in Virtuoso variables, using dot notation, bracket notation, or a combination of both, depending on the complexity of the property names.
Solution:
The data stored in a variable in Virtuoso is stored in JSON format.
There are primarily three types of notations used to access a node/property within a variable.
1. Dot notation:
Use dot notation when the property name is straightforward
Store value ${$mileStoneUpdate.response.data.trackingId} in $tempData
Use bracket notation when the property name is dynamic or contains special characters.
For Example You may get a JavaScript error when you try to access object properties inside a variable using the dot notation when the property has a hyphen/dash in it
In such cases, bracket notation should be used
Store value ${$spayedToolTipDetails.attributes["data-bs-original-title"]} in $tempData
3. Combination of Dot and bracket notation:
A hybrid approach can be used for complex property names.
Store value ${$mileStoneUpdate.response.data['trackingId']} in $tempData
Comments
0 comments
Please sign in to leave a comment.