press
Class: matlab.uitest.TestCase
Namespace: matlab.uitest
Perform press gesture on UI component
Syntax
Description
Input Arguments
testCase
— Test case
matlab.uitest.TestCase
object
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.
Supported Component | Typical Creation Function |
---|---|
Axes | axes |
Button | uibutton |
Check Box | uicheckbox |
Hyperlink | uihyperlink |
Image | uiimage |
Menu | uimenu |
Panel | uipanel |
Polar Axes | polaraxes |
Push Tool | uipushtool |
Radio Button | uiradiobutton |
State Button | uibutton |
Switch (Rocker, Slider, Toggle) | uiswitch |
Toggle Button | uitogglebutton |
Toggle Tool | uitoggletool |
UI Axes | uiaxes |
UI Figure | uifigure |
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 — 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)
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
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.
Value | Corresponding Action |
---|---|
| Click the left mouse button. |
| Shift-click the left mouse button. |
| Click the right mouse button. |
| Double-click any mouse button. |
Data Types: char
| string
Examples
Press Switch
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);
Press Axes Location
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 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
.
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.
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.
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.
Press UI Figure with Specified Selection Type
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')
Automatically Scroll to Component
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.
tc = matlab.uitest.TestCase.forInteractiveUse; tc.verifyFalse(b.Value)
Verification passed.
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.
tc.press(b) tc.verifyTrue(b.Value)
Verification passed.
Version History
Introduced in R2018aR2024b: Specify location of gesture on figures that use nonpixel units
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"
.
R2024b: Specifying location of gesture on axes or UI axes with active right y-axis is not supported
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.
R2024a: Perform gestures on hyperlinks
You can perform press gestures in tests on hyperlinks.
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.
MATLAB Command
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: .
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)