Note: You are looking at a static snapshot of documentation related to Robot Framework automations. The most recent documentation is at https://robocorp.com/docs

Telnet

Closes all open connections and empties the connection cache.

If multiple connections are opened, this keyword should be used in a test or suite teardown to make sure that all connections are closed. It is not an error if some of the connections have already been closed by Close Connection.

After this keyword, new indexes returned by Open Connection keyword are reset to 1.

Closes the current Telnet connection.

Arguments

ArgumentTypeDefault value
loglevelNone

Remaining output in the connection is read, logged, and returned. It is not an error to close an already closed connection.

Use Close All Connections if you want to make sure all opened connections are closed.

See Logging section for more information about log levels.

Executes the given command and reads, logs, and returns everything until the prompt.

Arguments

ArgumentTypeDefault value
commandnull
loglevelNone
strip_promptFalse

This keyword requires the prompt to be configured either in importing or with Open Connection or Set Prompt keyword.

This is a convenience keyword that uses Write and Read Until Prompt internally. Following two examples are thus functionally identical:

${out} =Execute Commandpwd

See Logging section for more information about log levels and Read Until Prompt for more information about the strip_prompt parameter.

Logs in to the Telnet server with the given user information.

Arguments

ArgumentTypeDefault value
usernamenull
passwordnull
login_promptlogin: \
password_promptPassword: \
login_timeout1 second
login_incorrectLogin incorrect

This keyword reads from the connection until the login_prompt is encountered and then types the given username. Then it reads until the password_prompt and types the given password. In both cases a newline is appended automatically and the connection specific timeout used when waiting for outputs.

How logging status is verified depends on whether a prompt is set for this connection or not:

1) If the prompt is set, this keyword reads the output until the prompt is found using the normal timeout. If no prompt is found, login is considered failed and also this keyword fails. Note that in this case both login_timeout and login_incorrect arguments are ignored.

2) If the prompt is not set, this keywords sleeps until login_timeout and then reads all the output available on the connection. If the output contains login_incorrect text, login is considered failed and also this keyword fails.

See Configuration section for more information about setting newline, timeout, and prompt.

Opens a new Telnet connection to the given host and port.

Arguments

ArgumentTypeDefault value
hostnull
aliasNone
port23
timeoutNone
newlineNone
promptNone
prompt_is_regexpFalse
encodingNone
encoding_errorsNone
default_log_levelNone
window_sizeNone
environ_userNone
terminal_emulationNone
terminal_typeNone
telnetlib_log_levelNone
connection_timeoutNone

The timeout, newline, prompt, prompt_is_regexp, encoding, default_log_level, window_size, environ_user, terminal_emulation, terminal_type and telnetlib_log_level arguments get default values when the library is imported. Setting them here overrides those values for the opened connection. See Configuration, Terminal emulation and Logging sections for more information about these parameters and their possible values.

Possible already opened connections are cached and it is possible to switch back to them using Switch Connection keyword. It is possible to switch either using explicitly given alias or using index returned by this keyword. Indexing starts from 1 and is reset back to it by Close All Connections keyword.

Reads everything that is currently available in the output.

Arguments

ArgumentTypeDefault value
loglevelNone

Read output is both returned and logged. See Logging section for more information about log levels.

Reads output until expected text is encountered.

Arguments

ArgumentTypeDefault value
expectednull
loglevelNone

Text up to and including the match is returned and logged. If no match is found, this keyword fails. How much to wait for the output depends on the configured timeout.

See Logging section for more information about log levels. Use Read Until Regexp if more complex matching is needed.

Reads output until the prompt is encountered.

Arguments

ArgumentTypeDefault value
loglevelNone
strip_promptFalse

This keyword requires the prompt to be configured either in importing or with Open Connection or Set Prompt keyword.

By default, text up to and including the prompt is returned and logged. If no prompt is found, this keyword fails. How much to wait for the output depends on the configured timeout.

If you want to exclude the prompt from the returned output, set strip_prompt to a true value (see Boolean arguments). If your prompt is a regular expression, make sure that the expression spans the whole prompt, because only the part of the output that matches the regular expression is stripped away.

See Logging section for more information about log levels.

Reads output until any of the expected regular expressions match.

Arguments

ArgumentTypeDefault value
expectednull

This keyword accepts any number of regular expressions patterns or compiled Python regular expression objects as arguments. Text up to and including the first match to any of the regular expressions is returned and logged. If no match is found, this keyword fails. How much to wait for the output depends on the configured timeout.

If the last given argument is a valid log level, it is used as loglevel similarly as with Read Until keyword.

See the documentation of Python re module for more information about the supported regular expression syntax. Notice that possible backslashes need to be escaped in Robot Framework data.

Examples:

Read Until Regexp(#|$)
Read Until Regexpfirst_regexpsecond_regexp
Read Until Regexp\\d{4}-\\d{2}-\\d{2}DEBUG

Sets the default log level used for logging in the current connection.

Arguments

ArgumentTypeDefault value
levelnull

The old default log level is returned and can be used to restore the log level later.

See Configuration section for more information about global and connection specific configuration.

Sets the encoding to use for writing and reading in the current connection.

Arguments

ArgumentTypeDefault value
encodingNone
errorsNone

The given encoding specifies the encoding to use when written/read text is encoded/decoded, and errors specifies the error handler to use if encoding/decoding fails. Either of these can be omitted and in that case the old value is not affected. Use string NONE to disable encoding altogether.

See Configuration section for more information about encoding and error handlers, as well as global and connection specific configuration in general.

The old values are returned and can be used to restore the encoding and the error handler later. See Set Prompt for a similar example.

If terminal emulation is used, the encoding can not be changed on an open connection.

Sets the newline used by Write keyword in the current connection.

Arguments

ArgumentTypeDefault value
newlinenull

The old newline is returned and can be used to restore the newline later. See Set Timeout for a similar example.

If terminal emulation is used, the newline can not be changed on an open connection.

See Configuration section for more information about global and connection specific configuration.

Sets the prompt used by Read Until Prompt and Login in the current connection.

Arguments

ArgumentTypeDefault value
promptnull
prompt_is_regexpFalse

If prompt_is_regexp is given a true value (see Boolean arguments), the given prompt is considered to be a regular expression.

The old prompt is returned and can be used to restore the prompt later.

Usage

${prompt}${regexp} =Set Prompt$
Do Something
Set Prompt${prompt}${regexp}

See the documentation of Python re module for more information about the supported regular expression syntax. Notice that possible backslashes need to be escaped in Robot Framework data.

See Configuration section for more information about global and connection specific configuration.

Sets the log level used for logging in the underlying telnetlib.

Arguments

ArgumentTypeDefault value
levelnull

Note that telnetlib can be very noisy thus using the level NONE can shutdown the messages generated by this library.

Sets the timeout used for waiting output in the current connection.

Arguments

ArgumentTypeDefault value
timeoutnull

Read operations that expect some output to appear (Read Until, Read Until Regexp, Read Until Prompt, Login) use this timeout and fail if the expected output does not appear before this timeout expires.

The timeout must be given in time string format. The old timeout is returned and can be used to restore the timeout later.

Usage

${old} =Set Timeout2 minute 30 seconds
Do Something
Set Timeout${old}

See Configuration section for more information about global and connection specific configuration.

Switches between active connections using an index or an alias.

Arguments

ArgumentTypeDefault value
index_or_aliasnull

Aliases can be given to Open Connection keyword which also always returns the connection index.

This keyword returns the index of previous active connection.

Usage

Open Connectionmyhost.net
Loginjohnsecret
Writesome command
Open Connectionyourhost.com2nd conn
Loginrootpassword
Writeanother cmd
${old index}=Switch Connection1# index
Writesomething
Switch Connection2nd conn# alias
Writewhatever
Switch Connection${old index}# back to original
[Teardown]Close All Connections

The example above expects that there were no other open connections when opening the first one, because it used index 1 when switching to the connection later. If you are not sure about that, you can store the index into a variable as shown below.

${index} =Open Connectionmyhost.net
Do Something
Switch Connection${index}

Writes the given text plus a newline into the connection.

Arguments

ArgumentTypeDefault value
textnull
loglevelNone

The newline character sequence to use can be configured both globally and per connection basis. The default value is CRLF.

This keyword consumes the written text, until the added newline, from the output and logs and returns it. The given text itself must not contain newlines. Use Write Bare instead if either of these features causes a problem.

Note: This keyword does not return the possible output of the executed command. To get the output, one of the Read ... keywords must be used. See Writing and reading section for more details.

See Logging section for more information about log levels.

Writes the given text, and nothing else, into the connection.

Arguments

ArgumentTypeDefault value
textnull

This keyword does not append a newline nor consume the written text. Use Write if these features are needed.

Writes the given control character into the connection.

Arguments

ArgumentTypeDefault value
characternull

The control character is prepended with an IAC (interpret as command) character.

The following control character names are supported: BRK, IP, AO, AYT, EC, EL, NOP. Additionally, you can use arbitrary numbers to send any control character.

Usage

Write Control CharacterBRK# Send Break command
Write Control Character241# Send No operation command

Writes the given text repeatedly, until expected appears in the output.

Arguments

ArgumentTypeDefault value
textnull
expectednull
timeoutnull
retry_intervalnull
loglevelNone

text is written without appending a newline and it is consumed from the output before trying to find expected. If expected does not appear in the output within timeout, this keyword fails.

retry_interval defines the time to wait expected to appear before writing the text again. Consuming the written text is subject to the normal configured timeout.

Both timeout and retry_interval must be given in time string format. See Logging section for more information about log levels.

Usage

Write Until Expected Outputps -ef| grep myprocess\r\nmyprocess
...5 s0.5 s

The above example writes command ps -ef | grep myprocess\r\n until myprocess appears in the output. The command is written every 0.5 seconds and the keyword fails if myprocess does not appear in the output in 5 seconds.