- Automated Testing in Microsoft Dynamics 365 Business Central
- Luc van Vugt
- 405字
- 2021-06-24 14:56:51
Pillar 5 – Test pages
Goal: Understand what test pages are and learn how to apply them when testing the UI.
The initial trigger for adding the testability framework to the platform was to get away from testing the business logic through the UI. The testability framework enabled headless, and thus faster, testing of the business logic. And this is how the testability framework was implemented in NAV 2009 SP1. Pure headless testing. It included everything of the four pillars discussed so far, even though test isolation was implemented in a different way than it is today. It was previously not possible to test the UI.
Moving ahead, it became clear that sole headless tests excluded too much. How could we test business logic that typically resides on pages? For example, consider a product configurator in which options are displayed or hidden depending on values entered by the user. So, with NAV 2013, Microsoft added the fifth pillar to the testability framework: test pages.
A test page is a logical representation of a page and is strictly handled in memory displaying no UI. To define a test page, you need to declare a variable of the TestPage type:
PaymentTerms: TestPage "Payment Terms";
A TestPage variable can be based on any page existing in the solution.
A test page allows you to mimic a user carrying out the following actions:
- Accessing the page
- Accessing its sub parts
- Reading and changing data on it
- Performing actions on it
You can achieve this by using the various methods that belong to the test page object. Let's build a small codeunit in which we use a couple of them:
codeunit 60003 MyFourthTestCodeunit
{
Subtype = Test;
[Test]
procedure MyFirstTestPageTestFunction()
var
PaymentTerms: TestPage "Payment Terms";
begin
PaymentTerms.OpenView();
PaymentTerms.Last();
PaymentTerms.Code.AssertEquals('LUC');
PaymentTerms.Close();
end;
[Test]
procedure MySecondTestPageTestFunction()
var
PaymentTerms: TestPage "Payment Terms";
begin
PaymentTerms.OpenNew();
PaymentTerms.Code.SetValue('LUC');
PaymentTerms."Discount %".SetValue('56');
PaymentTerms.Description.SetValue(
PaymentTerms.Code.Value()
);
ERROR('Code: %1 \ Discount %: %2 \Description: %3',
PaymentTerms.Code.Value(),
PaymentTerms."Discount %".Value(),
PaymentTerms.Description.Value()
);
PaymentTerms.Close();
end;
}
So, we get the following as a result:

For a complete listing of all test page methods, you can access the following URLs:
TestPage: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testpage/testpage-data-type
TestField: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testfield/testfield-data-type
TestAction: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testaction/testaction-data-type
If you are running Microsoft 365 Business Central on-premises and you want to run tests using test pages, be sure that you have the Page Testability module installed:
