type
Class: matlab.uitest.TestCase
Namespace: matlab.uitest
Type in UI component
Description
Input Arguments
testCase
— Test case
matlab.uitest.TestCase
object
Test case, specified as a matlab.uitest.TestCase
object.
comp
— Component to type in
UI component object
Component to type in during test, specified as a UI component object that supports a type gesture. Components that support type gestures include edit fields and text areas.
Supported Component | Typical Creation Function |
---|---|
Date Picker | uidatepicker |
Drop Down | uidropdown |
Edit Field (Numeric, Text) | uieditfield |
Spinner | uispinner |
Text Area | uitextarea |
value
— Value to type
depends on component
Value to type into the component. The data type of
value
depends on the type of component under test.
For example, if the component is a spinner, specify
value
as numeric. If the component is a text area
or table, specify value
as a character vector or
string.
uit
— Target table UI component
matlab.ui.control.Table
object
Target table UI component, specified as a
matlab.ui.control.Table
object. Table UI components are
created with the uitable
function.
indices
— Indices of table cell
1-by-2 vector
Indices of the table cell to type in, specified as a 1-by-2 vector with the row index appearing before the column index.
Example: [2 3]
Examples
Type in Edit Field and Verify Change
Create a text edit field.
ed = uieditfield('Value','Hello')
Create an interactive test case and verify the initial value.
tc = matlab.uitest.TestCase.forInteractiveUse;
tc.verifyEqual(ed.Value,'Hello')
Verification passed.
Type the word "Goodbye" in the edit field and verify the new value.
value = 'Goodbye';
tc.type(ed,value)
tc.verifyEqual(ed.Value,value)
Verification passed.
Add Item to Drop-down List and Verify Change
Create an editable drop-down list.
dropdown = uidropdown('Editable','on');
Create an interactive test case and add a custom item to the drop-down list.
tc = matlab.uitest.TestCase.forInteractiveUse;
tc.type(dropdown,'Custom Item')
Verify the new value.
tc.verifyEqual(dropdown.Value,'Custom Item')
Verification passed.
Type in Table Cell and Verify Change
Create a table UI component that contains a mixture of different data types. Set the ColumnEditable
property to true
so that users can edit the data in the table.
fig = uifigure; uit = uitable(fig); d = {'Male',52,true;'Male',40,true;'Female',25,false}; uit.Data = d; uit.ColumnName = {'Gender','Age','Authorized'}; uit.ColumnEditable = true;
Create an interactive test case and verify the initial value of the table cell with indices (1,2).
tc = matlab.uitest.TestCase.forInteractiveUse; tc.verifyEqual(uit.Data(1,2),{[52]})
Verification passed.
Change the value of the cell to 50 and verify the new value.
tc.type(uit,[1 2],'50')
tc.verifyEqual(uit.Data(1,2),{[50]})
Verification passed.
Version History
Introduced in R2018aR2021a: Perform gestures on table UI components
You can perform type gestures in tests on table UI components. The
type
method has a new syntax that lets you type in table
cells.
R2019a: Perform gestures on date pickers
You can perform type gestures in tests on date pickers.
See Also
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)