Share this page

# Tips and tricks - General

The following tips and tricks are relevant for all AUT technologies.

In this topic:

## Return a test object collection to match a description

You can retrieve a collection of test objects that match a description.

Programming language | Instructions
--- | ---
C# and Java | Use the <TestObject>.FindChildren method.
JavaScript | Use .$$ syntax. For details, see Setting up and working with the JavaScript SDK

Back to top

## Use a regular expression for a property value

Depending on your programming language, use the following syntax to use regular expressions in a property.

Programming language | Syntax
--- | ---
C# | `IDProp = As.RegExp(@"RegExpValue")`
Java | `.idProp(new RegExpProperty("RegExpValue"))`
JavaScript | `idProp:/RegExpValue/`

For more details, see Regular expression guidelines.

Back to top

## Use SDK exceptions to debug your test

Information from SDK exceptions can be helpful when debugging your test.

For example:

Exception | Description
--- | ---
ReplayObjectNotFoundException | Thrown during a test run when no object matches the test object description.
ReplayObjectNotUniqueException | Thrown during a test run when more than one object matches the test object description.

Back to top

## Pause a spying operation

While spying on objects with the Object Identification Center (OIC), you may want to temporarily pause the spying operation, for example to use your mouse to bring another application into focus.

Press and hold Ctrl on your keyboard to pause the spy while performing other mouse operations.

Back to top

## Type text and special characters

Type text and special characters, such as ALT, F1 keys, Esc, or CapsLock into fields in your application.

Use the SendKeys method with constants from the Keys class.

Back to top

## Capture text from an application using OCR

To capture text from within a specific object in your application, use the GetVisibleText and GetTextLocations methods, available for all test objects.

You can also capture an image of any part of your application and then use the GetText and LocateText methods of the ImageUtils class to capture text from within a supplied image.

For more details, see Tips & tricks - OCR methods (Windows only) and the .NET SDK Reference, Java SDK Reference, or JavaScript SDK Reference.

Back to top

## DataGridView: Use a native object to mouse-click a table cell (C#)

When working with tables based on the class System.Windows.Forms.DataGridView, you can use a native object to mouse-click a table cell in two ways:

Note: To check which class your table is based on, check the table test object's FullType property.

Create a ClickCell method that accepts a table and cell as parameters:

Create a method that performs a mouse-click:

Copy code

    public static void ClickCell(ITable table, int columnIndex, int rowIndex)
    {
        dynamic cellRectangle = table.NativeObject.GetCellDisplayRectangle(columnIndex, rowIndex, true);
        Point cellPoint = new Point(cellRectangle.X, cellRectangle.Y);

        ClickArgs clickArgs = new ClickArgs
        {
            Button = MouseButton.Left,
            Location = new Location(Position.TopLeft, cellPoint)
        };

        table.Click(clickArgs);
    }

Use the ClickCell method providing the relevant table and cell:

Copy code

    ClickCell(myTableObject,columnIndex,rowIndex);

Add a ClickCell method to the Table test object:

Create an extension method to define mouse-click functionality

Copy code

    static class TableExtensions
    {
        public static void ClickCell(this ITable table, int columnIndex, int rowIndex)
        {
            dynamic cellRectangle = table.NativeObject.GetCellDisplayRectangle(columnIndex, rowIndex, true);
            Point cellPoint = new Point(cellRectangle.X, cellRectangle.Y);

            ClickArgs clickArgs = new ClickArgs
            {
                Button = MouseButton.Left,
                Location = new Location(Position.TopLeft, cellPoint)
            };

            table.Click(clickArgs);
        }
    }

Use the table's extension method:

Copy code

    myTableObject.ClickCell(columnIndex,rowIndex);

Back to top

## Use a dynamic browser type

To run the same web test on different browsers, you can provide the browser type to the test as a parameter.

For example, create a test.runsettings file with the following content, and place it in the same folder as the test:

Copy code

    <RunSettings>
       <TestRunParameters>
          <Parameter name="Browser" value="chrome" /> <!-- "firefox", "edge" -->
       </TestRunParameters>
    </RunSettings>

In your MSTest, retrieve the parameter, using `context.Properties["Browser"]`:

Copy code

    private static BrowserType _browserType;

    [ClassInitialize]
    public static void ClassInitialize(TestContext context)
    {
    string browser = context.Properties["Browser"]?.ToString() ??
    throw new Exception(@"Test context property ""Browser"" is not set.");
    if (Enum.TryParse(browser, true, out _browserType))
    {
    GlobalSetup(context);
    }
    else
    {
    throw new Exception(@$"Unsupported browser type: [{browser}].");
    }
    }

    [TestMethod]
    public void Test1()
    {
          IBrowser browser = BrowserFactory.Launch(_browserType);
          browser.Navigate("https://www.advantageonlineshopping.com");
          browser.Sync();
    . . .
    browser.Close();
    }

In the dotnet command you use to run the test, add the options that passes runtime parameters to the test: `--settings test.runsettings`

For more details on using runtime parameters, see the online Microsoft documentation.

See also:

- Tips & tricks - Web testing
- Tips and tricks - SAP GUI
- Tips & tricks - OCR methods (Windows only)

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: