0 scripting techniques and tips, 1 expect and expectmonitor for automating tasks, 1 expect script – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual

Page 102

Advertising
background image

5.0 Scripting Techniques and Tips

This section describes ways that scripting can extend the capabilities of CETerm.
Tips for script development are also presented.

5.1

E

XPECT AND

E

XPECT

M

ONITOR FOR

A

UTOMATING

T

ASKS

The “expect” script and “ExpectMonitor” class provide a general purpose
“prompt-and-response” tool. Using “expect” for automated login was described in
Section 2.6. Here we provide the complete listing of the scripts and discuss
other options for use.

5.1.1 Expect Script


The “expect” script illustrates a couple of powerful JavaScript constructs. Even
though the expect function has 4 defined arguments in the function declaration, it
is possible to pass an unlimited number of arguments. All arguments are
accessible through the special “arguments” variable. This script also shows the
object-oriented aspects of JavaScript by creating a new ExpectMonitor class.


/* expect */
//
// This script will "expect" a text prompt on the screen and
// respond with text or action.
//
// Syntax: expect( session, timeout,
// expectedText, response
// [,expectedText2, response2] )
//
// session is the session index
// timeout is the wait interval for each text in milliseconds
// expectedText can be a string or regular expression
// Response can be a text response or a function

function expect( session, timeout, expectedText, response )
{
// Build array from arguments
// This technique will accumulate any
// number of expect/response pairs
var TargetResponseArray = [];
for (var i=2; i < arguments.length; i++)
{
TargetResponseArray.push( arguments[i] );
}

// Create an ExpectMonitor class that manages the actions
var EM = new ExpectMonitor ( session, timeout,
TargetResponseArray );

// Set optional ExpectMonitor behaviors
//EM.silent = true;

Advertising
This manual is related to the following products: