OpKey Web allows you to create dynamic objects at runtime. The Dynamic Object is an advanced feature which is very helpful in case you need to create and use multiple objects which have almost similar properties. In such cases, you can use dynamic objects which are used only at runtime.
Why to use Dynamic Objects instead of Object Repository?
Its true that the Test scripts can be executed both with Object Repository (OR) and Dynamic Objects. However, Dynamic Objects have several advantages over OR.
Suppose you need to create an FL to click on a button. First of all, you need to record actions fetch objects, save and execute them in case you are using OR.
While using Dynamic Objects, you just need to inspect element and provide Xpath as the Dynamic Object Property. The FL will get executed without fetching the required objects.
For More – See Example below:
To add a Dynamic Object, follow the steps given below:
- Select any Test Step/Function Library whose action requires an Object Input Argument.
- Click on the Object Input Argument tab.
- Go to Object Type tab and select Dynamic Object Radio Button.
- Add Property allows you to add any property of the dynamic object.
- you can add properties like Logical Name, Innertext and tag as dynamic object property in the following two conditions:
The agent is not synchronized with the database.
-If the agent is synchronized with the database but you are working on old scripts.
-You can select any property for which you want to provide value. Suppose you have provided values for properties like Logical Name, Name, Innertext, id, class and tag.
In this case, OpKey will take the property which has the highest priority as Dynamic Object Property.
*The priority of the object properties are set internally in OpKey in the following order:
In case you click on Object Repository or Output radio button then It will not be reflected in the Test Steps unless and until you select the Desired Object Repository or output.
- Select any property for which you want to provide value. Click on the Value cell. You can provide either static value or value from Global Variable or Output of a Test Step can be used as an input for this Test Step or input parameter of a function library.
- Select the desired value and click OK.
- The Dynamic object will act as an Object Input Argument for the selected Test Step.
- You can also create a dynamic object at the time of recording.
Test step 1: OpenBrowser
Test Step 2: For
“i” is a output variable which will hold the output of Step2
Test Step 3: StringConcat
This String 2 “i” indicates the variable whose value changes on every iteration
For the First iteration the value of i [String 2] is “1”
Out1 is a output variable which will hold the output of Step3 StringConcat
Test Step 4: Click
Test Step 5: Next
The FL will get executed and Click on the highlighted alphabets [in the screenshot below] one by one from A- Z
Since a single value is provided for the Test Step 1, only 1 iteration will be performed for the Test Step 1. So in this case, Test Step 1 will be executed and will open the given URL on the specified browser. Once the execution is completed for Test Step 1, the control moves to Test Step2 which creates a For Loop with an incremental variable i having initial value 1.
Now, Test Step 3 and 4will get executed with the initial value of i=1. The Xpath property for all the alphabets highlighted in the screenshot has almost similar Xpath property. Hence, we have used Dynamic OR feature for this particular scenario. We logically made Xpath (as shown above) in such a way that the Xpath changes with each iteration of for loop. This Dynamic Object containing desired Xpath property is passed as an Object input Argument for Test Steps 3, 4.
Thus, when the FL gets executed for the first time, the first value [A] gets clicked. Then Test Step 6 transfers the control back to Test Step 2 with an incremented value of i=2 for the 2nd Iteration.
The process continues for 25 Iterations till the value of i becomes 25. This is how the Test Case gets executed completely.
When the Test Case is executed, the execution takes place as follows:
Test step 1:
Iteration 1: Opens the given URL on the specified browser.
For the Test Step 2, 3, 4, 5
And so on till 25 Iterations are completed.