Matlab 2019a Testing multiple Apps in a tool
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear MATLAB-Experts,
As part of creating a test suit for our matlab app, we encountered a situtation where we had to test a child app which is popped up on clicking a button in the parent app.
This parent app is a tool which opens multiple chilldren apps, we are using the matlab.uitest.TestCase package.
We have our parent app launched like below,
methods(TestMethodSetup)
function launchApp(testCase)
%
testCase.App = ParentApp;
testCase.addTeardown(@delete,testCase.App)
end
end
Using the setup above, we implemented the below test case:
function childApp_onClick_ChildRunButton(testCase)
%%
testCase.App.global_test_action_count = 0;
testCase.press(testCase.App.ParentLaunchButton);
if height(testCase.App.datatable) > 0
testCase.App.datasetsTable.Data{1,2} = cellstr2logical(cellstr('true'));
testCase.press(testCase.App.ParentGoButton);
%% The child app opens after clicking the ParentGoButton
% Now We need to click few buttons and check few boxes in the
% child app, which is now in the focus for the user
%% After clicking the Go button in the child app, the child app pop up closes and the control should be back to the parent app
testCase.verifyEqual(dataCount_Before,dataCount_Before+1);
end
end
We have tried few approaches,
- Mocking the child app data in the code secion of the child app and force calling the Go button like below,
ExecuteButtonPushed(app, matlab.ui.eventdata.ButtonPushedData)
Is there any way on how to control child apps within the matlab test framework?
Thanks in advance!
0 Commenti
Risposte (1)
Hari
il 27 Dic 2023
Modificato: Hari
il 27 Dic 2023
Hi Darshan Mathew,
I understand that you are developing a test suite for a MATLAB app using the "matlab.uitest.TestCase" framework. Your parent app launches child apps, and you want to test interactions with these child apps, specifically clicking buttons and checking boxes within them.
I am assuming that you have access to the child app object once it is launched, you can interact with the child app's UI components using the same "matlab.uitest.TestCase" methods as you do with the parent app.
Here's an example of how you might interact with the child app's components:
function childApp_onClick_ChildRunButton(testCase)
% ...
% Your existing code to launch the child app
% ...
% Assuming the child app is assigned to a property of the parent app
childApp = testCase.App.ChildApp;
% Interact with the child app's components
% For example, pressing a button in the child app
testCase.press(childApp.SomeButton);
% Checking a checkbox in the child app
testCase.choose(childApp.SomeCheckbox, 'true');
% Verifying the child app's data count has increased
dataCount_After = height(childApp.DataTable);
testCase.verifyEqual(dataCount_After, dataCount_Before + 1);
% Your existing code to handle the control back to the parent app
% ...
end
In this example, you can press a button and choose a checkbox in the child app, then verify that an action has taken place (e.g., the data count has increased). You will need to replace "ChildApp", "SomeButton", "SomeCheckbox", and "DataTable" with the actual names of the properties and components in your apps.
For more information on how to use "matlab.uitest.TestCase" for testing UI components, refer to the documentation: https://www.mathworks.com/help/matlab/ref/matlab.uitest.testcase-class.html
To understand more about interacting with UI components in tests, refer to the documentation of UI component interactions
Hopw this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Create Custom UI Components in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!