press(testcase,comp,location)
specifies the location to press within the component. You can only specify
location with five of the available components: axes, UI axes, polar axes,
panel, and UI figure. If you do not specify the location, MATLAB® presses at the center of comp.
testcase — Instance of test case matlab.uitest.TestCase object
Instance of the test case, specified as a matlab.uitest.TestCase object.
comp — Component to press UI component 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.
location — Location to press 1-by-2 or 1-by-3 numeric array
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.
Panel and UI Figure — A 1-by-2 numeric array containing
x- and y-coordinates.
Specify the coordinates of the point to press as measured in pixels
from the lower-left corner of the component.
Example: [32.5 13 0.25] (UI axes)
Example: [pi/2 0.5] (Polar axes)
Example: [100 200] (UI figure)
spn — Spinner component to press matlab.ui.control.Spinner object
Spinner component to press during the test, specified as a
matlab.ui.control.Spinner object. Spinner components
are typically created with the uispinner function.
direction — Direction of change 'up' | 'down'
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
compst — Component to press using mouse selection type matlab.graphics.axis.Axes object | matlab.ui.control.UIAxes object | matlab.ui.Figure object
Component to press during the test using a given mouse selection type,
specified as a matlab.graphics.axis.Axes,
matlab.ui.control.UIAxes, or
matlab.ui.Figure object.
type — Mouse selection type 'normal' (default) | 'extend' | 'alt' | 'open'
Mouse selection type, specified as 'normal',
'extend', 'alt', or
'open'. This input provides information about how the
mouse button is pressed in the component. For more information, see
UI Figure Properties.
This table lists the possible selection type values and the actions that
correspond to these values.
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'.
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
coordinates.
tc.press(ax,[0.85 0.2])
Press Button and Verify Value Change
Create a state button.
b = uibutton('state');
Create an interactive test case and verify that the value of the state button is false.
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.
Modify Value of Spinner and Verify Change
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.
Create a UI figure and an interactive test case instance.
f = uifigure;
tc = matlab.uitest.TestCase.forInteractiveUse;
Test a right-click at the center of the UI figure. A blue dot representing
the programmatic push gesture appears and then disappears at the center of
the figure.
tc.press(f,'SelectionType','alt')
Test a double-click on the UI figure at the coordinates (100, 200). A blue
dot representing the programmatic push gesture appears and then disappears
at the specified location.
R2021b: Specify the mouse selection type in gestures on axes and UI axes
You can specify the mouse selection type in press gestures that are performed in
tests on axes and UI axes. The compst argument now also
supports objects of type Axes and UIAxes, and can be
used in combination with the type
input argument to specify the mouse selection type.
R2021a: Perform gestures on panels
You can perform press gestures in tests on panels.
R2020b: Perform gestures on push tools and toggle tools
You can perform press gestures in tests on push tools and toggle tools.
R2020a: Specify the mouse selection type in gestures on UI figures
You can specify the mouse selection type in press gestures that are performed in
tests on UI figures. To specify the mouse selection type, use the type
input argument.
R2019b: Perform gestures on polar axes and images
You can perform press gestures in tests on polar axes and images.
R2019a: Perform gestures on axes and UI figures
You can perform press gestures in tests on axes and UI figures.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.