Using HTA in VBScript for Interactive Test Automation
Software testers often automate some mundane tasks which increases their efficiency and add value to the project. This automation can be done using any automation tools or writing your own scripts.

When a task is such that you need to access system information on windows, then one of the best candidate for automation is VBScript. It allows you to access the registry information and other system information easily. Using VBScript does not even require any application or framework for execution. The WSH (Windows Scripting Host) takes care of execution, which is installed by default on almost all Windows OS.

Though VBScript is very useful in many situations, it does not provide enough functionality to take inputs from the user. At the most, there are input boxes. Using these input boxes is not a good idea because of the possibilities of typographical errors in user-supplied data. What if we have functionality like check boxes or radio buttons so that user just selects what he wants but their input is restricted by the options we provide them.

Yes, We can have such Functionality from within VBScript also. This could be implemented by the help of HTML Applications which is also known as HTA.

Now Question is why do we need user input when we want a process to be automated. Automation means no user intervention…that’s right. Well I can think of a scenario, which I faced while automating ‘Install Testing’. We had an application, which integrates with various .NET IDEs like VS.NET 2003 and VS.NET 2005. During install testing, one of the main task is to check registry values. There were some registry values, which were common for both the IDE’s while others were specific to a particular IDE. In order to check these completely, we should have information on the IDE used for test so that specific registry entries can be tested. This could be achieved by following two mechanisms -

  • Have two separate scripts one for each type
  • Just check for the existence of any one of the IDE’s and perform accordingly.

These approaches had few drawbacks. In the first one I had one common code for both the scripts, which was redundant. Besides that, there might be a possibility that user might have both the IDE’s in that case both the scripts needed to be executed causing the common component checking twice which was unnecessary. In the second approach the existence of any one of the IDE’s could be tested only based upon the registry entries but how will you check the if the registry key itself is not present. In this case it would cause an error and script will not be executed.

The better approach is to give choose IDE for which testing needs to be performed. User can specify appropriate IDE and code will be executed according to the user input. This could be achieved by having check boxes as shown in figure below. Test execution will take place based on the choices made on this form.

How to Implement it?

Now comes the question of implementation. Well very simple yes it indeed is. Use HTA !!!!. HTA allow us to combine Internet Explorer and scripting code and, in turn, give our scripts a graphical user interface. There could be different mechanism to incorporate a graphical user interface into your scripts, but this is probably the easiest.

I think, best way to understand this is by looking at the code itself, so let’s start by giving you the code for HTA. Prior to that Create a file with a .htm extension and in between the <HTML> </HTML> tags you just write your VBScript code

<Script LANGUAGE="vbscript">;

Sub Button1_OnClick

blnselect = False

   strVS8 = ""

   strVS7 = ""

   If Document.InstallForm.option1.Checked Then

       blnselect = True

       strVS7 ==  Document.installForm.option1.Value

   End If

   If Document.InstallForm.option2.Checked Then

       blnselect = True

       strVS8 =  Document.installForm.option2.Value

   End If

   If Not blnSelect Thenn

       Alert "You must select VS type"

       Exit Sub

   End If

' Create the File System Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

  'You can use this file to store user input

  Set objFile = objFSO.CreateTextFile("C:\InstallInfo.txt")

  objFile.Close

  'Call your automation scripts based on the choices made here.

   call AutoInstall(strVS7,strVS8)

End Sub

</Script>

This code should be self explanatory. Best part of this code is its simplicity and the way it allows GUI enabled user input in your software test automation.

You could learn more about HTA from this link from Microsoft.

Recent Updates
Guerrilla Testing Tips
One CPU better than two
TG Tips For Automation?
Is It Really Done?
Exploratory Testing
Automated Testing
Model Based Testing
Live News
 
Read More
Accessibility API Testing Article Backword BigBang Blackbox Blog Bottomup Boundary CaseStudies Certification DefectReport DistanceTest Equivalence FitNesse Geeks Graybox Guerrilla Testing Tips GUI HTA Humor Hybrid Internationalization Installation Integration Is it done? JUnit Measurement Mercury Quality Centre News One CPU better than two Patent Performace Checklist Rational Test Suite Regression Requirement Verification Research Rational Functional Tester Security Selenium SilkTest System Testing Templates TestComplete Tools Testing Types Testing Tools In News Testing Terms In News Testometer Test Plan TG Tips For Automation Top Down Integration Trait UAT UI Testing CheckList Unit Testing Usability VMWare Web Application Security Web Application Testing Checklist Whitebox Testing
Disclaimer  |  Privacy Policy  |  g e e k AT T e s t i n g G e e k DOT c o m
© Copyright 2008, www.TestingGeek.com