drag

Class: matlab.uitest.TestCase
Package: matlab.uitest

Perform drag gesture on UI component

Syntax

drag(testcase,comp,start,stop)

Description

drag(testcase,comp,start,stop) performs a drag gesture from start to stop on the UI component comp.

Input Arguments

expand all

Instance of the test case, specified as a matlab.uitest.TestCase object.

Component to drag during test, specified as a UI component object that supports a drag gesture. Components that support drag gestures include continuous knobs and sliders.

Supported ComponentTypical Creation Function
Knob

uiknob

Slider

uislider

Data Types: matlab.ui.control.Knob | matlab.ui.control.Slider

Starting value of the drag gesture, specified as a numeric value within component limits. Limits are defined by the Limits property of the component.

Stopping value of the drag gesture, specified as a numeric value within component limits. Limits are defined by the Limits property of the component.

Examples

expand all

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.

Introduced in R2018a