Processing Test Data from XML Files

December 31, 2008
Revised: May 30, 2014

Synopsis

This concept was initially conceived as a SilkTest script which I was experimenting with while trying to find an alternative to storing test data in spreadsheets. I later implemented two variations of the algorithm in VBScript.


Introduction

It’s a common practice to maintain test data in spreadsheets. For the purpose of maintaining test data, each row in a spreadsheet represents an individual test case. If the application being tested has a large number of data fields, for the most part, Excel spreadsheets are much easier to manipulate than Word tables. However, spreadsheets can become cumbersome if you are dealing with a large number of columns. Most people are averse to horizontal scrolling back and forth through a sheet to find the data they are looking for. In addition, when entering numerical data in Excel you have to remember to set the cell Category as Text.

This paper presents a solution that can be implemented using tools that every computer user has—an editor and a Web browser. Even though this technique was developed to eliminate using spreadsheets for inputting data into an automated test tool, such as SilkTest, it can be used to maintain test data for manual test cases as well. Both 4Test and VBScript implementations are presented.

Note: while Windows Notepad can be used to view and edit XML files, I recommend using a good programmer’s editor that provides syntax highlighting. For example, the editor in Microsoft Visual Studio. Other commercially available editors that I personally recommend and use are UltraEdit by IDM Computer Solutions, Inc. and VEDIT by Greenview Data, Inc. If you prefer free software, then I recommend Notepad++ and jEdit.

Excel to XML Conversion

The process of converting spreadsheet data to an XML formatted text file is fairly straightforward. Table 1 below is an example of a customer’s name and address in spreadsheet format.

Table 1
Name Address City State Zip
Joe Green 25 East Colonial Drive Orlando FL 32825

Row(1) in Table 1 contains the column headings which represent the data fields in the application. Each of the remaining Rows(2–n) contain the customer data which will be used for the test procedure. The steps necessary to convert the data to XML format is to first create a tag for each column heading along with the corresponding cell as the tag’s value. For example:

The next step is to create a tag to group the customer name and address information. The convention for naming this tag is to use the application’s window or page name. For this example, let’s use “Customer.” The XML now looks like the following:

Finally, a declarations line is added at the beginning of the file so that errors are not generated when the file is opened. Comments can also be added.

 4Test Solution

I began work on this XML parsing script during the 2002–2003 timeframe and then completed it in 2008. The 4Test script is presented in the normalized or code format using braces (“{“, “}”) and semicolons (“;”) as opposed to the Visual 4Test format which displays the code folding notation: [ ], [-] and [+].

Table 2 lists the files associated with the 4Test implementation.

Table 2
File Description
XML.t XML Parsing Script
shipping_address.xml Data Input File
xml_res.txt Results File

 Script Features

  • Leading spaces are trimmed from the input line
  • Opening and closing tags are validated
  • &lt, &gt, &amp, &apos, and &quot are translated

Script Limitations

  • Leading tab characters are not trimmed from the input line
  • Embedded windows are not handled
  • Only one test case per XML file is assumed

Function Invocation

VBScript Solution

I recently decided to re-implement the XML parsing function in VBScript since I’m now working primarily with HP QuickTest Pro. I took the approach of re-designing the algorithm instead of attempting a line for line translation. I also made the assumption that the tester would use a Web browser to validate the XML, so tag checking code was omitted. In addition, since I’m no longer working within the SilkTest framework mentioned previously, I was able to eliminate some function calls from the original version. Finally, where the SilkTest implementation uses local variables, the VBScript version uses mostly global variables.

I’m providing two different versions of the parsing subroutine. ParseXML_1 was my first attempt. This version parses the input string by successively reducing the size of the string after each tag or tag value is found. That is, each search always starts at the beginning of the string. ParseXML_2 was my second attempt at the subroutine. This version parses the input string by examining each character individually. Also, unlike the 4Test implementation, the code to read the input file is outside the subroutine.

Note: If you are running Windows 7 or Vista, you may get the following very annoying error message when trying to run the script: There is no script engine for file extension ‘.vbs’. A registry fix is required to resolve the problem. I have a script available for Download. Remember to back up your registry before running the update.

 

 

 

 

 

 

 

Click here for reuse options!
Copyright 2014 Gerard Sczepura

Leave a Reply

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