1 / 11

Expect

Expect. Tool for Automation and Testing. Expect - Introduction. Unix automation and testing tool Written by Don Libes Primarily designed as an extension to the Tcl scripting language

irma
Download Presentation

Expect

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Expect Tool for Automation and Testing

  2. Expect - Introduction • Unix automation and testing tool • Written by Don Libes • Primarily designed as an extension to the Tcl scripting language • Useable in interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others.

  3. Expect – TCL* Basics • Everything is a command • No Fixed Parser • Case-Sensitive • Explicit Expression Evaluation • set a 5  a = 5 • set b a+2  b = a+2 • set c [expr $a+2]  c = 7 (Note: $ for variable substitution) • Simple variables are strings of arbitrary length • Real & Int  cast to real • Non-numeric string and real/int  cast to string • Built in Lists • Standard flow control structures (while, if, etc.) • String manipulation with Regular Expressions • Procedures – arguments can be passed by value or reference *Tool Command Language

  4. Expect – The Programming Language • Extension of TCL, so the syntax is TCL syntax • Basic command set • expect • send • spawn • Interact • Regular Expression pattern matching • “Glue” to combine separate executables

  5. Expect – Pros / Cons • Pros • Built on existing system tools, so learning curve is small. • Extensive support from corporate entities* *Silicon Graphics, IBM, HP, Sun, Xerox, Amdahl, Tektronix, AT&T, ComputerVision and the World Bank • Numerous ports to other programming languages (Perl, Python, java, etc.) • Cons • Only useful for command line scripting • Cryptic syntax for those unfamiliar with TCL (When do I use a $ again?) • Generally machine dependent tools are run with Expect, so porting scripts cross-platform is not easily supported.

  6. Expect – “Hello World!” Start Expect with “expect” or write the script to a file and run > expect filename • send “Hello World!\n” • expect “Hi\n” Putting it together • Expect “Hi\n” { send “Hi World!\n” }

  7. Expect – More Advanced • expect "hi\n" { send "Hi World!\n" } \ "hello\n" {send "Hello World!\n" } \ "bye\n" {send "Bye World!\n" }

  8. Expect - Automation spawn ftp $argv expect "Name" { send "anonymous\r" } \ "name" { send "anonymous\r" } expect "assword:" send "nobody@nobody.com\r" interact

  9. Expect - Others • Brute Force security • Beer • Chess • Weather • Rogue • Hunt

  10. # start things rolling spawn gnuchess set id1 $spawn_id expect "White \\(1\\) :" send "random\r" send "depth 6\r" send "go\r" # read_first_move expect -re "My move is : (.*)\n" spawn gnuchess set id2 $spawn_id expect "White \\(1\\) :" send "random\r" send "depth 5\r" send $expect_out(1,string) while {1} { expect { -i $id2 -re "is : (.*)\n" { send -i $id1 $expect_out(1,string) } -i $id1 -re "is : (.*)\n" { send -i $id2 $expect_out(1,string) } } } Expect - GnuChess

  11. Expect - Questions

More Related