Please find below a table of expect methods:
Method | Description |
---|---|
equals |
used to test that the value of a variable matches the comparison value, e.g., the following tests that the value of vendor is 9: if( vendor.equals("9") ) |
expect |
commands are used when automating any interactive processes wait for the specific string from the process. E.g., this command instructs to wait for the Username prompt to display before sending the username: expect.expect('Username', {sendln param.username; CONTINUE;} |
expectAfter |
performs the included actions at the end of each expect block. It has the format: public void expectAfter(Object ... args) |
expectBefore |
performs the included actions at the start of each expect block. It has the format: public void expectBefore(Object ... args) |
getClass | Determining Type of object at runtime. |
getMatched |
it returns the part of the buffer consumed up until the match. It has the format: public StringBuffer getMatched() |
getMatcher |
returns matcher to allow access to groups. It has the format: public Matcher getMatcher() |
getTimeout |
returns the timeout value. It has the format: public int getTimeout() |
hashCode | returns a hashcode for the object. |
log |
writes to the Expect log, but only if DiagnosticLogging is enabled. It has the format: public void log(String log) |
notify | allows waking of one waiting thread, which can be used when you require a particular waiting thread to take action. |
notifyAll | allows waking of all waiting threads, which can be used when all waiting threads have been waiting for the current thread to complete. |
send |
sends the command to the host without appending a newline. It has the format: public void send(String s) |
sendPassword |
sends the password without logging it. It has the format: public void sendPassword() |
sendPassword2 |
sends password2 without logging it. It has the format: public void sendPassword2() |
sendLn |
sends the command to the host with an appended new line instruction. |
setDiagnosticLogging |
either true or false, specifies whether logging is turned on or off in expect.log. Entuity recommends to turn off logging if sensitive data are expected in the device's output. It has the format: public void setDiagnosticLogging(boolean diagnosticLogging) |
setLogUser |
controls terminal logging, which is on by default. To turn it off, enter: expect.setLogUser false |
setPassword | sets the password without logging it. |
setPassword2 | sets password2 without logging it. |
setTimeout |
sets the timeout. It has the format: public void setTimeout(int seconds) |
toString | converts the data type to a string. |
wait | pauses the script until an expected character string is received from the host. |
Manage magic values:
A magic value is a literal value used within a script. It is recommended you set up named constants for each magic value and use that constant within your script. For example, the following declarations (which are part of Expect) represent timeout, end of file, and continue values respectively:
public final static Integer TIMEOUT = -1;
public final static Integer EOF = -2;
public final static Integer CONTINUE = -3;
Setting these constants makes it easier to identify the purpose of the value, and if you have to ever update it, you only have to amend it once where you have declared it.
Comments
0 comments
Please sign in to leave a comment.