COM Interface for Telnet to UNIX and Linux

 A little bit of history

A while back I had to automate a Client/Server application and execute quite a few UNIX commands on a backend.

After trying several things, like PuTTY, TE Add-in, Exceed, etc., I made a choice to use Exceed.

It worked decent enough, but it was a complicated solution. I had to use "Capture to File" feature and then parse the file.

A couple years later I was working on a performance test for Telnet interface and I needed to use WinSock protocol to create a LoadRunner script.

It got me thinking - Are there any WinSock COM interface I can use in QTP?

My goal was to connect to Unix/Linux box bypassing external applications and execute scripts on locked boxes. Another reason was that QTP has problems with GetVisibleText method.

This is from QTP 9.5 Readme:

On Windows Vista 32-bit or any 64-bit operating system, QuickTest text recognition features (such as text checkpoints and output values, GetVisibleText and GetTextLocation test object methods, and TextUtil.GetText and TextUtil.GetTextLocation reserved object methods) are limited and are not always reliable.

 After several unsuccessful attempts I finally found w3Sockets Dll which satisfied my needs.

 It is a free download from Dimac Development - www.dimac.net

 

W3Sockets DLL

 w3Sockets properties and methods: 

*      COM Object - socket.tcp

*      Buffer :  String
DoTelnetEmulation :
Boolean
Host :
String
TelnetEmulation :
String
TimeOut :
Integer
Close() :

GetLine() : String
GetText( len ) : String
Open() :
SendLine( Line ) :
SendText( text ) :
Wait() :
WaitFor( Substring ) : Boolean
WaitForDisconnect() :

 The full W3Sockets reference is located at:

 http://www.dimac.net/Products/FreeProducts/w3Sockets/Reference/Refstart.htm

You need to download this Dll and register it using SocketReg.exe included in a zip file.

Note: Readme said that you need to download winsock2 - ignore it.

 

Example of Use:

This function will connect to Unix/Linux box via Telnet, navigates to TestDirectory, executes “grep” command and returns “grep” results

Function w3Socket_Example()

Dim NavDirPrompt: NavDirPrompt = "TestDitectory]$"

Dim w3sock

Set w3sock = CreateObject("socket.tcp")

w3sock.timeout = 5000

w3sock.DoTelnetEmulation = True

w3sock.TelnetEmulation = "TTY"

w3sock.Host = “myserver:23"                             ' server name and port

w3sock.Close

w3sock.Open                                                     ' Open connection

w3sock.WaitFor "login:"                                      ' wait for Login prompt

w3sock.SendLine "myusername"                         ' send username

w3sock.WaitFor "Password:"                              ' wait for Password prompt

w3sock.SendLine "mypassword"                         ' send password

w3sock.WaitFor "$"                                                       ' wait for $ prompt

Print "Initial prompt: "& w3sock.Buffer                              ' retrieve data

w3sock.SendLine "cd /home/default/TestDitectory"           ' change directory

 

If w3sock.WaitFor(NavDirPrompt)<>True Then      ' wait for TestDirectory prompt

Reporter.ReportEvent micFail,"cd command”,"Prompt not found.”

            w3sock.Close    ' Close connection

            Set w3sock = Nothing   

            Exit Function

End If

 w3sock.SendLine "grep "Hello world" *.xml"  'grep for xml files with "Hello world"

w3sock.WaitFor NavDirPrompt                            ' wait for Stub Directory prompt

w3Socket_Example =w3Sock.Buffer                    ' return results

w3sock.Close    ' Close connection

Set w3sock = Nothing

End Function

 

You can also find some examples on Web:

http://www.tek-tips.com/viewthread.cfm?qid=938038&page=3

http://www.mediamonkey.com/forum/viewtopic.php?t=21124

 

[include_copyright.htm] [include_footer.htm]
footer image footer image