QTP - Not Just for GUI Anymore
-
Upload
yvijayasekhar5032 -
Category
Documents
-
view
127 -
download
9
Transcript of QTP - Not Just for GUI Anymore
![Page 1: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/1.jpg)
QTP: Not just for GUI anymore
Prepared by: Igor Gershovich
www.connectedtesting.com
![Page 2: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/2.jpg)
The true beauty of QTP is that the only limitation is your imagination and ability to code in VBScript.
Ian Fraser
![Page 3: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/3.jpg)
Topics
Web Services Telnet FTP XML
![Page 4: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/4.jpg)
Advantages 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
![Page 5: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/5.jpg)
Let’s 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.
![Page 6: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/6.jpg)
COM methods and properties
COM properties and methods Properties don’t 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)
![Page 7: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/7.jpg)
VBScript CreateObject functionCreateObject 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 'Connecttdc.Login sUser, sPasswordtdc.Connect sDomain, sProject
![Page 8: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/8.jpg)
COM objects in Registry editor
![Page 9: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/9.jpg)
Resources:
Microsoft “COM: Component Object Model Technologies” www.microsoft.com/com/default.mspx
“COM for ASP Programmers”By Wayne Berry http://www.15seconds.com/Issue/971214.htm
![Page 10: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/10.jpg)
File Transfer Protocol (FTP)
![Page 11: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/11.jpg)
Using WinInet API for FTP
Windows WinINet.DLL enables applications to interact with the following protocols: FTP HTTP Gopher
![Page 12: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/12.jpg)
WinInet FTP hierarchy
![Page 13: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/13.jpg)
FTP: File download steps
1. Open an FTP session with InternetOpen function. The function returns a session handle.
2. Connect to the host by calling the InternetConnect function using session handle. It returns a connection handle.
3. Call the FtpGetFile function to get the file.
4. Close the handles created in Steps 1 and 2, using the InternetCloseHandle function
![Page 14: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/14.jpg)
FTP: File download Script
![Page 15: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/15.jpg)
FTP: File download is successful
![Page 16: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/16.jpg)
ActiveX 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.
![Page 17: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/17.jpg)
FTP: Download file using Chilkat’s ActiveX component (COM)
![Page 18: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/18.jpg)
Resources:
“FTP your scripts” by Dani Vainstein
www.advancedqtp.com “Creating an FTP Component in Visual
Basic”
By Jeff Niblack www.15seconds.com
![Page 19: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/19.jpg)
Telnet to Unix/Linux using COM objects
![Page 20: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/20.jpg)
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.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 QTPThe 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.
![Page 21: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/21.jpg)
ActiveX 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.htm by Dart Communications www.dart.com etc.
![Page 22: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/22.jpg)
Dimac w3sockets DLL methods and properties COM Object - socket.tcp Buffer : String
DoTelnetEmulation : BooleanHost : StringTelnetEmulation : StringTimeOut : IntegerClose() : GetLine() : StringGetText( len ) : StringOpen() : SendLine( Line ) : SendText( text ) : Wait() : WaitFor( Substring ) : BooleanWaitForDisconnect() :
![Page 23: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/23.jpg)
Dimac 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/w3Sockets/Reference/Refstart.htm
![Page 24: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/24.jpg)
Example 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?qid=938038&page=3 http://www.mediamonkey.com/forum/viewtopic.php?t=21124
![Page 25: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/25.jpg)
![Page 26: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/26.jpg)
W3Sockets API limitation
This API has a problem with SendLine method when sending over 80 characters.
![Page 27: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/27.jpg)
Web Services and XML
![Page 28: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/28.jpg)
Web Services architecture
![Page 29: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/29.jpg)
HP/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
![Page 30: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/30.jpg)
Windows 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.
![Page 31: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/31.jpg)
WinHTTP 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
![Page 32: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/32.jpg)
WinHttp.WinHttpRequest.5.1 Methods and PropertiesMethods 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 server—either 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. Status: Retrieves the HTTP status code from the last response. StatusText: Retrieves HTTP status text.
![Page 33: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/33.jpg)
ChangeMetricWeightUnit Web Service on-linehttp://www.webservicex.net/convertMetricWeight.asmx
![Page 34: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/34.jpg)
ChangeMetricWeightUnit Web Service WSDL
![Page 35: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/35.jpg)
Using Http.WinHttpRequest.5.1 for WebServices
![Page 36: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/36.jpg)
WinHttp.WinHttpRequest.5.1 snippet' WinHttp.WinHttpRequest.5.1 ObjectSet oWinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")oWinHttpReq.Open "POST", sWebService_Url, FalseoWinHttpReq.setRequestHeader "Content-Type", sContentTypeoWinHttpReq.setRequestHeader "SOAPAction", sSOAPAction
'Send SOAP requestoWinHttpReq.Send sSOAP_Request
'Get XML ResponsesXMLResponse = oWinHttpReq.ResponseText
![Page 37: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/37.jpg)
SOAP XML Response
![Page 38: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/38.jpg)
Off topic: Using WinHTTP for Web pages
![Page 39: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/39.jpg)
HTML Response
![Page 40: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/40.jpg)
Msxml2.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
![Page 41: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/41.jpg)
XML Request file
![Page 42: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/42.jpg)
Using Msxml2.DOMDocument to load XML file
![Page 43: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/43.jpg)
Msxml2.DOMDocument Code Snippet'lMsxml2.DOMDocument
Set oInputXmlDoc = CreateObject("Msxml2.DOMDocument")
'loadXML from file
oInputXmlDoc.load("C:\XML_Files_Demo\Weight_Conversion.xml")
…
…
'Send SOAP request
oWinHttpReq.Send oInputXmlDoc
![Page 44: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/44.jpg)
QTP XML Objects
XMLUtil Object XMLAttribute Object XMLAttributesColl Object XMLData Object XMLElement Object XMLElementsColl Object XMLFile Object XMLItemColl Object
![Page 45: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/45.jpg)
Example: Compare XML files using QTP objects
![Page 46: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/46.jpg)
Comparison results
![Page 47: QTP - Not Just for GUI Anymore](https://reader033.fdocuments.us/reader033/viewer/2022051411/5470e16fb4af9f256f8b4592/html5/thumbnails/47.jpg)
Resources:
MSDN http://msdn.microsoft.com/en-us/library/aa384109.aspx
Stefan Thelenius about Software Testing http://abouttesting.blogspot.com
QuickTest Professional Help file