Robot and pexpect

592 views
Skip to first unread message

vladimir...@gmail.com

unread,
Oct 9, 2013, 1:41:48 PM10/9/13
to robotframe...@googlegroups.com
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.

Sandeep Vaidya

unread,
Jan 29, 2018, 6:17:40 AM1/29/18
to robotframework-users
Did you make any progress on this ?  - Sandeep

Manikandan G

unread,
Jan 30, 2018, 10:03:36 AM1/30/18
to robotframework-users
Could you please paste your robot framework telnet scripts. 


-Manikandan.G

zhuy...@gmail.com

unread,
Jan 30, 2018, 9:23:31 PM1/30/18
to robotframework-users
I can't tell the exact reason for the fail, but you can try the following to debug it
  • declare the scope of the library by ROBOT_LIBRARY_SCOPE = "TEST SUITE"
  • init self.c in __init__ method
  • print "self.c" in Telnet and EnterSlot to check if they are the same object.




在 2013年10月10日星期四 UTC+8上午1:41:48,vladimir...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages