Hi Nick,
I understand that you are facing an issue in closing the dialog box without manual intervention.
To programmatically click a button in a dialog box during a test in MATLAB, you would typically use the “matlab.uitest.TestCase” class to interact with the UI components. However, “uiconfirm” dialog boxes are modal and block the MATLAB command line, preventing further commands from running until a user makes a selection.
Since you cannot directly interact with the “uiconfirm” dialog in an automated way using “matlab.uitest.TestCase”, you would need to create a custom dialog using “uifigure” and UI components (like “uibutton”) if you want to automate interaction with a dialog box. Once you have a custom dialog with buttons, you can use the press method of the “matlab.uitest.TestCase” object to simulate a button click.
Here's an example of how you might create a custom dialog and then simulate a button click:
function tester(data)
% Create a TestCase object for UI testing
testCase = matlab.uitest.TestCase.forInteractiveUse;
app = YourAppName;
pause(2);
% Create a custom dialog with buttons
dlg = uifigure('Name', 'Confirmation', 'Position', [100 100 250 150]);
btnYes = uibutton(dlg, 'Text', 'Yes', 'Position', [50 50 70 25]);
btnNo = uibutton(dlg, 'Text', 'No', 'Position', [130 50 70 25]);
% Pause to ensure the dialog is rendered before trying to interact
drawnow;
pause(0.5); % Pause for half a second
% Use the TestCase to press the 'Yes' button
testCase.press(btnYes);
pause(0.5);
% Additional testing code goes here
% Close the custom dialog and the app when done
delete(dlg);
delete(app);
end
In case, if you wish to pass the data from workspace into the app when testing, you can modify the function syntax as follows.
function tester(data)
% Code
% The data variable is passed as an argument from workspace
app.EditField.Value = data;
% Code
end
When calling this testcase from the command window, we need to specify the parameters as well.
tester(data)
Hope this solution helps.
Thanks,
Ravi