DEV Community

hiclab
hiclab

Posted on

How to check if an item exists in a tree or table in RCPTT

When working with trees and tables, have you ever faced a case where you want to check whether a given item is visible?

In RCPTT, an item is obtained using the get-item ECL command. If you try to get an item that does not exist then an error is returned saying that the item could not be found and the test case fails immediately.

In general, invoking get-item can be enough to verify that an given item exists but what to do if we want to continue the execution of the test case to perform other verifications even if the item does not exist.

We create a procedure to handle the case where an item is not found so the error can be captured using try and catch commands as follows:

proc itemExists [val parent -input] [val path] {
    try {
        $parent | get-item $path
        bool true
    } -catch {
        bool false
    }
}

As you can see, it is simple and lets us have control over the execution of any command that can fail. In this case, the procedure returns true if the item exists or false if an error occurs when getting the item.

Example of general usage

get-preferences-menu | click
with [get-window Preferences] {
    get-tree | itemExists Help | verify-true
    get-tree | itemExists HelpNotFound | verify-false
}

Example of specific usage with conditions

if [itemExists Help] {
    // item is found, do more verifications
} -else {
    // item is not found, do more verifications if you want
}

Top comments (0)