Class: matlab.uitest.TestCase
Package: matlab.uitest
Perform drag gesture on UI component
drag(testcase,comp,start,stop)
drag(
performs a drag gesture from testcase
,comp
,start
,stop
)start
to stop
on
the UI component comp
.
testcase
— Instance of test casematlab.uitest.TestCase
objectInstance of the test case, specified as a matlab.uitest.TestCase
object.
comp
— Component to dragstart
— Starting valueStarting value of the drag gesture, specified as a numeric scalar or a
1-by-2 or 1-by-3 numeric array. The form of start
depends
on the UI component:
Knob and Slider — A numeric scalar within component limits.
Limits are defined by the Limits
property
of the component.
Axes and UI Axes — A 1-by-2 or 1-by-3 numeric array containing x-, y-, and optionally z-coordinates.
Example: 20
(knob)
Example: [2.5 3 1.25]
(UI axes)
stop
— Stopping valueStopping value of the drag gesture, specified as a numeric scalar or a
1-by-2 or 1-by-3 numeric array. The form of stop
depends
on the UI component:
Knob and Slider — A numeric scalar within component limits.
Limits are defined by the Limits
property
of the component.
Axes and UI Axes — A 1-by-2 or 1-by-3 numeric array containing x-, y-, and optionally z-coordinates.
Example: 30
(knob)
Example: [5 3 2.25]
(UI axes)
Create a knob.
knob = uiknob;
Create an interactive test case and drag the knob between two values. A blue dot representing the programmatic drag gesture appears and then disappears when the knob reaches the stop
value.
tc = matlab.uitest.TestCase.forInteractiveUse; tc.drag(knob,13,42)
Create a slider with a minimum value of -237, a maximum value of 237, and a starting value of 7.
slider = uislider('Limits',[-237 237],'Value',7);
Create an interactive test case and verify the initial value of the slider.
tc = matlab.uitest.TestCase.forInteractiveUse; tc.verifyEqual(slider.Value,7)
Verification passed.
Drag the slider between two values and verify the final value. Since the framework mimics a user manipulating the component to an arbitrarily precisioned value, it is a best practice to use a tolerance to compare the actual and expected slider values.
val = 26.75;
tc.drag(slider,-val,val)
tc.verifyEqual(slider.Value,val,'AbsTol',0.1)
Verification passed.
Create an axes within a UI figure and then plot a line into the axes. In this example, the plot sets both x- and y-axis limits to [1 10].
f = uifigure; ax = axes(f); plot(ax,1:10)
Create an interactive test case and drag from the point (3, 2) to the point (4, 2). A blue dot representing the programmatic drag gesture appears at the start value and then disappears when it reaches the stop value. The axis limits are updated based on the difference between the start and stop values.
tc = matlab.uitest.TestCase.forInteractiveUse; tc.drag(ax,[3 2],[4 2])
Verify that the drag gesture reduced the x-axis limits by one unit. Since the framework mimics a user manipulating the component, using a tolerance to compare the actual and expected values is the recommended practice.
tc.verifyEqual(ax.XLim,[0 9],'AbsTol',0.1)
Verification passed.
Create an axes within a UI figure and plot a surface into the axes using the peaks
function. Then, call the view
function to save the azimuth and elevation angles of the camera's line of sight for the axes.
f = uifigure; ax = axes(f); surf(ax,peaks) xlabel(ax,'X') ylabel(ax,'Y') zlabel(ax,'Z') [caz_before,cel_before] = view(ax);
Create an interactive test case and drag from the point (2, 2, -10) to the point (4, 4, 10). A blue dot representing the programmatic drag gesture appears at the start value and then disappears when it reaches the stop value. The view of the surface plot changes with the drag.
tc = matlab.uitest.TestCase.forInteractiveUse; tc.drag(ax,[2 2 -10],[4 4 10])
Verify that the drag gesture changed the view of the surface plot.
[caz_after,cel_after] = view(ax); tc.verifyNotEqual([caz_after cel_after],[caz_before cel_before])
Verification passed.
You have a modified version of this example. Do you want to open this example with your edits?