10 So let's go and begin for instantination. In order to unify and isolate external objects management, I prefer either Singleton or Factory simple patterns (http://at4qa.blogspot.com/2010/01/20-essential-design-patterns-for.html). They will take care about objects lifecycle management:
- object creation if not exist in current context or reference returning if an instance lives (singleton)
- new instance creation (if factory)
- dynamic object update when needed
- object life finalization destroy and freeding memory as it actual for languages w/o garbage collection or with with weak one
- protected/private use
- logging and exception handling
In VBScript new instance of object can be created as:
Set Obj= CreateObject(ObjStrSemantic),
e.g Set Obj= CreateObject("MSXML.DOMDocument")
I will address objects by mean of string variable ObjStrSemantic down the road:
- "Scripting.FileSystemObject" - all operations over files and folders
- "Shell.Application" - Standard shell Win object for running basic system operations
- "WScript.Shell" - This is more prefearable object then listed above
- "VBScript.RegExp" - Regular expressions object
- "Scripting.Dictionary" - Dictionary object type. Basically, this structure is used in VBS or to create arguments of this type for subsequent calls
- "WScript.Network" - Implements basic interfaces for networking
- "InternetExplorer.Application" - can be used to manipulate on IE and can be candidate to replace testing tool functionality, clicking and so on
- "ADODB.Connection" and "ADODB.Recordset" - basic object for obtaining connection with source through ADODB connector and object of Recordset type serving to store retrieved data from ADODB in memory
- "MSXML.DOMDocument"("MSXML2.DOMDocument.3.0") - essential object to process XML through standard DOM methods, XPath. Why you may need it? You can develop Web testing code omitting testing vendors tools which make the same but giving own custom interfaces. Desing data (DDT) or keyword-driven(KDT) testing framework leveraging power of XML. Check out my post about XML possible use (http://at4qa.blogspot.com/2010/01/tools-xml-orm-for-efficient.html)
- "WbemScripting.SWbemLocator" - Windows Management Instrumentation (WMI) is really powerful tool to manipulate over various system operations (hardware and software). I think WMI covers all system capabilities including all related to administration, providing remote connection and querying using SQL-like language WQL and unified API for administration automation. The link http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en leads on download page of WMI code editor tool from MS - indeed, this tool is simple and handy.
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & HostName & "\root\cimv2")
Set colOperatingSystems = oWMIService.ExecQuery ("Select * from Win32_OperatingSystem") 'Querying OS info
Simple WMI usage for remoting:
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(Host, "root\CIMV2", UID, Pwd, "MS_409")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk",,48)
Working on test automation or infrastracture framework, it's better to design wrappers over methods, properties and events of appropriate objects and put these wrappers into appropriate custom Registry classes which will represent appropriate object interfaces. What you will get from that? At least:
- Unified and safe access to objects, methods and properties (Registry class is better to implement using Singleton)
- Your IDE/TDE will see instructions and Intellisense will work!
- You will follow proper coding standards, you will avoid duplications and improper use. As result, you get back quality and code consistency
- More long-term advantages...


2 comments:
Thank you for posting this information in this blog. The article which you have posted is highly informative.and I would be glad if you could post more article in this blog for future reference.
Software Testing Tools
I'm glad you like it. More interesting things will come regularly
Also everyone feel free to point out what would be nice to be highlighted in this blog: technologies, tools, methods, thoughts...
Post a Comment