- https://www.mathworks.com/help/releases/R2021b/matlab/ref/timer.html
- https://www.mathworks.com/help/releases/R2021b/matlab/ref/videoreader.html
- https://www.mathworks.com/help/releases/R2021b/matlab/app-testing-framework.html
testcase.press() interrupts rest of testing script until button callback function has completed.
3 views (last 30 days)
Show older comments
Good day,
I am using the testing framework to test a pause/play state button. The state button's callback simply changes the icon of the button and executes a timer object callback function to playback the media. The code snippet tests that the button icon changes to the correct icon when pressed.
% Press the Restart button and verify it was pressed
testCase.press(testCase.App.Play)
if testCase.App.Play.Icon ~= "pause.png" || testCase.App.Play.Value ~= 1
test = 0;
log(testCase,4,"'Restart' button is broken")
end
Not sure if relevant, but this used to work fine when the button used to have text (as in the word 'play' for example) instead of an icon. Then I made several changes to the rest of the app (including adding icons and moving buttons around the page) and now the when testCase.press() is executed, the test is interrupted until the timer object callback function is completed, at which point the playback is completed and the icon reverts back (as it should). This means that by the time the test script gets to the if statement, the test fails because the playback is complete and the icon has changed.
Before the changes where made, testCase.press() seemed to be asynchronous, and the test script will get to the if statement while playback is still occuring, which is the desired behaviour.
I would like some insight as to what is happening please.
Thanks
0 Comments
Answers (1)
Kanishk
on 27 Sep 2024
Hi Gad,
I've implemented a similar application using a "state button," "timer," and "VideoReader" to control video playback. I conducted a test to verify the pause icon on the button, and it passed successfully, so I was not able to reproduce the issue you're experiencing.
Below is the timer function I used for video playback:
function playVideo(app)
app.TimerObj = timer('ExecutionMode', 'fixedRate', ...
'Period', 1/app.VideoObj.FrameRate, ...
'TimerFcn', @(~,~)updateFrame(app));
start(app.TimerObj);
end
function pauseVideo(app)
stop(app.TimerObj);
end
function updateFrame(app)
if hasFrame(app.VideoObj)
frame = readFrame(app.VideoObj);
imshow(frame, 'Parent', app.UIAxes);
else
app.VideoObj = VideoReader('vid.mp4');
app.Play.Value = 0;
app.Play.Icon = fullfile('play.png');
stop(app.TimerObj);
end
end
I also adjusted the test function to verify the icon and the button's value.
function testPlay(testCase)
import matlab.unittest.fixtures.SuppressedWarningsFixture
testCase.applyFixture(SuppressedWarningsFixture('MATLAB:timer:miliSecPrecNotAllowed'))
testCase.press(testCase.App.Play)
testCase.verifyEqual(testCase.App.Play.Icon, 'pause.png');
testCase.verifyEqual(testCase.App.Play.Value, true);
stop(testCase.App.TimerObj);
delete(testCase.App.TimerObj);
end
I have attached a dummy app for further information if needed.
Here is the official MATLAB documentation of “timer”, “VideoReader” and writing tests for MATLAB apps.
Glad to help!!
Thanks
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!