Share this page

# Java code samples (.NET SDK)

In this topic:

## Select menu items in a list

This example demonstrates how to use the Menu test object, which enables several methods to access and select menu items.

This example selects a menu item, which changes the background color of the main DesktopPane of the AUT.

     public void JavaMenuTest()
    {
    	// Launch the AUT, an executable JAR.
    	var appProcess = new Process { StartInfo = { FileName = @"C:\SwingSet2.jar" } };
    	appProcess.Start();

    	// Create a Description for the main AUT window. Set the title for the Description object.
    	var window = Desktop.Describe<IWindow>(new WindowDescription
    	{
    		Title = "SwingSet2"
    	});

    	// Create a description for the AUT DesktopPane as an IUiObject.
    	// Set the NativeClass value for the Description object.
    	var desktopPane = window.Describe<IUiObject>(new UiObjectDescription
    	{
    		NativeClass = "javax.swing.JDesktopPane"
    	});

    	// Check the item is not selected. If selected, the background color is Aqua, 0x80c0c0.
    	Verify.AreNotEqual("80c0c0", desktopPane.BackgroundColor, "Verify Item is Not Selected", "Verify the item is not selected by checking the item's background color.");

    	// Create a description for the top level menu item: Themes.
    	var themesMenu = window.Describe<IMenu>(new MenuDescription
    	{
    		Label = "Themes"
    	});

    	// Check that the themesMenu has the expected six submenus.
    	// A submenu is a collection of menu items located directly under the parent menu. The check is not recursive.
    	Verify.AreEqual(9, themesMenu.SubMenus.Count, "Verify Themes Submenu", "Verify that the themes sub menu has 9 items.");

    	// *** Different ways to select a sub menu ***

    	// 1) The SelectSubMenu method accepts the path of the submenu.
    	//    The elements of a multi-level path are separated with a semicolon (;).
    	themesMenu.SelectSubMenu("Aqua");

    	// 2) The GetSubMenu method returns a menu test object representing the submenu item. The item is then selected.
    	themesMenu.GetSubMenu("Aqua").Select();

    	// 3) The SubMenus property returns a menu test object representing the submenu item. The item is then selected.
    	//     This applies only when selecting a direct child of the parent menu.
    	var aquaSubMenu = themesMenu.SubMenus[4];
    	Verify.AreEqual("Aqua", aquaSubMenu.Label, "Verify Correct Menu", "Verify we have selected the correct menu from the SubMenus collection."); // to verify we have selected the correct menu from the SubMenus collection.
    	aquaSubMenu.Select();

    	// Check that the item is selected. If selected, the background color is Aqua.
    	Verify.AreEqual("80c0c0", desktopPane.BackgroundColor, "Verify Item is Selected", "Verify the item is selected by checking the item's background color.");
    }

Back to top

## Wait until a state is reached and click a link

This demonstrates how to use the:

- WaitUntil method to wait for the AUT to reach a certain state
- ClickLink method of the Editor test object

    public void EditorFunctionality_BasicTesting()
    {
    	// Launch the AUT, an executable JAR.
    	var appProcess = new Process { StartInfo = { FileName = @"C:\SwingSet2.jar" } };
    	appProcess.Start();

    	// Create a description object for main window of the AUT.
    	var window = Desktop.Describe<IWindow>(new WindowDescription
    	{
    		Title = "SwingSet2"
    	});

    	// This AUT contains a dynamically loaded toolbar that starts to load when the AUT is launched.

    	// Create a description for the Toolbar.
    	var toolBar = window.Describe<IToolBar>(new ToolBarDescription
    	{
    		NativeClass = "SwingSet2$ToggleButtonToolBar"
    	});

    	// There are 16 buttons in the toolbar. Use the WaitUntil method to wait until all 16 buttons are loaded.
    	// This ensures that any button we press was loaded. If not loaded, the test fails.
    	toolBar.WaitUntil(tb => (tb.Buttons.Count == 16));

    	// Clicking the JEditorPane button displays the editor test object.
    	toolBar.GetButton("JEditorPane").Press();

    	// Create a description for the Editor test object.
    	var editor = window.Describe<IEditor>(new EditorDescription
    	{
    		NativeClass = "javax.swing.JEditorPane"
    	});

    	// The editor in this AUT is a read only HTML text with links.
    	Verify.IsTrue(editor.IsReadOnly, "Verify Editor is Read Only", "Verify that the editor in this AUT is read only.");

    	// Click the link to king.html.
    	editor.ClickLink("king.html");

    	// Verify that the correct page loaded by checking the text.
    	// The text is long, so check only the first segment of the text.
    	const string expectedTextPrefix = "   \n \n \nDo here most humbly lay this small Present";
    	var editorText = editor.Text;
    	Verify.IsTrue(editorText.StartsWith(expectedTextPrefix), "Verify Correct Page Was Loaded", "Verify that the correct page was loaded by checking the page's first segment of text.");
    }

Back to top

https://admhelp.microfocus.com Functional Testing for Developers 8942
Tips to improve your search results... OpenText™ Functional Testing for Developers Help Center OpenText™ Functional Testing for Developers Help 25.2 All View Local Help Center View Online Help Center Version: