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.
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.
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 — A 1-by-2 numeric array containing x-
and y-coordinates. Specify the coordinates of the
point measured in pixels from the lower-left corner of the
component.
UI Figure — A 1-by-2 numeric array containing
x- and y-coordinates. Specify
the coordinates of the point 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)
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 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
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.
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 Figure.
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])
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.
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.
tc.press(f,[100 200],'SelectionType','open')
Since R2023b
Perform a gesture on a component that is not in the viewable area of a figure by automatically scrolling to the component.
Create a scrollable figure with a state button that is outside the viewable area of the figure.
fig = uifigure("Scrollable","on");
b = uibutton(fig,"state","Position",[fig.Position(3)+100 100 100 22]);
Create a test case for interactive testing, and verify the initial state of the button.
Press the button and verify that its state changes. Because the figure is scrollable, the app testing framework automatically scrolls to the button before performing the gesture.
You can specify the location of the gesture on a UI figure that uses any unit of measurement.
In previous releases, the method lets you specify coordinates only for figures whose
Units property is set to "pixels".
Specifying the location of the gesture on axes or UI axes with an active right
y-axis is no longer supported. If your chart has two
y-axes, activate the side associated with the left
y-axis before performing the gesture. In previous releases, when you
specify the location on axes or UI axes with an active right side, the app testing framework
interprets that location with respect to the left y-axis, which can cause
the gesture to occur at an unexpected location or fail.
You can perform press gestures in tests on hyperlinks.
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.
You can perform press gestures in tests on panels.
You can perform press gestures in tests on push tools and toggle tools.
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.
You can perform press gestures in tests on polar axes and images.
You can perform press gestures in tests on axes and UI figures.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
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.