QTP - Not just for GUI anymore


Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

QTP - Not just for GUI anymore

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