How to Test InfoPath Forms with TestComplete

Applies to TestComplete 15.47, last modified on January 20, 2023

This topic describes the techniques that you can use to automatically populate your Microsoft Office InfoPath forms. The following sections will explain how to configure your TestComplete project and access the InfoPath form’s fields in scripts.

General Notes

TestComplete enables you to fill InfoPath forms automatically. InfoPath forms are displayed using the WebBrowser control, which supports Microsoft Active Accessibility (MSAA). This means that forms and controls are exposed via the IAccessible interface. So, you can access individual elements in InfoPath forms using the TestComplete MSAA engine. For more information about testing applications that support Active Accessibility, see Using Microsoft Active Accessibility.

This functionality is provided by the Microsoft Active Accessibility Support plugin. This plugin is installed and enabled automatically.

Note: To use the plugin, you must have a license for the TestComplete Desktop module.
Configuring TestComplete Project

Before testing an InfoPath form you need to configure the TestComplete MSAA engine so that it provides access to form elements:

  • Open your TestComplete project.

  • Right-click the project node in the Project Explorer panel and select Edit | Properties from the context menu.

  • Select the Open Applications | MSAA options category.

  • Enable the “*” item in the List of accepted windows:

  • Select File | Save All from the TestComplete main menu or press Ctrl+S to save the changes made.

Exploring the Form in the Object Browser

Before recording or creating a new test, you need to make sure that TestComplete has access to windows and controls in the tested application. To do this, you can explore your InfoPath form in the Object Browser:

  • Launch InfoPath and open your form in it.

  • In TestComplete, switch to the Object Browser panel.

  • In the Object Tree, expand the node corresponding to the InfoPath process and its child nodes:

    InfoPath Form in the Object Browser

    The objects accessible via the IAccessible interface are shown with the icon. The Window("Internet Explorer_Server", "", 1) object highlighted on the above image corresponds to the form. The child objects of this object -- Table(0), Grouping("Issue Title") and others -- correspond to form elements and fields. For more information about object names, see Using Microsoft Active Accessibility for more information.

To determine which name a particular form element has in the Object Browser, you can use the TestComplete target glyph:

  • Click the  Display Object Spy button on the Tools toolbar.

  • Activate the InfoPath window.

  • In the Object Spy window, click the Drag the target to point to the object icon, drag its glyph () to the desired form element, wait until the red frame appears around the element and release the mouse button. TestComplete will display the element’s properties, methods and events in the Object Spy window. The element’s full name, which is used to address the object in scripts, is specified by the FullName property. You can right-click the value of the property in the Object Spy window, select Copy from the context menu and then paste the copied element name to the script in the Code Editor.

Example

The following example illustrates the automatic population of an InfoPath form. It uses the Issue Tracking (Simple) form which is shipped with InfoPath. Before running the script, you should open that form in InfoPath.

JavaScript, JScript

function Main()
{
  var p, form, tbl, obj;

  // Obtain the form
  p = Sys.Process("INFOPATH");
  form = p.Form("* - Microsoft Office InfoPath 2003").Window("XDocs HTMLSurface").Window("ATL*").Window("Internet Explorer_Server");

  tbl = form.Table(1);

  // Populate the "Issue Title" field
  obj = tbl.Cell(2).Grouping("Issue Title");
  obj.Click();
  obj.Keys("Automatic population of InfoPath forms");

  // Populate the "Opened By" field
  obj = tbl.Cell(3).Grouping("Opened By");
  obj.Click();
  obj.Keys("John Smith");

  // Populate the "Area Owner" field
  obj = tbl.Cell(6).Grouping("Area Owner");
  obj.Click();
  obj.Keys("Bobby Brown");

  // Populate the "Date Opened" field
  tbl.Cell(5).Grouping("Date Opened").Button(1).Click();
  p.Dialog("Date Picker").Window("SysMonthCal32").wDate = aqDateTime.Today();

  // Populate the "Due Date" field
  tbl.Cell(8).Grouping("Due Date").Button(1).Click();
  p.Dialog("Date Picker").Window("SysMonthCal32").wDate = aqDateTime.Today();

  // Populate the "Priority" field
  tbl.Cell(9).ComboBox("Priority").Button("Open").Click();
  p.Window("ComboLBox").ListItem("High").Click();

  // Populate the "Status" field
  tbl.Cell(11).ComboBox("Status").Button("Open").Click();
  p.Window("ComboLBox").ListItem("In Progress").Click();

  // Populate the "Description" field
  obj = form.Grouping("Description");
  obj.Click();
  obj.Keys("This form was populated by TestComplete.");

  // Insert the "Actions" section
  form.Grouping("Click here to insert the Actions section.").Click();

  tbl = form.Table("Contributor");

  // Populate the contributor name
  obj = tbl.Cell(4).Grouping("Name");
  obj.Click();
  obj.Keys("Bill Thornton");

  // Populate the contributor e-mail
  obj = tbl.Cell(5).Grouping("E-mail Address");
  obj.Click();
  obj.Keys("[email protected]");

  // Send the form via e-mail
  form.Button("Send as E-mail").Click();
}

Python

def Main():

  # Obtain the form
  p = Sys.Process("INFOPATH");
  form = p.Form("* - Microsoft Office InfoPath 2003").Window("XDocs HTMLSurface").Window("ATL*").Window("Internet Explorer_Server");

  tbl = form.Table(1);

  # Populate the "Issue Title" field
  obj = tbl.Cell(2).Grouping("Issue Title");
  obj.Click();
  obj.Keys("Automatic population of InfoPath forms"); 

  # Populate the "Opened By" field
  obj = tbl.Cell(3).Grouping("Opened By");
  obj.Click();
  obj.Keys("John Smith");

  # Populate the "Area Owner" field
  obj = tbl.Cell(6).Grouping("Area Owner");
  obj.Click();
  obj.Keys("Bobby Brown");

  # Populate the "Date Opened" field 
  tbl.Cell(5).Grouping("Date Opened").Button(1).Click();
  p.Dialog("Date Picker").Window("SysMonthCal32").wDate = aqDateTime.Today();

  # Populate the "Due Date" field
  tbl.Cell(8).Grouping("Due Date").Button(1).Click();
  p.Dialog("Date Picker").Window("SysMonthCal32").wDate = aqDateTime.Today();

  # Populate the "Priority" field
  tbl.Cell(9).ComboBox("Priority").Button("Open").Click();
  p.Window("ComboLBox").ListItem("High").Click();

  # Populate the "Status" field
  tbl.Cell(11).ComboBox("Status").Button("Open").Click();
  p.Window("ComboLBox").ListItem("In Progress").Click();

  # Populate the "Description" field
  obj = form.Grouping("Description");
  obj.Click();
  obj.Keys("This form was populated by TestComplete."); 

  # Insert the "Actions" section
  form.Grouping("Click here to insert the Actions section.").Click();

  tbl = form.Table("Contributor");

  # Populate the contributor name
  obj = tbl.Cell(4).Grouping("Name");
  obj.Click();
  obj.Keys("Bill Thornton");

  # Populate the contributor e-mail
  obj = tbl.Cell(5).Grouping("E-mail Address");
  obj.Click();
  obj.Keys("[email protected]"); 

  # Send the form via e-mail
  form.Button("Send as E-mail").Click();

VBScript

Sub Main
  Dim p, form, tbl, obj

  ' Obtain the form
  Set p = Sys.Process("INFOPATH")
  Set form = p.Form("* - Microsoft Office InfoPath 2003").Window("XDocs HTMLSurface").Window("ATL*").Window("Internet Explorer_Server")

  Set tbl = form.Table(1)

  ' Populate the "Issue Title" field
  Set obj = tbl.Cell(2).Grouping("Issue Title")
  obj.Click
  obj.Keys("Automatic population of InfoPath forms")

  ' Populate the "Opened By" field
  Set obj = tbl.Cell(3).Grouping("Opened By")
  obj.Click
  obj.Keys("John Smith")

  ' Populate the "Area Owner" field
  Set obj = tbl.Cell(6).Grouping("Area Owner")
  obj.Click
  obj.Keys("Bobby Brown")

  ' Populate the "Date Opened" field
  tbl.Cell(5).Grouping("Date Opened").Button(1).Click
  p.Dialog("Date Picker").Window("SysMonthCal32").wDate = aqDateTime.Today

  ' Populate the "Due Date" field
  tbl.Cell(8).Grouping("Due Date").Button(1).Click
  p.Dialog("Date Picker").Window("SysMonthCal32").wDate = aqDateTime.Today

  ' Populate the "Priority" field
  tbl.Cell(9).ComboBox("Priority").Button("Open").Click
  p.Window("ComboLBox").ListItem("High").Click

  ' Populate the "Status" field
  tbl.Cell(11).ComboBox("Status").Button("Open").Click
  p.Window("ComboLBox").ListItem("In Progress").Click

  ' Populate the "Description" field
  Set obj = form.Grouping("Description")
  obj.Click
  obj.Keys("This form was populated by TestComplete.")

  ' Insert the "Actions" section
  form.Grouping("Click here to insert the Actions section.").Click

  Set tbl = form.Table("Contributor")
  
  ' Populate the contributor name
  Set obj = tbl.Cell(4).Grouping("Name")
  obj.Click
  obj.Keys("Bill Thornton")

  ' Populate the contributor e-mail
  Set obj = tbl.Cell(5).Grouping("E-mail Address")
  obj.Click
  obj.Keys("[email protected]")

  ' Send the form via e-mail
  form.Button("Send as E-mail").Click
End Sub

DelphiScript

procedure Main;
var p, form, tbl, obj;
begin
  // Obtain the form
  p := Sys.Process('INFOPATH');
  form := p.Form('* - Microsoft Office InfoPath 2003').Window('XDocs HTMLSurface').Window('ATL*').Window('Internet Explorer_Server');

  tbl := form.Table(1);

  // Populate the 'Issue Title' field
  obj := tbl.Cell(2).Grouping('Issue Title');
  obj.Click;
  obj.Keys('Automatic population of InfoPath forms');

  // Populate the 'Opened By' field
  obj := tbl.Cell(3).Grouping('Opened By');
  obj.Click;
  obj.Keys('John Smith');

  // Populate the 'Area Owner' field
  obj := tbl.Cell(6).Grouping('Area Owner');
  obj.Click;
  obj.Keys('Bobby Brown');

  // Populate the 'Date Opened' field
  tbl.Cell(5).Grouping('Date Opened').Button(1).Click;
  p.Dialog('Date Picker').Window('SysMonthCal32').wDate := aqDateTime.Today;

  // Populate the 'Due Date' field
  tbl.Cell(8).Grouping('Due Date').Button(1).Click;
  p.Dialog('Date Picker').Window('SysMonthCal32').wDate := aqDateTime.Today;

  // Populate the 'Priority' field
  tbl.Cell(9).ComboBox('Priority').Button('Open').Click;
  p.Window('ComboLBox').ListItem('High').Click;

  // Populate the 'Status' field
  tbl.Cell(11).ComboBox('Status').Button('Open').Click;
  p.Window('ComboLBox').ListItem('In Progress').Click;

  // Populate the 'Description' field
  obj := form.Grouping('Description');
  obj.Click;
  obj.Keys('This form was populated by TestComplete.');

  // Insert the 'Actions' section
  form.Grouping('Click here to insert the Actions section.').Click;

  tbl := form.Table('Contributor');

  // Populate the contributor name
  obj := tbl.Cell(4).Grouping('Name');
  obj.Click;
  obj.Keys('Bill Thornton');

  // Populate the contributor e-mail
  obj := tbl.Cell(5).Grouping('E-mail Address');
  obj.Click;
  obj.Keys('[email protected]');

  // Send the form via e-mail
  form.Button('Send as E-mail').Click;
end;

C++Script, C#Script

function Main()
{
  var p, form, tbl, obj;

  // Obtain the form
  p = Sys["Process"]("INFOPATH");
  form = p["Form"]("* - Microsoft Office InfoPath 2003")["Window"]("XDocs HTMLSurface")["Window"]("ATL*")["Window"]("Internet Explorer_Server");

  tbl = form["Table"](1);

  // Populate the "Issue Title" field
  obj = tbl["Cell"](2)["Grouping"]("Issue Title");
  obj["Click"]();
  obj["Keys"]("Automatic population of InfoPath forms");

  // Populate the "Opened By" field
  obj = tbl["Cell"](3)["Grouping"]("Opened By");
  obj["Click"]();
  obj["Keys"]("John Smith");

  // Populate the "Area Owner" field
  obj = tbl["Cell"](6)["Grouping"]("Area Owner");
  obj["Click"]();
  obj["Keys"]("Bobby Brown");

  // Populate the "Date Opened" field
  tbl["Cell"](5)["Grouping"]("Date Opened")["Button"](1)["Click"]();
  p["Dialog"]("Date Picker")["Window"]("SysMonthCal32")["wDate"] = aqDateTime["Today"]();

  // Populate the "Due Date" field
  tbl["Cell"](8)["Grouping"]("Due Date")["Button"](1)["Click"]();
  p["Dialog"]("Date Picker")["Window"]("SysMonthCal32")["wDate"] = aqDateTime["Today"]();

  // Populate the "Priority" field
  tbl["Cell"](9)["ComboBox"]("Priority")["Button"]("Open")["Click"]();
  p["Window"]("ComboLBox")["ListItem"]("High")["Click"]();

  // Populate the "Status" field
  tbl.Cell(11).ComboBox("Status").Button("Open").Click();
  p["Window"]("ComboLBox")["ListItem"]("In Progress")["Click"]();

  // Populate the "Description" field
  obj = form["Grouping"]("Description");
  obj["Click"]();
  obj["Keys"]("This form was populated by TestComplete.");

  // Insert the "Actions" section
  form["Grouping"]("Click here to insert the Actions section.")["Click"]();

  tbl = form["Table"]("Contributor");

  // Populate the contributor name
  obj = tbl["Cell"](4)["Grouping"]("Name");
  obj["Click"]();
  obj["Keys"]("Bill Thornton");

  // Populate the contributor e-mail
  obj = tbl["Cell"](5)["Grouping"]("E-mail Address");
  obj["Click"]();
  obj["Keys"]("[email protected]");

  // Send the form via e-mail
  form["Button"]("Send as E-mail")["Click"]();
}

See Also

Testing Microsoft InfoPath Forms
Using Microsoft Active Accessibility
Addressing Objects in MSAA Open Applications
Supported Development Tools

Highlight search results