Use TestComplete to Fill InfoPath 2003 Forms Automatically

With TestComplete, you can automatically populate InfoPath forms. TestComplete can access the internal elements of such forms in two ways:

  • It can work with them as with web pages , using the Web Testing plug-in.
  • It can access elements by using the MSAA Open Applications plug-in.

Testing InfoPath forms as web pages is not very convenient, since form controls such as text boxes, check boxes or radio buttons, change their names from one InfoPath run to another. You can find the needed element by analyzing its property values, but this approach slows down the test execution. It is much more efficient to work with InfoPath forms by using TestComplete's MSAA engine. Following is a description of the steps to do this.

To demonstrate how you can populate an InfoPath form automatically, we will use the Issue Tracking form. This is a sample form shipped with InfoPath 2003 which is a part of Microsoft Office 2003 Professional Edition.

To open the form in InfoPath:

  • Select File | Fill out a Form from InfoPath's menu. The Task Pane will appear.
  • Choose More Forms in the Task Pane.
  • In the ensuing Forms dialog, switch to the Sample Forms tab and select the Issue Tracking (Simple) form.

For TestComplete to be able to "see" objects located on InfoPath forms, the MSAA Open Applications plug-in must be installed and enabled in TestComplete. You can check whether the plug-in is installed in the Extensions dialog (from the File | Install Extensions menu):

Now it is time to customize the project in TestComplete. For this purpose, you need to enable MSAA support for all windows. To do this:

  • Switch to the Project Explorer panel.
  • Double-click on the project node in the panel. TestComplete will show the project editor in the Workspace panel.
  • Switch to the Properties page of the editor.
  • Select the MSAA Open Applications group on the left of the page. TestComplete will display the list of MSAA Open Applications properties on the right. This list contains windows class names, and their properties will be accessed via TestComplete's MSAA engine.
  • Select the check box for the asterisk (*) class name. This allows TestComplete to use MSAA to expose the methods and properties of any existing window:

Now TestComplete’s Object Browser displays InfoPath forms as MSAA objects named "pane":

Expand the node corresponding to the needed InfoPath form to make sure that the test engine has access to the form’s controls. These elements are accessed through MSAA.

To determine which fields to populate, you can use the Finder Tool:

  • Right-click somewhere within the Object Browser panel and select Object Properties from the context menu. This will display the Object Properties window.
  • Activate InfoPath.
  • Drag the Finder Tool () from the Object Properties window and point to the needed element of the InfoPath form. When you release the mouse button, TestComplete will display the element’s properties and name in the Object Properties window. You can copy the name to Code Editor and write script code that will work with the element.

The following JScript routine demonstrates how you can populate the sample Issue Tracking form:

[JScript]
function Main()
{
p = Sys.Process(“INFOPATH”);
w = p.Window(“Framework::CFrame”, “*”, 1).Window(“XDocs HTMLSurface”, “”, 1).Window(“ATL:304352C0″, “”, 1).Window(“Internet Explorer_Server”, “”, 1)
Page = w.MSAAObject(“pane”);
Object = Page.MSAAObject(“table”).MSAAObject(“cell_2″).MSAAObject(“gr_Issue_Title”);
Object.Click();
Object.Keys(“Automatic population of InfoPath 2003 forms”);
Object = Page.MSAAObject(“table”).MSAAObject(“cell_3″).MSAAObject(“gr_Opened_By”);
Object.Click();
Object.Keys(“John Gallaher”);
Object = Page.MSAAObject(“table”).MSAAObject(“cell_6″).MSAAObject(“gr_Area_Owner”);
Object.Click();
Object.Keys(“Bobby Brown”);
Object = Page.MSAAObject(“table”).MSAAObject(“cell_5″).MSAAObject(“gr_Date_Opened”);
Object.MSAAObject(“push_button”).Click(11, 2);
p.Window(“#32770″, “Date Picker”).Window(“SysMonthCal32″).wDate = Utilities.DateToStr(Utilities.Date());
Object = Page.MSAAObject(“table”).MSAAObject(“cell_8″).MSAAObject(“gr_Due_Date”);
Object.MSAAObject(“push_button”).Click(11, 2);
p.Window(“#32770″, “Date Picker”).Window(“SysMonthCal32″).wDate = Utilities.DateToStr(Utilities.Date() + 7);
Object = Page.MSAAObject(“table”).MSAAObject(“cell_9″).MSAAObject(“combo_box_Priority”);
Object.MSAAObject(“btn_Open”).Click();
p.Window(“ComboLBox”, “”, 1).MSAAObject(“list”).MSAAObject(“list_item_High”).Click(15, 7);
Object = Page.MSAAObject(“table”).MSAAObject(“cell_11″).MSAAObject(“combo_box_Status”);
Object.MSAAObject(“btn_Open”).Click();
p.Window(“ComboLBox”, “”, 1).MSAAObject(“list”).MSAAObject(“list_item_Completed”).Click(78, 7);
Object = Page.MSAAObject(“gr_Description”);
Object.Click();
Object.Keys(“This form was populated by TestComplete.”);
Object = Page.MSAAObject(“gr_Click_here_to_insert_the_Actions_section”);
Object.Click();
Object = Page.MSAAObject(“table_Contributor”).MSAAObject(“cell_4″).MSAAObject(“gr_Name”);
Object.Click();
Object.Keys(“Bill Thornton”);
Object = Page.MSAAObject(“table_Contributor”).MSAAObject(“cell_5″).MSAAObject(“gr_Email_Address”);
Object.Click();
Object.Keys(“Tester@YourDomain.com”);
Object = Page.MSAAObject(“btn_Send_as_Email”);
Object.Click();
}

As you can see, using TestComplete and its MSAA engine, you can create scripts that will automatically fill InfoPath forms with data.

 


Close

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox