# Test object description examples

The examples below show some simple test code with programmatic descriptions for Web and Windows objects.

In this topic:

## C#

Web Link Object

This example initializes testBrowser as a Chrome browser and navigates to the HPE web site.

It then creates a keyboardLink test object that will be recognized within the launched testBrowser.

    IBrowser testBrowser = BrowserFactory.Launch(BrowserType.Chrome);

    testBrowser.Navigate("http://www.hpe.com");

    var keyboardLink = testBrowser.Describe<ILink>(new LinkDescription { TagName = "A", InnerText = "Computer Keyboards" });

Standard Windows Calculator Objects

This example creates the calcApp Window test object.

Inside the calcApp hierarchy, it creates a Button test object to represent the number 1 button in the calculator, and a Static test object to represent the main calculator display box.

    var calcApp = Desktop.Describe<IWindow>(new WindowDescription { WindowClassRegExp = "CalcFrame", WindowTitleRegExp = "Calculator" });
    var calcButton1 = calcApp.Describe<IButton>(new ButtonDescription { WindowId = 131, NativeClass = "Button" });
    var calcDisplay = calcApp.Describe<IStatic>(new StaticDescription { WindowId = 150, NativeClass = "Static" });

Back to top

## Java

Web Link Object

This example initializes browser as a Chrome browser and navigates to the New Tours web site.

It then creates a link test object to represent the Business Travel link on the web page.

    Browser browser = BrowserFactory.launch(BrowserType.CHROME);
    browser.navigate("http://newtours.demoaut.com/");
    browser.describe(Link.class, new LinkDescription.Builder()
    .tagName("A").innerText("Business Travel @ About.com").build());

Standard Windows Notepad Objects

This example creates the notepadWindow test object.

Inside the notepadWindow hierarchy, it creates a Menu test object to represent the main NotePad menu.

Inside the notepadMenu hierarchy, it uses the buildMenuPath method to create a test object for the Format > Font sub-menu command and to perform the select operation on that object.

Finally, it creates a notepadFontDialog object as a child of the main notepadWindow and the fontsComboBox object as a child of the dialog box.

    Window notepadWindow = Desktop.describe(Window.class, new  WindowDescription.Builder().windowClassRegExp("Notepad").windowTitleRegExp(" Notepad").build());
    Menu notepadMenu = notepadWindow.describe(Menu.class, new  MenuDescription(MenuType.MENU));

    // Build the "Format"-->"Font" menu item

    String path = notepadMenu.buildMenuPath("Format", 2);

    // Open the "Font" dialog by selecting "Format"-->"Font" in the menu
    MenuItem menuItem = notepadMenu.getItem(path);

    notepadMenu.select(menuItem);

    Dialog notepadFontDialog = notepadWindow.describe(Dialog.class, new  DialogDescription.Builder().windowTitleRegExp("Font").build());
    ComboBox fontsComboBox = notepadFontDialog.describe(ComboBox.class, new  ComboBoxDescription.Builder().attachedText("&Font:").nativeClass("ComboBox").build());

Back to top

## JavaScript

Web List Object

This example navigates to a Web site in an already initialized and launched browser.

It creates the list object as a Web list box child object. After selecting an additional item in the list, it verifies information about the state of the list. Then it deselects the item and again verifies the new state of the list.

    	    browser.navigate("http://mySite.com");

            var list = browser.$(new Web.ListBox({
                name: "what-to-wear"
            }));

            list.select("Cape", 4);

            list.selectedItems()
                .then(function (items) {
                    expect.equal(items.length, 2);
                    expect.strictEqual(items[0], "Socks");
                    expect.strictEqual(items[1], "Cape");
                });

            list.deselect(4, "Cape");

            list.selectedItems()
                .then(function (items) {
                    expect.equal(items.length, 1);
                })

Back to top

See also:

- Code samples - .NET
- Code samples - Java
- Code samples - JavaScript
- Setting up and working with the JavaScript SDK

https://admhelp.microfocus.com LeanFT 8942
Tips to improve your search results...TOC Lean Functional Testing Help Center LeanFT Help Center 14.50 - 14.53 All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version:(Undefined variable: _rscC_Basic_Variables.FloatingTocShow)