Skip to content

Enabling PowerApps MDA Table, Form, Classic Form for Custom Pages with Test Engine Support #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
43 changes: 43 additions & 0 deletions samples/mdaformtablecontrol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Overview

This Power Apps Test Engine sample demonstrates how to assert and interact with the values of Table, Form, and Classic Forms—EditForm and ViewForm controls—in a model-driven application form.

## Usage

1. **Build the Test Engine Solution**
Ensure the Power Apps Test Engine solution is built and ready to be executed.

2. **Get the URL of the Model-Driven Application Form**
Acquire the URL of the specific model-driven application form that you want to test.

3. **Modify the testPlan.fx.yaml**
Update the YAML file to assert expected values of the Table, Form, and Classic Forms—EditForm and ViewForm controls.

> **Note:** The controls are referenced using the [logical name](https://learn.microsoft.com/power-apps/developer/data-platform/entity-metadata#table-names).

4. **Update the Domain URL for Your Model-Driven Application**

| URL Part | Description |
| ---------------------------------------------- | ------------------------------------------------------- |
| `appid=a1234567-cccc-44444-9999-a123456789123` | The unique identifier of your model-driven application. |
| `etn=` | The name of the entity being validated. |
| `id=26bafa27-ca7d-ee11-8179-0022482a91f4` | The unique identifier of the record being edited. |
| `pagetype=custom` | The type of page to open. |
| `UserAuth=storagestate` | The type of user authentication to use. |
| `UseStaticContext=True` | A flag indicating the use of a static context. |

5. **Execute the Test for Custom Page**
Please replace the example URLs with your organization's URL. Validate the number of records in the Employee table before executing the test plan. If needed, update the number in the test plan.

**Command for Form and Table Controls:**
```pwsh
cd bin\Debug\PowerAppsEngine
dotnet PowerAppsTestEngine.dll -i ..\..\..\samples\mdaformtablecontrol\formtablecontroltestplan.fx.yaml -e 00000000-0000-0000-0000-11112223333 -t 11112222-3333-4444-5555-666677778888 -u browser -p mda -d "https://orgfc708206.crm.dynamics.com/main.aspx?appid=706281e3-b1ed-ef11-be20-7c1e526718b6&pagetype=custom&name=cr693_employeedetails_7f620"
```

**Command for Classic Form and Table Controls:**
```pwsh
cd bin\Debug\PowerAppsEngine
dotnet PowerAppsTestEngine.dll -i ..\..\..\samples\mdaformtablecontrol\classicformtablecontroltestplan.fx.yaml -e 00000000-0000-0000-0000-11112223333 -t 11112222-3333-4444-5555-666677778888 -u browser -p mda -d "https://orgfc708206.crm.dynamics.com/main.aspx?appid=706281e3-b1ed-ef11-be20-7c1e526718b6&pagetype=custom&name=cr7d6_classicforms_e08a2"
```

33 changes: 33 additions & 0 deletions samples/mdaformtablecontrol/RunTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# Get current directory so we can reset back to it after running the tests
$currentDirectory = Get-Location

$config = Get-Content -Path .\config.json -Raw | ConvertFrom-Json
$tenantId = $config.tenantId
$environmentId = $config.environmentId
$user1Email = $config.user1Email

if ([string]::IsNullOrEmpty($environmentId)) {
Write-Error "Environment not configured. Please update config.json"
return
}

# Build the latest debug version of Test Engine from source
Set-Location ..\..\src
dotnet build

if ($config.installPlaywright) {
Start-Process -FilePath "pwsh" -ArgumentList "-Command `"..\bin\Debug\PowerAppsTestEngine\playwright.ps1 install`"" -Wait
} else {
Write-Host "Skipped playwright install"
}

Set-Location ..\bin\Debug\PowerAppsTestEngine
$env:user1Email = $user1Email
# Run the tests for each user in the configuration file.
dotnet PowerAppsTestEngine.dll -u "storagestate" -p "mda" -a "none" -i "$currentDirectory\formtablecontroltestplan.fx.yaml" -t $tenantId -e $environmentId

# Reset the location back to the original directory.
Set-Location $currentDirectory
158 changes: 158 additions & 0 deletions samples/mdaformtablecontrol/classicformtablecontroltestplan.fx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
testSuite:
testSuiteName: MDA Custom Page tests - Table and Classic Edit and View form Control
testSuiteDescription: Verify test cases for Table and Classic Edit and View form Control in Custom Page
persona: User1
appLogicalName: NotNeeded

testCases:
- testCaseName: Test Table Control - Selected Property
testCaseDescription: Verify that selecting a row updates the Selected property correctly.
testSteps: |
SetProperty(Table1.SelectedItems, Table(Index(Table1.Items, 5)));
Select(Table1, 5);
Wait(FormViewer1, "Visible", true);
Assert(Form1.Visible = false && FormViewer1.Visible = true, "Checking if the View form is displayed and Edit form is hidden correctly");
Assert(Employee_Name_DataCard2.Default = "Diana Prince", "Checking if the selected record in the table display correctly in view form");

- testCaseName: Test Table Control - Validate the Selected Record in Form
testCaseDescription: Verify that selected record in the table display correctly in view form.
testSteps: |
SetProperty(Table1.SelectedItems, Table(First(Table1.Items)));
Assert(Employee_Name_DataCard2.Default = "George Clooney", "Checking if the selected record in the table display correctly in view form");

- testCaseName: Test Edit Form through Edit Button
testCaseDescription: Verify that Edit form is visible on click of Edit button.
testSteps: |
Select(btnEdit);
Assert(Form1.Visible = true && FormViewer1.Visible = false, "Checking if the Edit form is displayed and View form is hidden correctly");

- testCaseName: Test Form Control in Edit Mode - Validate Mode
testCaseDescription: Verify that Form control is in Edit mode.
testSteps: |
Assert(Form1.DefaultMode = 0, "Checking if the form control is in edit mode during edit operation");

- testCaseName: Test Edit Form through updating field value
testCaseDescription: Verify that Edit form through updating field value.
testSteps: |
SetProperty(Department_DataCard1.Default, {Id:681470003,Value:"Sales"});
SetProperty(DOB_DataCard1.Default, DateTime(1983,01,09,10,0,0));
SetProperty(Email_DataCard1.Default, "xyz123@abc.com");
Select(btnUpdate);
SetProperty(Table1.SelectedItems, Table(First(Table1.Items)));
Select(Table1, 1);
Wait(FormViewer1, "Visible", true);
Assert(DOB_DataCard2.Default = "1/9/1983 10:00 AM", "Check if the DOB displays '01/09/1983 10:00 AM'.");
Assert(Email_DataCard2.Default = "xyz123@abc.com", "Checking if the email value updated to new value");
Assert(CountRows('DataCardValue12'.SelectedItems) = 1, "Check if only one item is selected in Department Field.");
Assert(Form1.Visible = false && FormViewer1.Visible = true, "Checking if the Edit form is displayed and View form is hidden correctly");


#
#
# - testCaseName: Test Form Control in Edit Mode - Validate Mode
# testCaseDescription: Verify that Form control is in edit mode during edit operation.
# testSteps: |
# SetProperty(Form2.DefaultMode, 0);
# Assert(Form2.DefaultMode = 0, "Checking if the form control is in edit mode during edit operation");

# - testCaseName: Test Form Control in Edit Mode - Edit Value of Form Controls
# testCaseDescription: Verify that Form control is in edit mode during edit operation.
# testSteps: |
# SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"});
# SetProperty(Address_DataCard2.Default, "152 South Cross Street");
# SetProperty(Email_DataCard2.Default, "xyz@abc.com");
# SetProperty(Phone_Number_DataCard2.Default, "0987654321");
# SetProperty(DOB_DataCard3.Default, DateTime(1983,01,09,09,0,0));
# Select(btnEdit);
# SetProperty(Table1.SelectedItems, Table(First(Table1.Items)));
# Assert(Email_DataCard2.Default = "xyz@abc.com", "Checking if the email value updated to new value");
# Assert(Phone_Number_DataCard2.Default = "0987654321", "Checking if the phone value updated to new value");
# Assert(DOB_DataCard3.Default = DateTime(1983,01,09,09,0,0), "Check if the DOB displays '01/09/1983 09:00 AM'.");


# # Form control test cases

# - testCaseName: Navigate to New Employee Form Control
# testCaseDescription: Verify that the Form Navigate to the new Employee form.
# testSteps: |
# Select(btnNew);

# - testCaseName: Test Employee_Name_DataCard2 - Default Value
# testCaseDescription: Verify that the Employee Name field displays the default value correctly.
# testSteps: |
# SetProperty(Employee_Name_DataCard2.Default, "David Benjamin12");
# Assert(Employee_Name_DataCard2.Default = "David Benjamin12", "Check if the Employee Name displays 'James Clear'.");

# - testCaseName: Test Gender_DataCard2 - Default Value
# testCaseDescription: Verify that updating the Gender field reflects correctly.
# testSteps: |
# SetProperty(Gender_DataCard2.Default, {Id:681470001,Value:"Female"});
# Assert(CountRows('DataCardValue7'.SelectedItems) = 1, "Check if only one item is selected in Gender Field.");

# - testCaseName: Test DOB_DataCard3 - DateTime Value
# testCaseDescription: Verify that setting DateTime in the DOB field reflects correctly.
# testSteps: |
# SetProperty(DOB_DataCard3.Default, DateTime(1975,01,01,05,0,0));
# Assert(DOB_DataCard3.Default = DateTime(1975,01,01,05,0,0), "Check if the DOB displays '01/01/1975 05:00 AM'.");

# - testCaseName: Test Department_DataCard2 - Default Value
# testCaseDescription: Verify that the Department field displays the default value correctly.
# testSteps: |
# SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"});
# Assert(CountRows('DataCardValue8'.SelectedItems) = 1, "Check if only one item is selected in Department Field.");

# - testCaseName: Test Address_DataCard3 - Default Value
# testCaseDescription: Verify that the Address field displays the default value correctly.
# testSteps: |
# SetProperty(Address_DataCard3.Default, "100 North Cross Street");
# Assert(Address_DataCard3.Default = "100 North Cross Street", "Check if the Address displays '152 South Cross Street'.");

# - testCaseName: Test Email_DataCard2 - Default Value
# testCaseDescription: Verify that the Email field displays the default value correctly.
# testSteps: |
# SetProperty(Email_DataCard2.Default, "DavidBenjamin@abc.com");
# Assert(Email_DataCard2.Default = "DavidBenjamin@abc.com", "Check if the Email displays 'DavidBenjamin@abc.com'.");

# - testCaseName: Test Phone_Number_DataCard2 - Default Value
# testCaseDescription: Verify that the Phone Number field displays the default value correctly.
# testSteps: |
# SetProperty(Phone_Number_DataCard2.Default, "1112223344");
# Assert(Phone_Number_DataCard2.Default = "1112223344", "Check if the Phone Number displays '1112223344'.");

# - testCaseName: Test Save Functionality of the New Employee Form Control
# testCaseDescription: Verify that the Employee data in the form saved correctly.
# testSteps: |
# Select(btnSubmit);
# Assert(CountRows(Table1.Items) = 14, "Checking if Table displays correct number of items");

# - testCaseName: Test Reset Functionality of the New Employee Form Control
# testCaseDescription: Verify that the Employee data in the form is reset to default value.
# testSteps: |
# SetProperty(Employee_Name_DataCard2.Default, "John Benjamin");
# SetProperty(Gender_DataCard2.Default, {Id:681470001,Value:"Female"});
# SetProperty(DOB_DataCard3.Default, DateTime(1975,01,01,05,0,0));
# SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"});
# SetProperty(Address_DataCard3.Default, "152 South Cross Street");
# SetProperty(Email_DataCard2.Default, "JohnBenjamin@abc.com");
# SetProperty(Phone_Number_DataCard2.Default, "1112223344");
# Select(btnReset);
# Wait(Employee_Name_DataCard2, "Default","");
# Assert(Employee_Name_DataCard2.Default = "", "Check if the Employee Name displays default value.");
# Assert(DOB_DataCard3.Default = DateTime(1980,01,01,03,0,0), "Check if the DOB displays '01/01/1980 03:00 AM'.");
# Assert(CountRows('DataCardValue8'.SelectedItems) = 1, "Check if only one item is selected in Department Field.");

testSettings:
headless: false
locale: "en-US"
recordVideo: true
extensionModules:
enable: true
browserConfigurations:
- browser: Chromium
channel: msedge

environmentVariables:
users:
- personaName: User1
emailKey: user1Email
passwordKey: NotNeeded
Loading