Title: QTP: Not just for GUI anymore
1QTP Not just for GUI anymore
- Prepared by Igor Gershovich
- www.connectedtesting.com
2- The true beauty of QTP is that the only
limitation is your imagination and ability to
code in VBScript. - Ian Fraser
3Topics
- Web Services
- Telnet
- FTP
- XML
4Advantages using APIs
- Accessing non-GUI applications via API directly
- Increases test execution speed
- Reduces synchronization problems related to GUI
window like Telnet, DOS CMD, PuTTY, Exceed, etc. - Allows execute scripts on locked boxes
- No need for QTP add-ins
5Lets talk about Component Object Model (COM)
first
- COM is used by developers to create reusable
software components, link components together to
build applications, and take advantage of Windows
services. - The family of COM technologies includes
- COM
- Distributed COM (DCOM)
- ActiveX Controls.
6COM methods and properties
- COM properties and methods
- Properties dont take any arguments and can be
read/write - value object.property (read)
- object.property value (write)
- Methods are read only if they returns value
- value object.method() (returns value)
- Set RS Conn.Execute(Select From Tbl")
(returns object) - Conn.Close (returns no value)
- tdc.Login username", psw" (method with
parameters, returns no value)
7VBScript CreateObject function
- CreateObject function creates and returns a
reference to an Automation object - CreateObject(servername.typename , location)
- Example connecting to Quality Center (QC)
- Set tdc CreateObject ("TDApiOle80.TDConnection")
- tdc.InitConnectionEx sServerName 'Connect
- tdc.Login sUser, sPassword
- tdc.Connect sDomain, sProject
8COM objects in Registry editor
9Resources
- Microsoft COM Component Object Model
Technologies www.microsoft.com/com/default.mspx - COM for ASP ProgrammersBy Wayne Berry
http//www.15seconds.com/Issue/971214.htm
10File Transfer Protocol (FTP)
11Using WinInet API for FTP
- Windows WinINet.DLL enables applications to
interact with the following protocols - FTP
- HTTP
- Gopher
12WinInet FTP hierarchy
13FTP File download steps
- Open an FTP session with InternetOpen function.
The function returns a session handle. - Connect to the host by calling the
InternetConnect function using session handle. It
returns a connection handle. - Call the FtpGetFile function to get the file.
- Close the handles created in Steps 1 and 2, using
the InternetCloseHandle function
14FTP File download Script
15FTP File download is successful
16ActiveX components (COM) for FTP
- The are numerous ActiveX (COM) components for FTP
free and not free - by Chilkat Software www.chilkatsoft.com
- by Easewe Software www.easewe.com
- by X360 Software www.x360soft.com
- by Dart Communications www.dart.com
- etc.
17FTP Download file using Chilkats ActiveX
component (COM)
18Resources
- FTP your scripts by Dani Vainstein
- www.advancedqtp.com
- Creating an FTP Component in Visual Basic
- By Jeff Niblack www.15seconds.com
19Telnet to Unix/Linux using COM objects
20A 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. - Exceed worked decent enough, but it was a
complicated solution. I had to use "Capture to
File" feature and then parse the file. - After working with LoadRunner WinSock protocol
for Telnet interface I start looking for WinSock
(ActiveX) COM interface that can be used in QTP - The goal was to connect to Unix/Linux box
bypassing external GUI applications and execute
scripts on locked boxes. Another reason was that
QTP has problems with GetVisibleText method.
21ActiveX components (COM) for Telnet
- The are numerous ActiveX (COM) components for
Telnet free and not free - by Dimac Development www.dimac.net
- EasyCom 3.1 www.sharewareconnection.com/easycom.ht
m - by Dart Communications www.dart.com
- etc.
22Dimac w3sockets DLL methods and properties
- COM Object - socket.tcp
- Buffer StringDoTelnetEmulation
BooleanHost StringTelnetEmulation
StringTimeOut IntegerClose() GetLine()
StringGetText( len ) StringOpen()
SendLine( Line ) SendText( text ) Wait()
WaitFor( Substring ) BooleanWaitForDisconnect(
)
23Dimac W3Socket API installation
- You need to download W3Socket Dll to your
location and register it using SocketReg.exe
included in a zip file. - Note Readme said that you need to download
winsock2 also - ignore it. - The full W3Sockets reference is located
- http//www.dimac.net/Products/FreeProducts/w3Sock
ets/Reference/Refstart.htm
24Example for Unix/Linux
- The function on next slide
- connect to Unix/Linux box via Telnet
- navigates to TestDirectory
- executes grep command
- returns grep results
- You can also find more examples on Web
- http//www.tek-tips.com/viewthread.cfm?qid938038
page3 - http//www.mediamonkey.com/forum/viewtopic.php?t2
1124
25(No Transcript)
26W3Sockets API limitation
- This API has a problem with SendLine method when
sending over 80 characters.
27Web Services and XML
28Web Services architecture
29HP/Mercury Solutions for WebServices
- The HP Service Test software is a SOA testing
solution that simplifies and accelerates the
automated functional testing of SOA services. HP
Service Test Management module plugs into Quality
Center - QTP Web Services add-in
30Windows APIs for Web Services
- HP Service Test and QTP Web Services Add-in are
great solutions for comprehensive Web Services
testing. However, the lightweight solution using
Windows APIs works perfect in most cases.
31WinHTTP DLL
- Microsoft Windows HTTP Services (WinHTTP)
provides developers with a server-supported,
high-level interface to the HTTP/1.1 Internet
protocol. - WinHTTP WinHttpRequest COM object uses Winhttp.dll
32WinHttp.WinHttpRequest.5.1 Methods and Properties
- Methods of WinHttp
- Abort Aborts a WinHTTP Send method.
- GetAllResponseHeaders Retrieves all HTTP
response headers. - GetResponseHeader Retrieves the HTTP response
headers. - Open Opens an HTTP connection to an HTTP
resource. - Send Sends an HTTP request to an HTTP server.
- SetAutoLogonPolicy Sets the current Automatic
Logon Policy. - SetClientCertificate Selects a client
certificate to send to a Secure Hypertext
Transfer Protocol (HTTPS) server. - SetCredentials Sets credentials to be used with
an HTTP servereither an origin or a proxy
server. - SetProxy Sets proxy server information.
- SetRequestHeader Adds, changes, or deletes an
HTTP request header. - SetTimeouts Specifies, in milliseconds, the
individual time-out components of a send/receive
operation. - WaitForResponse Specifies the wait time, in
seconds, for an asynchronous Send method to
complete, with optional time-out value. - Properties of WinHttp
- Option Sets or retrieves a WinHTTP option value.
- ResponseBody Retrieves the response entity body
as an array of unsigned bytes. - ResponseStream Retrieves the response entity
body as an IStream. - ResponseText Retrieves the response entity body
as a string.
33ChangeMetricWeightUnit Web Service
on-linehttp//www.webservicex.net/convertMetricWe
ight.asmx
34ChangeMetricWeightUnit Web Service WSDL
35Using Http.WinHttpRequest.5.1 for WebServices
36WinHttp.WinHttpRequest.5.1 snippet
- ' WinHttp.WinHttpRequest.5.1 Object
- Set oWinHttpReq CreateObject("WinHttp.WinHttpReq
uest.5.1") - oWinHttpReq.Open "POST", sWebService_Url, False
- oWinHttpReq.setRequestHeader "Content-Type",
sContentType - oWinHttpReq.setRequestHeader "SOAPAction",
sSOAPAction - 'Send SOAP request
- oWinHttpReq.Send sSOAP_Request
- 'Get XML Response
- sXMLResponse oWinHttpReq.ResponseText
37SOAP XML Response
38Off topic Using WinHTTP for Web pages
39HTML Response
40Msxml2.DOMDocument
- A DOM for XML is an object model that exposes the
contents of an XML document - We use the XML DOM by creating an instance of an
XML parser - CreateObject(Msxml2.DOMDocument ) is the
method to create an instance of the Parser object
- Msxml2.DOMDocument COM object uses Msxml.dll
41XML Request file
42Using Msxml2.DOMDocument to load XML file
43Msxml2.DOMDocument Code Snippet
- 'lMsxml2.DOMDocument
- Set oInputXmlDoc CreateObject("Msxml2.DOMDocumen
t") - 'loadXML from file
- oInputXmlDoc.load("C\XML_Files_Demo\Weight_Conver
sion.xml") -
-
- 'Send SOAP request
- oWinHttpReq.Send oInputXmlDoc
44QTP XML Objects
- XMLUtil Object
- XMLAttribute Object
- XMLAttributesColl Object
- XMLData Object
- XMLElement Object
- XMLElementsColl Object
- XMLFile Object
- XMLItemColl Object
45Example Compare XML files using QTP objects
46Comparison results
47Resources
- MSDN http//msdn.microsoft.com/en-us/library/aa384
109.aspx - Stefan Thelenius about Software Testing
http//abouttesting.blogspot.com - QuickTest Professional Help file
48Igor Gershovich
- E-Mail igershovich_at_connectedtesting.com
- Phone 720-933-9395
- www.connectedtesting.com