Templates

> See the list of available templates

A template is what the recorder uses to format code. The files are located in the "Templates" directory with the main application and have an extension of ".trt" for Test Recorder Template.

The real power of a template is that it gives you the ability to wrap your own assemblies and code around a test, outputting the source code meaningful to you. We recommend that you add a new template rather than change an existing file so installing a new version will not overwrite your templates.

There are a few parts to the template:

  • TemplateName - name of the template as you want it to appear on the drop-down lists
  • CodeLanguage - language of the template, currently only "CSharp", "VBNet", and "PHP" are supported
  • CanRun - indicates whether this template should be shown in the "Run" list
  • CanCompile - indicates whether this template should be shown in the "Compile" list
  • FileExtension - extension for the save dialog box
  • ReferencedAssemblies - .NET assemblies necessary for compilation
  • code - formatted code page showing where the methods should go
    • TESTMETHODLIST is replaced by a list of the test methods
    • TESTMETHODCODE is replaced by the code, formatted using the Method format (below)
  • Method - format of a single test method
    • TESTNAME is replaced by the name you gave the test
    • TESTCODE is replaced by the recorded code
  • IncludedFiles - addition source files necessary for compilation
  • StartupApplication - application to start with recorder output as a parameter. An entry of "php.exe" here would start a process like "php.exe testcode.php"

Here is an example template:

<settings>
  <TemplateName>C# Console</TemplateName>
  <CodeLanguage>CSharp</CodeLanguage>
  <CanRun>1</CanRun>
  <CanCompile>1</CanCompile>
  <FileExtension>*.cs</FileExtension>
  <ReferencedAssemblies>%NETPATH%\System.dll
%NETPATH%\System.Data.dll
%NETPATH%\System.XML.dll
C:\Development\TestRecorder\bin\Debug\WatiN.Core.dll
</ReferencedAssemblies>
  <code>
using System;
using System.IO;
using System.Threading;
using WatiN.Core;
using WatiN.Core.DialogHandlers;
using WatiN.Core.Exceptions;
using WatiN.Core.Interfaces;
using WatiN.Core.Logging;

namespace TestSpace
{
	public class TestClass
	{
		[STAThread]
		static void Main()
		{
			TESTMETHODLIST
			System.Environment.Exit(0);
		}
	
		TESTMETHODCODE
	}
}
</code>
  <Method>
public static void TESTNAME ()
{
	TESTCODE
}
</Method>
  <IncludedFiles>
  </IncludedFiles>
  <StartupApplication>
  </StartupApplication>
</settings>

> See the list of available templates