In Power Apps, the Test Engine provides a robust capability to test variables and collections on custom pages. This article explores the essentials of Power FX variables and collections, their common uses, and the role of testing in simplifying application state management.
Power FX variables and collections are fundamental components in Power Apps that help manage the state and data within an application.
Variables in Power FX are used to store values that can change over time. They are essential for controlling the state of the application, such as toggling visibility, storing user inputs, or managing session data.
Collections are used to store tables of data that can be queried and manipulated. They are often used to fetch data from connectors and serve as data sources for controls like Grids and Galleries.
Variables are commonly used to:
Collections are powerful for:
Testing is crucial for ensuring that the application behaves as expected. By querying and updating the state of the application, testing simplifies the process of verifying functionality without inferring state from control values.
Set()
Function in Test Steps The Set()
function is instrumental in testing as it allows developers to change the state of the application directly. This capability is vital for:
In traditional code-first applications, mocking is a common approach to simulate different states and behaviors. In Power Apps, the low-code nature of the platform, combined with the Set()
function, makes testing more accessible and approachable. This approach allows developers to:
The Setup and Upgrade Wizard of the CoE Starter Kit provides a good example of working with global variables. The state of the page, which includes the current state of the Subway Navigation control and the wizard steps, is controlled by a common variable. This application is made up of multiple screens that allow the user to verify that the different elements of the CoE Starter Kit have been set up and are in a working state.
Let’s look at how the test engine helps with testing this scenario. This example demonstrates that by being able to interact with the Power FX variables, it greatly simplifies the testing of this application as a key global variable controls the state of the application. By being able to get and set the variable rather than having to infer where in the process the app is, the variable can easily be asserted to verify the state of the app.
Key parts of this example test that start the test and set the initial state
Preview.ConsentDialog(Table({Text: "Center of Excellence Setup Wizard"}));
Set(configStep, 1);
Assert(configStep=1);
Some key points
Set(configStep, 1)
function call updates the step of the upgrade process to the Confirm pre-requisites step. By updating this variable, the Power Apps Provider updates the Model Driven Application custom page state.Assert()
and CountRows()
could be functions to check that the state of the app and the selected data. This could be extended to filter functions to ensure the specific status of the required components.Select(Next)
to move to the second step given the state of variables is known.The Test Engine in Power Apps provides a powerful framework for testing variables and collections. By leveraging the Set()
function and understanding the role of variables and collections, developers and makers can create robust and reliable applications. Testing not only ensures functionality but also enhances the overall user experience by catching issues early in the process.