Working With Ribbon Command Bars in Windows 7 Applications

Applies to TestComplete 15.62, last modified on March 19, 2024

Ribbon controls are a modern alternative to menu bars and toolbars and have application commands arranged and grouped in a tabular form on a single control bar.

TestComplete provides support for the most popular ribbon controls, including MFC, WPF, Developer Express and Windows Ribbon framework ribbons. The MFC, WPF and Developer Express ribbons are supported via the specific program objects attached to them. The Windows Ribbon framework ribbons are supported via the MSAA engine that allows TestComplete to get access to the tested applications’ windows and controls using the IAccessible interface.

This topic describes the specifics of working with the ribbons of the Windows Ribbon framework in the Windows 7 applications.

Configuring TestComplete Project

In order for TestComplete to recognize the tested ribbon application as open and available for testing, you need to do the following:

  • Install and enable the Microsoft Active Accessibility Support plugin. For information on how to install and enable plugins, see Installing Extensions.

  • Open the Project Properties editor and choose the Open Applications | MSAA item in the menu to access the MSAA Options window to change the MSAA engine settings.

  • Check the "*" item in the project’s MSAA Options window to specify the class names of the objects which are to be exposed by the Microsoft Active Accessibility Support plugin.

  • Check the Work with MSAA objects in mode compatible with TestComplete 6 and earlier option in the project’s MSAA Options window if you need to address the tested objects in the way they were addressed in the TestComplete 4 - 6 versions. Note, that the tests, created in this mode will not be played back correctly in the new mode, presented in TestComplete 7 and later.

For more information on changing MSAA engine settings, see Project Properties - MSAA Options.

Addressing the Ribbon Command Bars

All tested controls, windows and processes are treated like objects. Each object can have one parent and several children. That makes up the hierarchical structure when exploring them in the Object Browser. To explore the ribbon in the Object Browser, do the following:

  • Run your tested application that contains ribbons.
  • In the Object Tree expand the node that corresponds to the ribbon application until you reach the node of the ribbon command bar. You can continue to expand the ribbon node to reach its child elements: groups, tabs, buttons and so on.

The ribbon object and its child elements are addressed in tests by their full name, that is specified by the FullName property in the Object Browser.

An easy way to learn how a particular element can be addressed and to explore the element’s properties is to use the TestComplete target glyph. To learn how to use the target glyph, see Object Spy.

Addressing controls, windows and processes is hierarchical, to obtain the object that corresponds to the tested ribbon bar you need to obtain the process that holds the window with the desired ribbon bar. To obtain the process, use the Sys.Process or Sys.WaitProcess methods which return a process object. For information on how to obtain a process object, see Naming Processes. As the process object is obtained, you can obtain the application’s window object and control objects.

The tested ribbon bars and their tabs, groups and controls are addressed the same way the elements of the MSAA open applications are addressed. The way they are addressed depends on the compatibility mode:

  • If the Work with MSAA objects in mode compatible with TestComplete 6 and earlier option is disabled, TestComplete operates in the new mode and the elements are addressed with their accessibility roles and accessibility names. For more information on addressing MSAA objects in the new mode, see Addressing Objects in MSAA Open Applications.

    The following example demonstrates how to address ribbon bars in the new mode. It obtains the Ruler check box of the Show or hide group on the View tab of the ribbon in the Windows 7 MSPaint application.

    JavaScript, JScript

    function test()
    {
      var process, window, ribbon, view, show_or_hide, cb_rulers;
      // Obtain the MSPaint process
      process = Sys.Process("mspaint");

      // Obtain the MSPaint window
      window = process.Form("Untitled - Paint");

      // Obtain the ribbon
      ribbon = window.Panel("UIRibbonDockTop").Panel("Ribbon").Panel("Ribbon").Window("NUIPane","" ,1).PropertyPage("Ribbon").Pane("LowerRibbon");

      // Obtain the view tab
      view = ribbon.Client(0).PropertyPage("View");

      // Obtain the Show or hide group
      show_or_hide = view.Toolbar("Show or hide");

      // Obtain the Rulers check box
      cb_rulers = show_or_hide.CheckBox("Rulers");

    }

    Python

    def test():
      # Obtain the MSPaint process
      process = Sys.Process("mspaint")
    
      # Obtain the MSPaint window
      window = process.Form("Untitled - Paint")
    
      # Obtain the ribbon
      ribbon = window.Panel("UIRibbonDockTop").Panel("Ribbon").Panel("Ribbon").Window("NUIPane","" ,1).PropertyPage("Ribbon").Pane("LowerRibbon")
    
      # Obtain the view tab
      view = ribbon.Client(0).PropertyPage("View")
    
      # Obtain the Show or hide group
      show_or_hide = view.Toolbar("Show or hide")
    
      # Obtain the Rulers check box
      cb_rulers = show_or_hide.CheckBox("Rulers")

    VBScript

    Sub test
      Dim process, window, ribbon, view, show_or_hide, cb_rulers
      ' Obtain the MSPaint process
      Set process = Sys.Process("mspaint")

      ' Obtain the MSPaint window
      Set window = process.Form("Untitled - Paint")

      ' Obtain the ribbon
      Set ribbon = window.Panel("UIRibbonDockTop").Panel("Ribbon").Panel("Ribbon").Window("NUIPane","" ,1).PropertyPage("Ribbon").Pane("LowerRibbon")

      ' Obtain the view tab
      Set view = ribbon.Client(0).PropertyPage("View")

      ' Obtain the Show or hide group
      Set show_or_hide = view.Toolbar("Show or hide")

      ' Obtain the Rulers check box
      Set cb_rulers = show_or_hide.CheckBox("Rulers")

    End Sub

    DelphiScript

    procedure test();
    var process, window, ribbon, view, show_or_hide, cb_rulers;
    begin
      // Obtain the MSPaint process
      process := Sys.Process('mspaint');

      // Obtain the MSPaint window
      window := process.Form('Untitled - Paint');

      // Obtain the ribbon
      ribbon := window.Panel('UIRibbonDockTop').Panel('Ribbon').Panel('Ribbon').Window('NUIPane', '' ,1).PropertyPage('Ribbon').Pane('LowerRibbon');

      // Obtain the view tab
      view := ribbon.Client(0).PropertyPage('View');

      // Obtain the Show or hide group
      show_or_hide := view.Toolbar('Show or hide');

      // Obtain the Rulers check box
      cb_rulers := show_or_hide.CheckBox('Rulers');

    end;

    C++Script, C#Script

    function test()
    {
      var process, window, ribbon, view, show_or_hide, cb_rulers;
      // Obtain the MSPaint process
      process = Sys["Process"]("mspaint");

      // Obtain the MSPaint window
      window = process["Form"]("Untitled - Paint");

      // Obtain the ribbon
      ribbon = window["Panel"]("UIRibbonDockTop")["Panel"]("Ribbon")["Panel"]("Ribbon")["Window"]("NUIPane","" ,1)["PropertyPage"]("Ribbon")["Pane"]("LowerRibbon");

      // Obtain the view tab
      view = ribbon["Client"](0)["PropertyPage"]("View");

      // Obtain the Show or hide group
      show_or_hide = view["Toolbar"]("Show or hide");

      // Obtain the Rulers check box
      cb_rulers = show_or_hide["CheckBox"]("Rulers");

    }
  • If the Work with MSAA objects in mode compatible with TestComplete 6 and earlier option is enabled, TestComplete operates in the compatibility mode and the tested elements are addressed the way they were addressed in TestComplete 4 - 6 versions. To address the tested controls, use the MSAAObject and WaitMSAAObject methods.

    The MSAAObject and WaitMSAAObject methods refer to the object by its identifier, which consists of the prefix specifying object's accessibility role, accessibility name and object's index specifying it among other objects with the same prefix and accessibility name. For more information on addressing MSAA objects in the compatibility mode, see Addressing Objects in MSAA Open Applications.

    The following example demonstrates how to address ribbon bars in the compatibility mode. It obtains the Ruler check box of the Show or hide group on the View tab of the ribbon in the Windows 7 MSPaint application.

    JavaScript, JScript

    function test()
    {
      var process, window, ribbon, ribbon_area, view, show_or_hide, cb_rulers;
      // Obtain the MSPaint process
      process = Sys.Process("mspaint");

      // Obtain the MSPaint window
      window = process.Window("MSPaintApp", "Untitled - Paint", 1);

      // Obtain the ribbon handler
      ribbon = window.Window("UIRibbonCommandBarDock", "UIRibbonDockTop", 3).Window("UIRibbonCommandBar", "Ribbon", 1).Window("UIRibbonWorkPane", "Ribbon", 1).Window("NUIPane", "", 1).Window("NetHWND", "", 1);

      // Obtain the ribbon working area
      ribbon_area = ribbon.MSAAObject("property_page_Ribbon").MSAAObject("pane_Lower_Ribbon");

      // Obtain the view tab
      view = ribbon_area.MSAAObject("client").MSAAObject("property_page_View");

      // Obtain the Show or hide group
      show_or_hide = view.MSAAObject("tb_Show_or_hide");

      // Obtain the Rulers check box
      cb_rulers = show_or_hide.MSAAobject("cb_Rulers");

    }

    Python

    def test():
      # Obtain the MSPaint process
      process = Sys.Process("mspaint")
    
      # Obtain the MSPaint window
      window = process.Window("MSPaintApp", "Untitled - Paint", 1)
    
      # Obtain the ribbon handler
      ribbon = window.Window("UIRibbonCommandBarDock", "UIRibbonDockTop", 3).Window("UIRibbonCommandBar", "Ribbon", 1).Window("UIRibbonWorkPane", "Ribbon", 1).Window("NUIPane", "", 1).Window("NetHWND", "", 1)
    
      # Obtain the ribbon working area
      ribbon_area = ribbon.MSAAObject("property_page_Ribbon").MSAAObject("pane_Lower_Ribbon")
    
      # Obtain the view tab
      view = ribbon_area.MSAAObject("client").MSAAObject("property_page_View")
    
      # Obtain the Show or hide group
      show_or_hide = view.MSAAObject("tb_Show_or_hide")
    
      # Obtain the Rulers check box
      cb_rulers = show_or_hide.MSAAobject("cb_Rulers")

    VBScript

    Sub test
      Dim process, window, ribbon, ribbon_area, view, show_or_hide, cb_rulers
      ' Obtain the MSPaint process
      Set process = Sys.Process("mspaint")

      ' Obtain the MSPaint window
      Set window = process.Window("MSPaintApp", "Untitled - Paint", 1)

      ' Obtain the ribbon handler
      Set ribbon = window.Window("UIRibbonCommandBarDock", "UIRibbonDockTop", 3).Window("UIRibbonCommandBar", "Ribbon", 1).Window("UIRibbonWorkPane", "Ribbon", 1).Window("NUIPane", "", 1).Window("NetHWND", "", 1)

      ' Obtain the ribbon working area
      Set ribbon_area = ribbon.MSAAObject("property_page_Ribbon").MSAAObject("pane_Lower_Ribbon")

      ' Obtain the view tab
      Set view = ribbon_area.MSAAObject("client").MSAAObject("property_page_View")

      ' Obtain the Show or hide group
      Set show_or_hide = view.MSAAObject("tb_Show_or_hide")

      ' Obtain the Rulers check box
      Set cb_rulers = show_or_hide.MSAAobject("cb_Rulers")

    End Sub

    DelphiScript

    procedure test();
    var process, window, ribbon, ribbon_area, view, show_or_hide, cb_rulers;
    begin
      // Obtain the MSPaint process
      process := Sys.Process('mspaint');

      // Obtain the MSPaint window
      window := process.Window('MSPaintApp', 'Untitled - Paint', 1);

      // Obtain the ribbon handler
      ribbon := window.Window('UIRibbonCommandBarDock', 'UIRibbonDockTop', 3).Window('UIRibbonCommandBar', 'Ribbon', 1).Window('UIRibbonWorkPane', 'Ribbon', 1).Window('NUIPane', '', 1).Window('NetHWND', '', 1);

      // Obtain the ribbon working area
      ribbon_area := ribbon.MSAAObject('property_page_Ribbon').MSAAObject('pane_Lower_Ribbon');

      // Obtain the view tab
      view := ribbon_area.MSAAObject('client').MSAAObject('property_page_View');

      // Obtain the Show or hide group
      show_or_hide:= view.MSAAObject('tb_Show_or_hide');

      // Obtain the Rulers check box
      cb_rulers := show_or_hide.MSAAobject('cb_Rulers');

    end;

    C++Script, C#Script

    function test()
    {
      var process, window, ribbon, ribbon_area, view, show_or_hide, cb_rulers;
      // Obtain the MSPaint process
      process = Sys["Process"]("mspaint");

      // Obtain the MSPaint window
      window = process["Window"]("MSPaintApp", "Untitled - Paint", 1);

      // Obtain the ribbon handler
      ribbon = window["Window"]("UIRibbonCommandBarDock", "UIRibbonDockTop", 3)["Window"]("UIRibbonCommandBar", "Ribbon", 1)["Window"]("UIRibbonWorkPane", "Ribbon", 1)["Window"]("NUIPane", "", 1)["Window"]("NetHWND", "", 1);

      // Obtain the ribbon working area
      ribbon_area = ribbon["MSAAObject"]("property_page_Ribbon")["MSAAObject"]("pane_Lower_Ribbon");

      // Obtain the view tab
      view = ribbon_area["MSAAObject"]("client")["MSAAObject"]("property_page_View");

      // Obtain the Show or hide group
      show_or_hide = view["MSAAObject"]t("tb_Show_or_hide");

      // Obtain the Rulers check box
      cb_rulers = show_or_hide["MSAAobject"]("cb_Rulers");

    }

Properties and Methods Added to the Ribbon Command Bars

Ribbons are exposed as onscreen objects and obtain all properties and methods common for them. These properties and methods allow you to check the object state, simulate clicks and keystrokes over it. Depending on the mode enabled, ribbons obtain additional properties and methods appended by MSAA engine and TestComplete:

  • If the new mode is enabled, the ribbon controls get the properties and methods that are wrappers over IAccessibility interface members, and additional properties and methods appended by TestComplete that allow to perform various testing action over them such as checking for the control's state, getting its caption or index among its sibling controls and so on. For more information on properties and methods added to the MSAA objects, see MSAA Objects.

  • If the compatibility mode is enabled, the tested ribbons get the properties and methods of the IAccessibility interface. They are displayed in the MSAA group in the Object Browser. For more information on these properties and methods, see the description of the IAccessible interface in the MSDN library.

If the name of the property or method appended by the MSAA engine coincides with the name of the TestComplete standard property or method, the property or method appended by the engine is placed in the NativeMSAA namespace.

Working With the Ribbon Command Bars

The ribbon command bars exposed with the MSAA engine allow you to perform functional testing over them. You can test ribbon application the same way you would test any other application: check the ribbon components properties value, simulate user actions like mouse clicks or dragging over them and so on. You can record and play back tests, create tests from a scratch and create low-level procedures, use the checkpoints for testing.

The following example demonstrates how to simulate user actions over the ribbon command bar in the Windows 7 MSPaint application. It simulates the click on the Home tab of the ribbon, pick the pencil tool on the Tools group, selects the brush type in the brush drop-down list, sets the foreground color by selecting it from the palette. Note, that TestComplete does not recognize the separate color buttons of the palette and to select the color from it the Click method with the specified ClientX and ClientY parameters was used.

JavaScript, JScript

function Test()
{
  var process, window, ribbon, tabs, home_tab;
  var ribbon_area, tools_group, pencil;
  var brush_group, ddb, brush_list, brush;
  var color_group, color, palette;

  // Obtain the MSPaint process, MSPaint window and ribbon
  process = Sys.Process("mspaint");
  window = process.Form("Untitled - Paint");
  ribbon = window.Panel("UIRibbonDockTop").Panel("Ribbon").Panel("Ribbon").Window("NUIPane","" ,1).PropertyPage("Ribbon");

  // Obtain the Home tab and click it
  tabs = ribbon.TabList("RibbonTabs");
  home_tab = tabs.Client(0).PageTab("Home");
  home_tab.Click();

  // Obtain the Tools group on the Home tab and click the Pencil tool
  ribbon_area = ribbon.Pane("Lower Ribbon").Client(0).PropertyPage("Home");
  tools_group = ribbon_area.ToolBar("Tools");
  pencil = tools_group.Button("Pencil");
  pencil.Click();

  // Obtain the brush drop-down button on the Brush group and click it
  brush_group = ribbon_area.ToolBar(0).Grouping("Brushes");
  ddb = brush_group.GridDropDownButton("Brushes");
  ddb.Click();
  // Obtain the Natural Pencil in the brush drop-down list and click it
  brush_list = process.WaitWindow("Net UI Tool Window", "", 1).Panel("Brushes").List("Brushes");
  brush = brush_list.Client(0).Grouping(0).ListItem("Natural pencil");
  brush.Click();

  // Obtain the foreground color button on the Colors group and set its color by clicking on the palette
  color_group = ribbon_area.ToolBar("Colors");
  color = color_group.Button("Color 1");
  color.Click();
  palette = color_group.Grouping(0);
  palette.Click(8, 10);
}

Python

def Test():

  # Obtain the MSPaint process, MSPaint window and ribbon
  process = Sys.Process("mspaint")
  window = process.Form("Untitled - Paint")
  ribbon = window.Panel("UIRibbonDockTop").Panel("Ribbon").Panel("Ribbon").Window("NUIPane","" ,1).PropertyPage("Ribbon")

  # Obtain the Home tab and click it
  tabs = ribbon.TabList("RibbonTabs")
  home_tab = tabs.Client(0).PageTab("Home")
  home_tab.Click()

  # Obtain the Tools group on the Home tab and click the Pencil tool
  ribbon_area = ribbon.Pane("Lower Ribbon").Client(0).PropertyPage("Home")
  tools_group = ribbon_area.ToolBar("Tools")
  pencil = tools_group.Button("Pencil")
  pencil.Click()

  # Obtain the brush drop-down button on the Brush group and click it
  brush_group = ribbon_area.ToolBar(0).Grouping("Brushes")
  ddb = brush_group.GridDropDownButton("Brushes")
  ddb.Click()
  # Obtain the Natural Pencil in the brush drop-down list and click it
  brush_list = process.WaitWindow("Net UI Tool Window", "", 1).Panel("Brushes").List("Brushes")
  brush = brush_list.Client(0).Grouping(0).ListItem("Natural pencil")
  brush.Click()

  # Obtain the foreground color button on the Colors group and set its color by clicking on the palette
  color_group = ribbon_area.ToolBar("Colors")
  color = color_group.Button("Color 1")
  color.Click()
  palette = color_group.Grouping(0)
  palette.Click(8, 10)

VBScript

Sub Test

  Dim process, window, ribbon, tabs, home_tab
  Dim ribbon_area, tools_group, pencil
  Dim brush_group, ddb, brush_list, brush
  Dim color_group, color, palette

  ' Obtain the MSPaint process, MSPaint window and ribbon
  Set process = Sys.Process("mspaint")
  Set window = process.Form("Untitled - Paint")
  Set ribbon = window.Panel("UIRibbonDockTop").Panel("Ribbon").Panel("Ribbon").Window("NUIPane","" ,1).PropertyPage("Ribbon")

  ' Obtain the Home tab and click it
  Set tabs = ribbon.TabList("RibbonTabs")
  Set home_tab = tabs.Client(0).PageTab("Home")
  Call home_tab.Click()

  ' Obtain the Tools group on the Home tab and click the Pencil tool
  Set ribbon_area = ribbon.Pane("Lower Ribbon").Client(0).PropertyPage("Home")
  Set tools_group = ribbon_area.ToolBar("Tools")
  Set pencil = tools_group.Button("Pencil")
  Call pencil.Click()

  ' Obtain the brush drop-down button on the Brush group and click it
  Set brush_group = ribbon_area.ToolBar(0).Grouping("Brushes")
  Set ddb = brush_group.GridDropDownButton("Brushes")
  Call ddb.Click()
  ' Obtain the Natural Pencil in the brush drop-down list and click it
  Set brush_list = process.WaitWindow("Net UI Tool Window", "", 1).Panel("Brushes").List("Brushes")
  Set brush = brush_list.Client(0).Grouping(0).ListItem("Natural pencil")
  Call brush.Click()

  ' Obtain the foreground color button on the Colors group and set its color by clicking on the palette
  Set color_group = ribbon_area.ToolBar("Colors")
  Set color = color_group.Button("Color 1")
  Call color.Click()
  Set palette = color_group.Grouping(0)
  Call palette.Click(8, 10)
End Sub

DelphiScript

procedure Test();
var process, window, ribbon, tabs, home_tab;
var ribbon_area, tools_group, pencil;
var brush_group, ddb, brush_list, brush;
var color_group, color, palette;
begin

  // Obtain the MSPaint process, MSPaint window and ribbon
  process := Sys.Process('mspaint');
  window := process.Form('Untitled - Paint');
  ribbon := window.Panel('UIRibbonDockTop').Panel('Ribbon').Panel('Ribbon').Window('NUIPane', '' ,1).PropertyPage('Ribbon');

  // Obtain the Home tab and click it
  tabs := ribbon.TabList('RibbonTabs');
  home_tab := tabs.Client(0).PageTab('Home');
  home_tab.Click();

  // Obtain the Tools group on the Home tab and click the Pencil tool
  ribbon_area := ribbon.Pane('Lower Ribbon').Client(0).PropertyPage('Home');
  tools_group := ribbon_area.ToolBar('Tools');
  pencil := tools_group.Button('Pencil');
  pencil.Click();

  // Obtain the brush drop-down button on the Brush group and click it
  brush_group := ribbon_area.ToolBar(0).Grouping('Brushes');
  ddb := brush_group.GridDropDownButton('Brushes');
  ddb.Click();
  // Obtain the Natural Pencil in the brush drop-down list and click it
  brush_list := process.WaitWindow('Net UI Tool Window', '', 1).Panel('Brushes').List('Brushes');
  brush := brush_list.Client(0).Grouping(0).ListItem('Natural pencil');
  brush.Click();

  // Obtain the foreground color button on the Colors group and set its color by clicking on the palette
  color_group := ribbon_area.ToolBar('Colors');
  color := color_group.Button('Color 1');
  color.Click();
  palette := color_group.Grouping(0);
  palette.Click(8, 10);
end;

C++Script, C#Script

function Test()
{
  var process, window, ribbon, tabs, home_tab;
  var ribbon_area, tools_group, pencil;
  var brush_group, ddb, brush_list, brush;
  var color_group, color, palette;

  // Obtain the MSPaint process, MSPaint window and ribbon
  process = Sys["Process"]("mspaint");
  window = process["Form"]("Untitled - Paint");
  ribbon = window["Panel"]("UIRibbonDockTop")["Panel"]("Ribbon")["Panel"]("Ribbon")["Window"]("NUIPane","" ,1)["PropertyPage"]("Ribbon");

  // Obtain the Home tab and click it
  tabs = ribbon["TabList"]("RibbonTabs");
  home_tab = tabs["Client"](0)["PageTab"]("Home");
  home_tab["Click"]();

  // Obtain the Tools group on the Home tab and click the Pencil tool
  ribbon_area = ribbon["Pane"]("Lower Ribbon")["Client"](0)["PropertyPage"]("Home");
  tools_group = ribbon_area["ToolBar"]("Tools");
  pencil = tools_group["Button"]("Pencil");
  pencil["Click"]();

  // Obtain the brush drop-down button on the Brush group and click it
  brush_group = ribbon_area["ToolBar"](0)["Grouping"]("Brushes");
  ddb = brush_group["GridDropDownButton"]("Brushes");
  ddb["Click"]();
  // Obtain the Natural Pencil in the brush drop-down list and click it
  brush_list = process["WaitWindow"]("Net UI Tool Window", "", 1)["Panel"]("Brushes")["List"]("Brushes");
  brush = brush_list["Client"](0)["Grouping"](0)["ListItem"]("Natural pencil");
  brush["Click"]();

  // Obtain the foreground color button on the Colors group and set its color by clicking on the palette
  color_group = ribbon_area["ToolBar"]("Colors");
  color = color_group["Button"]("Color 1");
  color["Click"]();
  palette = color_group["Grouping"](0);
  palette["Click"](8, 10);
}

Known Limitations

  • The test engine cannot recognize the ribbon enhanced tooltips and contextual tab sets.

  • The Quick Access Toolbar is recognized only when it's displayed below the ribbon bar.

  • The keyword tests recorded for the ribbon Application menu can be played back incorrectly and result in failure.

See Also

Object-Specific Tasks
Exploring Applications
Using Microsoft Active Accessibility

Highlight search results