[Webinar] SpiraTest - Setting New Standards in Quality Assurance
Expect the unexpected
1. WebTech Varna 2007
Expect – the unexpected
Marian Marinov – mm@yuhu.biz
System Architect - Siteground.com
2. Agenda
➢ What is Expect and where it can help
➢ Implementations
`
➢ UNIX tool expect
➢ Python pexpect
➢ Perl Expect
➢ PHP expect
2
Marian Marinov - mm@yuhu.biz 1/30 WebTech Varna 2007
3. What is Expect
➢ Automating Interactive Applications
➢ Unique System Administrators tool
➢ Just Another TCL extension
➢ Great automated application tester
Where to use it:
➢ passwd automations
➢ automation of ncurses based application
➢ automated patch management
3
Marian Marinov - mm@yuhu.biz 2/30 WebTech Varna 2007
6. UNIX Expect application
send – sending string to the command
send_user – sending string to STDOUT
send_log – sending string to text log file
set timeout -1|0|60 – maximum wait for
command input
stty -echo – turn off KBD echo
spawn – start a program
interact – returns the control of the
started command back to user
6
Marian Marinov - mm@yuhu.biz 5/30 WebTech Varna 2007
7. UNIX Expect application
match_max 100000 - max buffer size
log_user 0|1 – enable/disable logging to
STDOUT
log_file filename – file where to store the
script output as addition to STDOUT
expect -exact – match exact string
expect -re – match regular expression
expect eof – wait the command to finish
7
Marian Marinov - mm@yuhu.biz 6/30 WebTech Varna 2007
9. UNIX Expect application
Get some user input:
stty -echo
expect_user -re "(.*)n"
set password $expect_out(1,string)
send_user "n"
9
Marian Marinov - mm@yuhu.biz 8/30 WebTech Varna 2007
10. UNIX Expect application
Show some examples :)
10
Marian Marinov - mm@yuhu.biz 9/30 WebTech Varna 2007
11. UNIX Expect application
I'm stupid and
I didn't understood anything
Can I still use Expect?
YES
autoexpect
11
Marian Marinov - mm@yuhu.biz 10/30 WebTech Varna 2007
15. Python pexpect package
Regular expression problems:
matching the end of the line can be tricky :)
The $ pattern for end of line match is useless.
child.expect ('w+rn') - matching word at the end
of the line
minimal match(instead of the standard greedy):
child.expect ('.+') - match always one char
child.expect ('.*') - match always zero or one char
15
Marian Marinov - mm@yuhu.biz 14/30 WebTech Varna 2007