How to Test FoxPro Applications with TestComplete

Applies to TestComplete 15.63, last modified on April 10, 2024

This topic explains how you can use TestComplete to test applications created in Microsoft Visual FoxPro v. 7.0 or later. The following sections contain instructions on setting set up a TestComplete project, explain how to explore the tested FoxPro application in the TestComplete Object Browser and provide an example of simulating user actions over a FoxPro application and retrieving data from it.

General Notes

TestComplete lets you perform functional testing of FoxPro applications. Since FoxPro applications support Microsoft Active Accessibility (MSAA), their forms and controls are exposed via the IAccessible interface. So, you can access the user interface elements in FoxPro applications 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.

To use the plugin, you must have a license for the TestComplete Desktop module.

Configuring TestComplete Project

Before testing a FoxPro application you need to configure the TestComplete MSAA engine so that it provides access to windows and controls in that application:

  • 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.

  • Add class names (the WndClass property value) of your FoxPro application’s forms to the List of accepted windows. This will make the TestComplete MSAA engine expose individual controls in these forms.

    To turn on MSAA support for all windows and controls, simply enable the “*” item:

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

Exploring the Application 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 FoxPro application. To do this, you can explore your application in the Object Browser:

  • Launch the tested FoxPro application.

  • Switch to the TestComplete Object Browser.

  • In the Object Tree, expand the node corresponding to your FoxPro application and its child nodes:

    The objects that implement the IAccessible interface are displayed with the icon. These objects are addressed by their type names -- Button("cmdFirst"), Dialog("Products"), Table("grdList") and so on. At that, the name in parentheses is the object name that is specified in the FoxPro application code. For more information on addressing objects exposed by the MSAA engine, see Addressing Objects in MSAA Open Applications.

To determine which name a particular window or control has in the Object Browser, you can use the TestComplete target glyph:

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

  • Activate the tested FoxPro application.

  • In the Object Spy window, click the Drag the target to point to the object icon, drag its glyph () to the desired application window or control, wait until the red frame appears around the object and release the mouse button. TestComplete will display the object’s properties, methods and events in the Object Spy window. The object’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 object name to the script in the Code Editor.

Example

The following example demonstrates how you can retrieve data from FoxPro applications. This example uses the Tastrade sample application that comes with Visual FoxPro and can be found in the <Visual FoxPro>\Samples\Tastrade\ folder. The application must be built into an executable file and must be running before you launch the test script.

This example also requires that the List of accepted windows in the project’s MSAA Options contains the tastrade* item and that the Work with MSAA objects in mode compatible with TestComplete 6 and earlier option in the same category is turned off.

JavaScript, JScript

function Main()
{
  var p, frmMain, dlgProducts, card, btnNext;

  // Obtain the Tasmanian Traders application's process and its main form
  p = Sys.Process("tastrade");
  frmMain = p.Form("Tasmanian Traders");

  // Open the Products list
  frmMain.MainMenu.Click("Administration|[8]");
  dlgProducts = frmMain.Panel("Tasmanian Traders").Dialog("Products");
  card = dlgProducts.TabList("pageframe1").PageTab("Data Entry");

  // Navigate through the products list and log information on each product
  btnNext = frmMain.Grouping(1).ToolBar("Navigation Tools").Button("cmdNext");
  while (btnNext.Enabled)
  {
    Log.AppendFolder(card.Edit(1).Text);
    Log.Message("English Name: "   + card.Edit(2).Text);
    Log.Message("Number in Unit: " + card.Edit(3).Text);
    Log.Message("Unit Price: "     + card.Edit(4).Text);
    Log.Message("Unit Cost: "      + card.Edit(6).Text);
    Log.Message("Discounted: "     + (card.CheckBox("Discontinued").State == cbChecked));
    Log.Message("Supplier: "       + GetSelectedItem(card.ComboBox("cboSupply_ID")));
    Log.Message("Category: "       + GetSelectedItem(card.ComboBox("cboCategory_ID")));
    Log.Message("Reorder Level: "  + card.Edit(5).Text);
    Log.Message("On Order: "       + card.Edit(7).Text);
    Log.Message("In Stock: "       + card.Edit(8).Text);
    Log.PopLogFolder();

    btnNext.DoDefaultAction();
  }

  // Close the Products list
  dlgProducts.Close();
}

// A helper function; returns the text of the selected combo box item
function GetSelectedItem(ComboBox)
{
  return ComboBox.Item(ComboBox.SelectedItem);
}

Python

def Main():
  # Obtain the Tasmanian Traders application's process and its main form
  p = Sys.Process("tastrade");
  frmMain = p.Form("Tasmanian Traders");

  # Open the Products list
  frmMain.MainMenu.Click("Administration|[8]");
  dlgProducts = frmMain.Panel("Tasmanian Traders").Dialog("Products");
  card = dlgProducts.TabList("pageframe1").PageTab("Data Entry");

  # Navigate through the products list and log information on each product
  btnNext = frmMain.Grouping(1).ToolBar("Navigation Tools").Button("cmdNext");
  while (btnNext.Enabled):
    Log.AppendFolder(card.Edit(1).Text);
    Log.Message("English Name: "   + card.Edit(2).Text);
    Log.Message("Number in Unit: " + card.Edit(3).Text);
    Log.Message("Unit Price: "     + card.Edit(4).Text);
    Log.Message("Unit Cost: "      + card.Edit(6).Text);
    Log.Message("Discounted: "     + (card.CheckBox("Discontinued").State == cbChecked));
    Log.Message("Supplier: "       + GetSelectedItem(card.ComboBox("cboSupply_ID")));
    Log.Message("Category: "       + GetSelectedItem(card.ComboBox("cboCategory_ID")));
    Log.Message("Reorder Level: "  + card.Edit(5).Text);
    Log.Message("On Order: "       + card.Edit(7).Text);
    Log.Message("In Stock: "       + card.Edit(8).Text);
    Log.PopLogFolder();

    btnNext.DoDefaultAction();

  # Close the Products list
  dlgProducts.Close();

# A helper function; returns the text of the selected combo box item
def GetSelectedItem(ComboBox):
  return ComboBox.Item(ComboBox.SelectedItem);

VBScript

Sub Main
  Dim p, frmMain, dlgProducts, card, btnNext

  ' Obtain the Tasmanian Traders application's process and its main form
  Set p = Sys.Process("tastrade")
  Set frmMain = p.Form("Tasmanian Traders")

  ' Open the Products list
  frmMain.MainMenu.Click("Administration|[8]")
  Set dlgProducts = frmMain.Panel("Tasmanian Traders").Dialog("Products")
  Set card = dlgProducts.TabList("pageframe1").PageTab("Data Entry")

  ' Navigate through the products list and log information on each product
  'btnNext = frmMain.Window("tastrade7c000000", "", 1).Panel("Navigation Tools").Button("cmdNext")
  Set btnNext = frmMain.Grouping(1).ToolBar("Navigation Tools").Button("cmdNext")
  While btnNext.Enabled
    Log.AppendFolder card.Edit(1).Text
    Log.Message("English Name: "   & card.Edit(2).Text)
    Log.Message("Number in Unit: " & card.Edit(3).Text)
    Log.Message("Unit Price: "     & card.Edit(4).Text)
    Log.Message("Unit Cost: "      & card.Edit(6).Text)
    Log.Message("Discounted: "     & (card.CheckBox("Discontinued").State = cbChecked))
    Log.Message("Supplier: "       & GetSelectedItem(card.ComboBox("cboSupply_ID")))
    Log.Message("Category: "       & GetSelectedItem(card.ComboBox("cboCategory_ID")))
    Log.Message("Reorder Level: "  & card.Edit(5).Text)
    Log.Message("On Order: "       & card.Edit(7).Text)
    Log.Message("In Stock: "       & card.Edit(8).Text)
    Log.PopLogFolder

    btnNext.DoDefaultAction
  Wend

  ' Close the Products list
  dlgProducts.Close
End Sub

' A helper function returns the text of the selected combo box item
Function GetSelectedItem(ComboBox)
  GetSelectedItem = ComboBox.Item(ComboBox.SelectedItem)
End Function

DelphiScript

// A helper function; returns the text of the selected combo box item
function GetSelectedItem(ComboBox);
begin
  Result := ComboBox.Item[ComboBox.SelectedItem];
end;

procedure Main;
var p, frmMain, dlgProducts, card, btnNext;
begin
  // Obtain the Tasmanian Traders application's process and its main form
  p := Sys.Process('tastrade');
  frmMain := p.Form('Tasmanian Traders');

  // Open the Products list
  frmMain.MainMenu.Click('Administration|[8]');
  dlgProducts := frmMain.Panel('Tasmanian Traders').Dialog('Products');
  card := dlgProducts.TabList('pageframe1').PageTab('Data Entry');

  // Navigate through the products list and log information on each product
  btnNext := frmMain.Grouping(1).ToolBar('Navigation Tools').Button('cmdNext');
  while btnNext.Enabled do
  begin
    Log.AppendFolder(card.Edit(1).Text);
    Log.Message('English Name: '   + card.Edit(2).Text);
    Log.Message('Number in Unit: ' + card.Edit(3).Text);
    Log.Message('Unit Price: '     + card.Edit(4).Text);
    Log.Message('Unit Cost: '      + card.Edit(6).Text);
    Log.Message('Discounted: '     + aqConvert.VarToStr(card.CheckBox('Discontinued').State = cbChecked));
    Log.Message('Supplier: '       + GetSelectedItem(card.ComboBox('cboSupply_ID')));
    Log.Message('Category: '       + GetSelectedItem(card.ComboBox('cboCategory_ID')));
    Log.Message('Reorder Level: '  + card.Edit(5).Text);
    Log.Message('On Order: '       + card.Edit(7).Text);
    Log.Message('In Stock: '       + card.Edit(8).Text);
    Log.PopLogFolder;

    btnNext.DoDefaultAction
  end;

  // Close the Products list
  dlgProducts.Close;
end;

C++Script, C#Script

function Main()
{
  var p, frmMain, dlgProducts, card, btnNext;

  // Obtain the Tasmanian Traders application's process and its main form
  p = Sys["Process"]("tastrade");
  frmMain = p["Form"]("Tasmanian Traders");

  // Open the Products list
  frmMain["MainMenu"]["Click"]("Administration|[8]");
  dlgProducts = frmMain["Panel"]("Tasmanian Traders")["Dialog"]("Products");
  card = dlgProducts["TabList"]("pageframe1")["PageTab"]("Data Entry");

  // Navigate through the products list and log information on each product
  btnNext = frmMain["Grouping"](1)["ToolBar"]("Navigation Tools")["Button"]("cmdNext");
  while (btnNext["Enabled"])
  {
    Log.AppendFolder(card.Edit(1).Text);
    Log["Message"]("English Name: "   + card["Edit"](2)["Text"]);
    Log["Message"]("Number in Unit: " + card["Edit"](3)["Text"]);
    Log["Message"]("Unit Price: "     + card["Edit"](4)["Text"]);
    Log["Message"]("Unit Cost: "      + card["Edit"](6)["Text"]);
    Log["Message"]("Discounted: "     + (card["CheckBox"]("Discontinued")["State"] == cbChecked));
    Log["Message"]("Supplier: "       + GetSelectedItem(card["ComboBox"]("cboSupply_ID")));
    Log["Message"]("Category: "       + GetSelectedItem(card["ComboBox"]("cboCategory_ID")));
    Log["Message"]("Reorder Level: "  + card["Edit"](5)["Text"]);
    Log["Message"]("On Order: "       + card["Edit"](7)["Text"]);
    Log["Message"]("In Stock: "       + card["Edit"](8)["Text"]);
    Log["PopLogFolder"]();

    btnNext["DoDefaultAction"]();
  }

  // Close the Products list
  dlgProducts["Close"]();
}

// A helper function; returns the text of the selected combo box item
function GetSelectedItem(ComboBox)
{
  return ComboBox["Item"](ComboBox["SelectedItem"]);
}

See Also

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

Highlight search results