Skip to main content

Advanced Techniques

Working with multiple windows

Some applications use multiple windows, either simultaneously or in sequence, as part of a loading or login flow.

# Switch to window by title

Once I switch to window with title "Login" in java app

# Switch to window which contains a specific element

Once I switch to window with object "cssSelector:*[text = 'Welcome to the application!']" in java app

Working with tables

Sometimes when working with tables you need to interact with a particular column, but you do not know which row ahead of time.

Consider the following situation. Your application presents the results of a search in a table, but the ordering of items is not guaranteed. One column of the table contains item ids, and you know ahead of time which item id you are looking for. Another column of the table contains a checkbox for selecting the item. You need to find the row by item id, and then click the checkbox in that row.

You can use a loop to get the row number into a variable, and then use that to click the checkbox.

# This example assumes a table where the 1st column is 'Item ID' and the 5th column is a checkbox we need to click

Given I assign 1 to variable "row_index"
Given I assign "false" to variable "found_row"
While $found_row is equal to "false"

# assume we want the row where 'Item ID' column is 'item_001'

Given I assign variable "row_locator" by combining "cssSelector:table::mnth-cell(" $row_index ", 1)[text = 'item_001']"
If I see object $row_locator in java app
Then I assign "true" to variable "found_row"
EndIf
EndWhile

# Now if we found the row, the index will be in the $row_index variable

Given I assign variable "checkbox_locator" by combining
"cssSelector:table::mnth-cell(" $row_index ", 5)"

When I click object $checkbox_locator in java app

Extracting text from UI elements

Sometimes you need to extract text from a table, list, or other element and insert that text into another element like a search field or form.

Cycle provides a step to copy all text from an element into a variable.

# Get an item number from a table cell

When I copy text inside object "cssSelector:table::mnth-cell(2,3)" in java app to variable "item_number"

# Use the item number in a search field

And I type $item_number in object "cssSelector:text-field[toolTipText = 'Search for item']" in java app

Cycle also supports extracting part of the text of an element using regular expressions.

# In this example, there is a label with the user's full name. We can extract that to separate variables for first and last name.

Given I assign text matching regex "(\w+) (\w+)" in object "cssSelector:label[toolTipText = 'Full Name']" in java app to variables "first_name,last_name"

And I type $first_name in object "cssSelector:*[toolTipText = 'Enter first name']" in java app

And I type $last_name in object "cssSelector:*[toolTipText = 'Enter last name']" in java app

Working with element focus

Sometimes an element may be hard to locate uniquely, but can be easy to put into focus via other means.

Cycle provides steps for interacting directly with the element which currently has the keyboard focus.

# Type some text into the focused element

And I type "myuser" in focused object in java app

# Type some text into the focused element and then press enter

And I enter "myuser" in focused object in java app

# You can clear the focused element, which can be helpful for ensuring a clean slate in often used elements, such as search fields

And I clear focused object in java app