navigation
 Thursday, February 28, 2008

The dotNet object in TestComplete (requires the .NET Classes Support plug-in) allows you to access .Net objects in your TestComplete script code.  For example, if I needed a Hash table I could do the following:

[JScript]

function dotNetSample()
{
  var dictionary;
  dictionary = dotNET.System_Collections.Hashtable.zctor();
  dictionary.Add("test","TestComplete");
  Log.Message(dictionary.Item("test"))
}
Or if I needed to write a Textfile:
function dotNetWriteTextFile()
{
  var sw;
  sw = dotNET.System_IO.StreamWriter.zctor_5("TestFile.txt");
  try
  {
  sw.Write_10("This is the ");
  sw.WriteLine_11("header for the file.");
  sw.WriteLine_11("-------------------");
  // Arbitrary objects can also be written to the file.
  sw.Write_10("The date is: ");
  sw.WriteLine_9(dotNET.System.DateTime.Now);
  }
  finally
  {
  sw.Close();
  }
}

Notice that some of the methods have an underscore and a number.  This is because the script languages supported by
TestComplete do not support method overloading, so TestComplete creates methods with a number for each overload.