press

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

Perform press gesture on UI component

Syntax

press(testcase,comp)
press(testcase,comp,location)
press(testcase,spn,direction)

Description

press(testcase,comp) performs a press gesture on the UI component comp.

press(testcase,comp,location) specifies the location to press within the component. You can specify the location within an Axes, UIAxes, PolarAxes, or Figure object. If you do not specify the location, MATLAB® presses at the center of comp.

press(testcase,spn,direction) specifies whether to press the 'up' or 'down' direction button in the spinner spn.

Input Arguments

expand all

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

Component to press during the test, specified as a UI component object that supports a press gesture. Components that support press gestures include images, buttons, check boxes, switches, menus, axes, and figures.

Supported ComponentTypical Creation Function
Imageuiimage
Button

uibutton

uiradiobutton

uitogglebutton

Check Boxuicheckbox
Switch

uiswitch

Menuuimenu
Axesaxes
UI Axesuiaxes
Polar Axespolaraxes
UI Figureuifigure

Data Types: matlab.ui.control.Image | matlab.ui.control.Button | matlab.ui.control.StateButton | matlab.ui.control.RadioButton | matlab.ui.control.ToggleButton | matlab.ui.control.CheckBox | matlab.ui.control.Switch | matlab.ui.control.ToggleSwitch | matlab.ui.control.RockerSwitch | matlab.ui.container.Menu | matlab.graphics.axis.Axes | matlab.ui.control.UIAxes | matlab.graphics.axis.PolarAxes | matlab.ui.Figure

Location to press, specified as the coordinates of the point:

  • Axes and UI Axes — A 1-by-2 or 1-by-3 numeric array containing x-, y-, and optionally z-coordinates.

  • Polar Axes — A 1-by-2 numeric array containing θ- and r-coordinates.

  • UI Figure — A 1-by-2 numeric array containing x- and y-coordinates. Specify the coordinates of the point to press measured in pixels from the lower-left corner of the UI figure.

Example: [32.5 13 0.25] (UI axes)

Example: [pi/2 0.5] (Polar axes)

Example: [100 200] (UI figure)

Spinner component to press during the test, specified as a matlab.ui.control.Spinner object. Spinner components are typically created with the uispinner function.

Data Types: matlab.ui.control.Spinner

Direction of change for the spinner, specified as 'up' or 'down'. To increment the value of the spinner, use 'up'. To decrement the value, use 'down'.

Data Types: char | string

Examples

expand all

Create a slider switch.

s = uiswitch('slider');

Create an interactive test case and press the switch. A blue dot representing the programmatic push gesture appears and then disappears at the center of the switch. The switch moves from 'Off' to 'On'.

tc = matlab.uitest.TestCase.forInteractiveUse;
tc.press(s);

Create UI axes and an interactive test case instance.

ax = uiaxes;
tc = matlab.uitest.TestCase.forInteractiveUse;

Press the center of the axes. A blue dot representing the programmatic push gesture appears and then disappears at the center of the axes.

tc.press(ax)

Press the axes at the coordinates (0.85,0.2). A blue dot representing the programmatic push gesture appears and then disappears at the specified axes coordinate.

tc.press(ax,[0.85 0.2])

Create a state button.

b = uibutton('state');

Create an interactive test case and verify that the value of the state button is false.

tc = matlab.uitest.TestCase.forInteractiveUse;
tc.verifyFalse(b.Value)
Verification passed.

Press the button and verify the state changes to true. A blue dot representing the programmatic push gesture appears and then disappears on the button.

tc.press(b)
tc.verifyTrue(b.Value)
Verification passed.

Create a spinner with an initial value of 42.

s = uispinner('Value',42);
initVal = s.Value;

Create an interactive test case and increment the spinner. Verify that the new value of the spinner is the initial value plus the spinner step value.

tc = matlab.uitest.TestCase.forInteractiveUse;
tc.press(s,'up')
tc.verifyEqual(s.Value,initVal+s.Step)
Verification passed.

Decrement the value of the spinner and verify that the value of the spinner is equal to the initial value again.

tc.press(s,'down')
tc.verifyEqual(s.Value,initVal)
Verification passed.

Introduced in R2018a