10 Objects to be Hand On!

This post is just short manual or reminder on generic system-available objects in Windows environments.
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:

  1. “Scripting.FileSystemObject” – all operations over files and folders
  2. “Shell.Application” – Standard shell Win object for running basic system operations
  3. “WScript.Shell” – This is more prefearable object then listed above
  4. “VBScript.RegExp” – Regular expressions object
  5. “Scripting.Dictionary” – Dictionary object type. Basically, this structure is used in VBS or to create arguments of this type for subsequent calls
  6. “WScript.Network” – Implements basic interfaces for networking
  7. “InternetExplorer.Application” – can be used to manipulate on IE and can be candidate to replace testing tool functionality, clicking and so on
  8. “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
  9. “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)
  10. “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.

Simple WMI usage for local querying:
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:

  1. Unified and safe access to objects, methods and properties (Registry class is better to implement using Singleton)
  2. Your IDE/TDE will see instructions and Intellisense will work!
  3. You will follow proper coding standards, you will avoid duplications and improper use. As result, you get back quality and code consistency
  4. More long-term advantages…

Let’s perfect scripting skills, MSDN will help in that – don’t forget to utilize Scripting Technet space where you can enjoy examples and practices, follow at http://technet.microsoft.com/en-us/library/cc498722.aspx

You are not authorized to see this part
Please, insert a valid App ID, otherwise your plugin won't work correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *


4 × two =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Plugin from the creators of Brindes Personalizados :: More at Plulz Wordpress Plugins