Hi.
I have a simple library (LibTelnet.py) that contains a class (LibTelnet) with a function to connect to the device via telnet (Telnet) and function of the introduction of some commands at the command line telnet connection (EnterSlot):
root@autotester-server:/home/autotester/Samba/TRASH/pexpectRobotTest# cat LibTelnet.py
import pexpect
import sys
class LibTelnet:
def Telnet(self,ip):
self.c = pexpect.spawn('telnet ' + str(ip))
self.c.logfile = sys.stdout
print self.c.logfile
self.c.expect('ogin:')
self.c.sendline('admin')
self.c.expect('assword:')
self.c.sendline('password')
self.c.expect('>')
def EnterSlot(self):
self.c.sendline('slot 14')
self.c.expect('>')
self.c.sendline('exit')
self.c.expect('>')
Also I have a script (test.py) that imports the library and works perfectly:
root@autotester-server:/home/autotester/Samba/TRASH/pexpectRobotTest# cat test.py
import LibTelnet
ip = '192.168.16.205'
A = LibTelnet.LibTelnet()
A.Telnet(ip)
A.EnterSlot()
root@autotester-server:/home/autotester/Samba/TRASH/pexpectRobotTest# python test.py
<open file '<stdout>', mode 'w' at 0x7f6be2f86150>
Trying 192.168.16.205...
Connected to 192.168.16.205.
Escape character is '^]'.
********************************************
* Welcome to Device *
********************************************
login: admin
Password: password
********************************************
* Welcome to Device *
********************************************
Welcome to Device on Wed Oct 9 23:40:01 LOCAL 2013
hostname> slot 14
slot 14
hostname(slot-14)> exit
exit
I wrote a script for a robot framework (Test.txt):
root@autotester-server:/home/autotester/Samba/TRASH/pexpectRobotTest# cat Test.txt
*** Settings ***
Library LibTelnet
***Test Case *** KEYWORD
TEST1 Telnet 192.168.16.205
EnterSlot
But he fails!
root@autotester-server:/home/autotester/Samba/TRASH/pexpectRobotTest# pybot Test.txt
==============================================================================
Test
==============================================================================
TEST1 | FAIL |
ValueError: I/O operation on closed file
------------------------------------------------------------------------------
Test | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: /home/autotester/Samba/TRASH/pexpectRobotTest/output.xml
Log: /home/autotester/Samba/TRASH/pexpectRobotTest/log.html
Report: /home/autotester/Samba/TRASH/pexpectRobotTest/report.html
log.html:
Test Execution Log
Expand AllTEST SUITE: Test
Full Name: Test
Source: /home/autotester/Samba/TRASH/pexpectRobotTest/Test.txt
Start / End / Elapsed: 20131009 23:40:39.499 / 20131009 23:40:41.689 / 00:00:02.190
Status: 1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
Expand AllTEST CASE: TEST1
Full Name: Test.TEST1
Start / End / Elapsed: 20131009 23:40:39.517 / 20131009 23:40:41.588 / 00:00:02.071
Status: FAIL (critical)
Message: ValueError: I/O operation on closed file
Expand AllKEYWORD: LibTelnet.Telnet 192.168.16.205
Start / End / Elapsed: 20131009 23:40:39.518 / 20131009 23:40:41.536 / 00:00:02.018
23:40:41.536 INFO <StringIO.StringIO instance at 0x289abd8>
Trying 192.168.16.205...
Connected to 192.168.16.205.
Escape character is '^]'.
********************************************
* Welcome to Device *
********************************************
login: admin
Password: password
********************************************
* Welcome to Device *
********************************************
Welcome to Device on Wed Oct 9 23:40:29 LOCAL 2013
hostname>
Expand AllKEYWORD: LibTelnet.Enter Slot
Start / End / Elapsed: 20131009 23:40:41.536 / 20131009 23:40:41.588 / 00:00:00.052
23:40:41.588 FAIL ValueError: I/O operation on closed file
Why ordinary script works, and robot script not?
Thanks.