Tuesday, 7 August 2012

Passing variable values through driver script (MonkeyTalk)

Value for variables can be passed as arguments in a driver script. The only requirement is that they should be provided in the same order as they are declared. We have two scripts here one is the main code (driven) script and the driver script.

MonkeyTalk form:-
Driven script
Vars * Define pass user
Input username EnterText ${user}
Input password EnterText ${pass}
Button LOGIN Tap %thinktime=500
Button LOGOUT Tap %thinktime=3000

Driver Script
Script <driven_script_name>.mt Run username1 "password1"
Script <driven_script_name>.mt Run username2 "password2" %thinktime=3000
Test message

Javascript form:
Driven script
<monkey_talk_project_name>.<driven_script_name>.prototype.run = function(pass, user) {

Driver script
<monkey_talk_project_name>.<driver_script_name>.prototype.run = function() {
                this.app.<dri>().run("john1", "password1");
                this.app.gj1().run("john2", "password2", {thinktime:"3000"});

Think Time at the end of second line of the driver script is important because when a script is executed the second time the first script needs some time to process the logout operation before starting the second script. Likewise, we can also provide a think time to the first script if it were to be followed by a test setup method/script while requires some processing.

Order of variables: It can be observed that in the driven script the password variable is declared first followed by the username variable. So all the values passed in as the first argument in the driver script are assigned to the pass variable. Although one might want to believe that since user variable is used first in the script the first value passed as argument would be the assigned to user, that is NOT correct.

Variables values that contain spaces can also be passed using the driven script. To prevent the space within the variable value from being interpreted as a separator between two arguments, one has to pass the argument within double quotes. For example: one can pass a password as “this is my password”


  1. I would like to thank you for sharing this great information with us. I am really glad to learn about this because it helps me to increase my knowledge.Web Designing Company | Website Design Company