Interview Questions

How to define the variable in script that have stored in excel sheet using winrunner?

Mercury WinRunner FAQ


(Continued from previous question...)

How to define the variable in script that have stored in excel sheet using winrunner?

How to define the variable in script that have stored in excel sheet using winrunner?
[In A1 field contains {Class:push button, lable:OK.....}
In B1 field Contains OK = button_press(OK);
where OK contains the value of field A1
OK should act as a variable which has to contain value of field A1]


Answer1:
There is no need to define any variable that is going to use in the Testscript. You can just start using it directly.
So, if you want to assign a value to the dynamic variable which is taken from Data Table, then you can use the "eval" function for this.
Example:
eval( ddt_val(Table,"Column1") & "=\"water\";" );
# The above statement takes the variable name from Data table and assigns "water" as value to it.


Answer2:
Write a function that looked down a column in a table and then grabbed the value in the next cell and returned it. However, you would then need to call
button_press(tbl_convert("OK"));
rather than
button_press("OK");
where tbl_convert takes the value from the A1 (in your example) and returns the value in B1.
One other difficulty you would have would be if you wanted to have the same name for objects from different windows (e.g., an "OK" button in multiple windows). You could expand your function to handle this by having a separate column that carries the window name.

(Continued on next question...)

Other Interview Questions