Using an XML File to Load Test Parameters to an ATEasy Program

Knowledge Base Article # Q200241

Read Prior Article Read Next Article
Summary The article show how to read XML file that has encoded ATEasy test parameters and to modify the ATEasy Program's tests requirements dynamically.
  
Login to rate article
This example reads a XML file and stores the new parameters in the program test objects. The parameters which will be updated by the XML file are grouped into a Test node and the specific test which will be updated is identified by an ID attribute.  Each child node that is grouped within a Test node can be used to update a Test properties.  For instance:

<Test ID="PS1">
   <min>3</min>
   <max>3.6</max>
   <tag>3.3</tag>
</Test>


This XML Test node, when used with the XMLTestParameters.drv, will update the the Test whose ID properties equals "PS1".  It will update the Test's Min, Max and Tag properties with 3, 3.6, and 3.3 respectively.

Using the Example

The code to read the XML file and apply the parameters reside in the XMLTestParameters.drv driver.  The XMLTestParameters driver utilizes the XML.drv, a general purpose XML file reader.  This driver uses the functionality of Microsoft's System.Xml namespace, documentation here.  Functionality includes the ability to create, open, read and write XML files.  Additional methods and properties can be added by the user to expand the driver functionality.

To use the driver:
1. Insert the XMLTestParameters.drv to your system
2. Insert the XML.drv to your system
3. To load the parameters to your program use the following code:

if not XMLTESTS ReadTestParametersFile(GetDir(0)+"\\TestParameters.xml")
    abort
endif


This code typically resides in Program.OnInit() event.

Example Code

The  XMLTestParameters.drv export one command / procedure that is used to load the parameters:

--------------------------------------------------------------------------------
Procedure ReadTestParametersFile(sFile): Bool
--------------------------------------------------------------------------------
sFile: Val String
sProperty: String
sTest: String
s: String
enNodeType: Long
{
  ! open the test properties file
  try
    XML Reader Open(sFile)
  catch else
    MsgBox("Unable to open XML File: '"+sFile+"'")
    return False
  endtry

  !Iterate through the open XML file
  while (XML Reader Next())
    enNodeType=XML Reader Get NodeType()
    select enNodeType
    Case XmlNodeType.Element
      ! Keep track of the element that the user is on.
      s = XML Reader Get Name()
      if s="Test"
        !If the element is a new test, store the ID attribute
        sTest=XML Reader Get Attribute("ID")
      else
        !Store the name of the element as a property
        sProperty=s
      endif
    Case XmlNodeType.Text
      !If the node is text, it is a value that should be updated
      !use the Test ID and property name to decide where to assign the value
      select sProperty
      case "min"
        Program.Tests(sTest).Min=Val(XML Reader Get Value())
      case "max"
        Program.Tests(sTest).Max=Val(XML Reader Get Value())
      case "tag"
        Program.Tests(sTest).Tag=XML Reader Get Value()
      case else
        !More customization can be here
      endselect
    EndSelect
  EndWhile
  XML Reader Close()
  return True
}


Where to Go From Here

This example only allows you to update a Min/Max type tests properties.  If the ability to update the properties of another test type were needed, the code within the sProperty case statement would need to be updated.  To add the ability to set the ValuePlus and ValueMinus property of a Tolerance type test, the user would need to add a 'case "valueplus"' and a 'case "valueminus"'.

Download the Example and the XML drivers:  DownloadClick Here
Article Date 2/7/2013 , 4/16/2014
Keywords ATEasy, XML, Properties, Parameters


Login to rate article

Read Prior Article Read Next Article