choose

Class: matlab.uitest.TestCase
Package: matlab.uitest

Perform choose gesture on UI component

Syntax

choose(testcase,comp,option)
choose(testcase,compNoOpts)

Description

choose(testcase,comp,option) performs a choose gesture on the specified item on the UI component comp.

choose(testcase,compNoOpts) performs a choose gesture on a UI component that does not require additional information, such as a tab or a tree node. For example, use this syntax to choose a specific tab, but use the previous syntax to choose a particular tab from a tab group.

Input Arguments

expand all

Instance of the test case, specified as a matlab.uitest.TestCase object.

Component to choose during test, specified as a UI component object that supports a choose gesture. Components that support choose gestures include check boxes, knobs, switches, and drop-down lists.

Supported ComponentTypical Creation Function
Button

uiradiobutton

uitogglebutton

Check Box

uicheckbox

Drop Down

uidropdown

List Box

uilistbox

Slider

uislider

State Buttonuibutton('state')
Button Group

uibuttongroup

Tab Group

uitabgroup

Knob, Discrete Knob

uiknob

Switch, Rocker Switch, Toggle Switch

uiswitch

Data Types: matlab.ui.container.ButtonGroup | matlab.ui.container.TabGroup | matlab.ui.control.CheckBox | matlab.ui.control.DiscreteKnob | matlab.ui.control.DropDown | matlab.ui.control.Knob | matlab.ui.control.ListBox | matlab.ui.control.RadioButton | matlab.ui.control.RockerSwitch | matlab.ui.control.Slider | matlab.ui.control.StateButton | matlab.ui.control.Switch | matlab.ui.control.ToggleButton | matlab.ui.control.ToggleSwitch

Item to choose in the component. The data type of option depends on the type of component under test. For example, if comp is a switch, option is a text or numeric value from the Items property of the switch. If comp is a check box, option is a logical value.

When a component has an Items property, option can be the value of an element in Items or an index to an element in Items. For example, for a default discrete knob, you can choose 'Medium' using a value for option that is either 'Medium' or 3.

Component to choose, specified as a UI component object that supports a choose gesture and does not require additional information. Components that support choose gestures include tabs and tree nodes.

Supported ComponentTypical Creation Function
Tab

uitab

Tree Node

uitreenode

Data Types: matlab.ui.container.Tab | matlab.ui.container.TreeNode

Examples

expand all

Create a discrete knob.

knob = uiknob('discrete');

Create an interactive test case and choose the 'High' knob value. An animated blue dot performs the programmatic choose gesture.

tc = matlab.uitest.TestCase.forInteractiveUse;
tc.choose(knob,'High')

View the value of the Items property on the knob.

knob.Items
ans =

  1×4 cell array

    {'Off'}    {'Low'}    {'Medium'}    {'High'}

Choose the 'Low' knob value by index. The knob moves from 'High' to 'Low'.

tc.choose(knob,2)

Create a list box and enable multiple node selection.

listbox = uilistbox('Multiselect','on')
listbox = 

  ListBox (Item 1) with properties:

              Value: {'Item 1'}
              Items: {'Item 1'  'Item 2'  'Item 3'  'Item 4'}
          ItemsData: []
        Multiselect: 'on'
    ValueChangedFcn: ''
           Position: [100 100 100 74]

  Show all properties

Create an interactive test case and choose items 1 through 3.

tc = matlab.uitest.TestCase.forInteractiveUse;
tc.choose(listbox,1:3)

Choose items 1 and 3 using the values of the Items property.

tc.choose(listbox,{'Item 1','Item 3'})

Create a slider.

s = uislider;

Create an interactive test case and verify that the value of the slider button is 0.

tc = matlab.uitest.TestCase.forInteractiveUse;
tc.verifyEqual(s.Value,0)
Verification passed.

Choose a new slider value and verify the slider value changes. Since the framework mimics a user manipulating the component to an arbitrarily precisioned value, it is a best practice to use a tolerance to compare the actual and expected slider values.

expVal = 42;
tc.choose(s,expVal)
tc.verifyEqual(s.Value,expVal,'AbsTol',0.1)
Verification passed.

Create a figure with two tabs.

fig = uifigure;
group = uitabgroup(fig);
tab1 = uitab(group,'Title','Tab #1');
tab2 = uitab(group,'Title','Tab #2');

Create an interactive test case and verify that the selected tab title contains the substring '#1'.

tc = matlab.uitest.TestCase.forInteractiveUse;
tc.verifySubstring(group.SelectedTab.Title,'#1')
verification passed.

Choose tab 2 and verify that the selected tab changes.

tc.choose(group,'Tab #2')
tc.verifyEqual(group.SelectedTab,tab2)
Verification passed.

Introduced in R2018a