Reliably resize uifigure – sometimes set Position is ignored under test automation
Hi,
I’m facing a strange issue, where resizing of a uifigure doesn’t work consistently under testautomation stress.
Maybe someone has a tip for me, is there a better way to ensure that fig.Postion = [something] is visually applied, than drawnow/pause?
I have set of complicated dialogs, where frames needs to be extended to accomodate additional controls, when user clicks something. Everything works OK for manual testing, but starts failing on test automation.
I have a class object, representing the dialog, and it has property "mainFigure" – uifigure. For resizing of it (extra space on the lower part) I’ve implemented method
function pos = increaseMainFigureHeight(obj, increase)
pos = obj.mainFigure.Position;
% move bottom
pos(2) = pos(2) – increase;
% and increase the height
pos(4) = pos(4) + increase;
obj.mainFigure.Position = pos; <<<
% Flush callbacks and allow layout/window to settle before asserting position
desiredPos = pos;
for k = 1:60
drawnow;
if isequal(obj.mainFigure.Position, desiredPos) <<<<< this read may return different value!
disp([‘increase ok: ‘ num2str(k)]);
break;
end
pause(0.05);
end
if k>=60
Messaging.debug(‘Figure height update not solved in 60 rounds’, level=Messaging.Warning);
end
end
And very similar for decrease the height.
Under manual conditions the "disp([‘increase ok: ‘ num2str(k)]);" prints always 1 – after setting new positions and drawnow, reading of the position will correspond to the positions, which were just set!
However, as soon as I get it under testautomation:
classdef ReusableDialogTest < matlab.unittest.TestCase
methods (Test)
function testIncreaseDecreaseMainFigureHeight(testCase)
dlg = dialogs.AIConfigDialog(); % Just create some dialog, inherited from ReusableDialog
clp = onCleanup(@() delete(dlg));
increaseSize = 100;
initialPos = dlg.mainFigure.Position;
extendedPosition = initialPos;
extendedPosition(2) = initialPos(2) – increaseSize;
extendedPosition(4) = initialPos(4) + increaseSize;
for repeat = 1:20
dlg.increaseMainFigureHeight(increaseSize);
testCase.assertEqual(dlg.mainFigure.Position, extendedPosition);
dlg.decreaseMainFigureHeight(increaseSize);
testCase.assertEqual(dlg.mainFigure.Position, initialPos);
end
end
end
end
I’m starting getting problems.
Note: I’ve inserted the loop for 20 repetitions, just to make the issue more visible.
Typical output for running the test will look like:
Running ReusableDialogTest
Setting up ReusableDialogTest
Done setting up ReusableDialogTest in 0 seconds
Running ReusableDialogTest/testIncreaseDecreaseMainFigureHeight
increase ok: 3
decrease ok: 1
increase ok: 2
decrease ok: 1
increase ok: 2
decrease ok: 2
…
So, sometimes several rounds of drawnow/pause are required.
But sometimes it stucks completely. In following case decrease didn’t succeed with 60 hops of drawnow/pause:
Running ReusableDialogTest
Setting up ReusableDialogTest
Done setting up ReusableDialogTest in 0 seconds
Running ReusableDialogTest/testIncreaseDecreaseMainFigureHeight
increase ok: 3
Warning: Figure height update not solved in 60 rounds
================================================================================
Assertion failed in ReusableDialogTest/testIncreaseDecreaseMainFigureHeight and it did not run to completion.
———————
Framework Diagnostic:
———————
assertEqual failed.
–> The numeric values are not equal using "isequaln".
–> Failure table:
Index Actual Expected Error RelativeError
_____ ______ ________ _____ __________________
2 478 578 -100 -0.173010380622837
4 252 152 100 0.657894736842105
Actual Value:
729 478 583 252
Expected Value:
729 578 583 152
——————
Stack Information:Hi,
I’m facing a strange issue, where resizing of a uifigure doesn’t work consistently under testautomation stress.
Maybe someone has a tip for me, is there a better way to ensure that fig.Postion = [something] is visually applied, than drawnow/pause?
I have set of complicated dialogs, where frames needs to be extended to accomodate additional controls, when user clicks something. Everything works OK for manual testing, but starts failing on test automation.
I have a class object, representing the dialog, and it has property "mainFigure" – uifigure. For resizing of it (extra space on the lower part) I’ve implemented method
function pos = increaseMainFigureHeight(obj, increase)
pos = obj.mainFigure.Position;
% move bottom
pos(2) = pos(2) – increase;
% and increase the height
pos(4) = pos(4) + increase;
obj.mainFigure.Position = pos; <<<
% Flush callbacks and allow layout/window to settle before asserting position
desiredPos = pos;
for k = 1:60
drawnow;
if isequal(obj.mainFigure.Position, desiredPos) <<<<< this read may return different value!
disp([‘increase ok: ‘ num2str(k)]);
break;
end
pause(0.05);
end
if k>=60
Messaging.debug(‘Figure height update not solved in 60 rounds’, level=Messaging.Warning);
end
end
And very similar for decrease the height.
Under manual conditions the "disp([‘increase ok: ‘ num2str(k)]);" prints always 1 – after setting new positions and drawnow, reading of the position will correspond to the positions, which were just set!
However, as soon as I get it under testautomation:
classdef ReusableDialogTest < matlab.unittest.TestCase
methods (Test)
function testIncreaseDecreaseMainFigureHeight(testCase)
dlg = dialogs.AIConfigDialog(); % Just create some dialog, inherited from ReusableDialog
clp = onCleanup(@() delete(dlg));
increaseSize = 100;
initialPos = dlg.mainFigure.Position;
extendedPosition = initialPos;
extendedPosition(2) = initialPos(2) – increaseSize;
extendedPosition(4) = initialPos(4) + increaseSize;
for repeat = 1:20
dlg.increaseMainFigureHeight(increaseSize);
testCase.assertEqual(dlg.mainFigure.Position, extendedPosition);
dlg.decreaseMainFigureHeight(increaseSize);
testCase.assertEqual(dlg.mainFigure.Position, initialPos);
end
end
end
end
I’m starting getting problems.
Note: I’ve inserted the loop for 20 repetitions, just to make the issue more visible.
Typical output for running the test will look like:
Running ReusableDialogTest
Setting up ReusableDialogTest
Done setting up ReusableDialogTest in 0 seconds
Running ReusableDialogTest/testIncreaseDecreaseMainFigureHeight
increase ok: 3
decrease ok: 1
increase ok: 2
decrease ok: 1
increase ok: 2
decrease ok: 2
…
So, sometimes several rounds of drawnow/pause are required.
But sometimes it stucks completely. In following case decrease didn’t succeed with 60 hops of drawnow/pause:
Running ReusableDialogTest
Setting up ReusableDialogTest
Done setting up ReusableDialogTest in 0 seconds
Running ReusableDialogTest/testIncreaseDecreaseMainFigureHeight
increase ok: 3
Warning: Figure height update not solved in 60 rounds
================================================================================
Assertion failed in ReusableDialogTest/testIncreaseDecreaseMainFigureHeight and it did not run to completion.
———————
Framework Diagnostic:
———————
assertEqual failed.
–> The numeric values are not equal using "isequaln".
–> Failure table:
Index Actual Expected Error RelativeError
_____ ______ ________ _____ __________________
2 478 578 -100 -0.173010380622837
4 252 152 100 0.657894736842105
Actual Value:
729 478 583 252
Expected Value:
729 578 583 152
——————
Stack Information: Hi,
I’m facing a strange issue, where resizing of a uifigure doesn’t work consistently under testautomation stress.
Maybe someone has a tip for me, is there a better way to ensure that fig.Postion = [something] is visually applied, than drawnow/pause?
I have set of complicated dialogs, where frames needs to be extended to accomodate additional controls, when user clicks something. Everything works OK for manual testing, but starts failing on test automation.
I have a class object, representing the dialog, and it has property "mainFigure" – uifigure. For resizing of it (extra space on the lower part) I’ve implemented method
function pos = increaseMainFigureHeight(obj, increase)
pos = obj.mainFigure.Position;
% move bottom
pos(2) = pos(2) – increase;
% and increase the height
pos(4) = pos(4) + increase;
obj.mainFigure.Position = pos; <<<
% Flush callbacks and allow layout/window to settle before asserting position
desiredPos = pos;
for k = 1:60
drawnow;
if isequal(obj.mainFigure.Position, desiredPos) <<<<< this read may return different value!
disp([‘increase ok: ‘ num2str(k)]);
break;
end
pause(0.05);
end
if k>=60
Messaging.debug(‘Figure height update not solved in 60 rounds’, level=Messaging.Warning);
end
end
And very similar for decrease the height.
Under manual conditions the "disp([‘increase ok: ‘ num2str(k)]);" prints always 1 – after setting new positions and drawnow, reading of the position will correspond to the positions, which were just set!
However, as soon as I get it under testautomation:
classdef ReusableDialogTest < matlab.unittest.TestCase
methods (Test)
function testIncreaseDecreaseMainFigureHeight(testCase)
dlg = dialogs.AIConfigDialog(); % Just create some dialog, inherited from ReusableDialog
clp = onCleanup(@() delete(dlg));
increaseSize = 100;
initialPos = dlg.mainFigure.Position;
extendedPosition = initialPos;
extendedPosition(2) = initialPos(2) – increaseSize;
extendedPosition(4) = initialPos(4) + increaseSize;
for repeat = 1:20
dlg.increaseMainFigureHeight(increaseSize);
testCase.assertEqual(dlg.mainFigure.Position, extendedPosition);
dlg.decreaseMainFigureHeight(increaseSize);
testCase.assertEqual(dlg.mainFigure.Position, initialPos);
end
end
end
end
I’m starting getting problems.
Note: I’ve inserted the loop for 20 repetitions, just to make the issue more visible.
Typical output for running the test will look like:
Running ReusableDialogTest
Setting up ReusableDialogTest
Done setting up ReusableDialogTest in 0 seconds
Running ReusableDialogTest/testIncreaseDecreaseMainFigureHeight
increase ok: 3
decrease ok: 1
increase ok: 2
decrease ok: 1
increase ok: 2
decrease ok: 2
…
So, sometimes several rounds of drawnow/pause are required.
But sometimes it stucks completely. In following case decrease didn’t succeed with 60 hops of drawnow/pause:
Running ReusableDialogTest
Setting up ReusableDialogTest
Done setting up ReusableDialogTest in 0 seconds
Running ReusableDialogTest/testIncreaseDecreaseMainFigureHeight
increase ok: 3
Warning: Figure height update not solved in 60 rounds
================================================================================
Assertion failed in ReusableDialogTest/testIncreaseDecreaseMainFigureHeight and it did not run to completion.
———————
Framework Diagnostic:
———————
assertEqual failed.
–> The numeric values are not equal using "isequaln".
–> Failure table:
Index Actual Expected Error RelativeError
_____ ______ ________ _____ __________________
2 478 578 -100 -0.173010380622837
4 252 152 100 0.657894736842105
Actual Value:
729 478 583 252
Expected Value:
729 578 583 152
——————
Stack Information: matlab gui, matlab, gui MATLAB Answers — New Questions









