Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Use test pages in AL to automate tests that simulate user interactions with the application. You can:
- View or change the value of a field on a test page.
- View the data on page parts.
- View or change the value of a field on a subpage.
- Filter the data on a test page.
- Invoke page actions exposed by the test page.
- Navigate to different records.
Open or handle a test page
You can open a test page directly or handle a page opened by application code:
- Declare a
TestPagevariable and open it by using one of these methods: - Register a
PageHandlerorModalPageHandlermethod with a test-page parameter in the test method'sHandlerFunctionsattribute. Then run application code that opens the corresponding page. Learn more in Create handler methods. - Call the Trap method before application code opens the corresponding nonmodal page. The matching page is attached to the test-page variable when it opens. Use a
ModalPageHandlerfor modal pages.
Note
Choose the test method's TransactionModel attribute to match the scenario. AutoRollback rolls back the test transaction, whereas AutoCommit commits it. With None, each test-page call has its own transaction. Configure test-runner isolation when committed changes must also be rolled back.
Note
Test methods and code on test pages run on the Business Central Server instance, even though they simulate client interactions.
Learn more about the AL methods available on test pages in TestPage data type.
Access fields on test pages
Access fields on a test page by using dot notation. For example, if a test page variable named CustomerCard represents the Customer Card page, use CustomerCard.Name to access its Name field.
These fields are instances of the TestField data type, so you can use the corresponding AL methods to work with them. To assign the value of the No. field to a variable named CustNo, write CustNo := CustomerCard."No.".Value in your code. To write a value in the Address field, use CustomerCard.Address.Value := '192 Market Square'.
Access page parts and subpages
Access page parts and subpages on a test page by using dot notation.
These are instances of the TestPart data type, so you can use the corresponding AL methods to work with them.
For example, compare the No. field on the Customer Card page with the No. field on its sales-history FactBox. The following fragment assumes that CustomerCard is an open TestPage "Customer Card" variable positioned on a customer record. SalesHistSelltoFactBox is the part control's name, not the name of its page object.
if CustomerCard."No.".Value <> CustomerCard.SalesHistSelltoFactBox."No.".Value then
Error('Page part data is not updated.');
Filter data on test pages
Use the AL methods on the TestFilter data type to filter the data available on a test page. For example, filter the Customer List page by a range of values in the No. field. This fragment assumes that CustomerList is an open TestPage "Customer List" variable.
CustomerList.Filter.SetFilter(CustomerList.Filter."No.", '20000..30000');
Invoke actions on test pages
Access page actions exposed by the test page by using dot notation. Call the Invoke method to invoke an action.
Actions are instances of the TestAction data type. Use TestAction.Enabled() and TestAction.Visible() to inspect an action's state. These methods don't change that state. Invoking a disabled action doesn't execute it.
Use the Yes, No, OK, or Cancel method to retrieve the corresponding system action when it's available. Then call Invoke to execute it. For example, use CustomerCard.OK().Invoke() to invoke an available OK action.
Navigate among records
To simulate moving to different items on a list page or to different records on a card page, use one of these navigation methods:
- Next method
- Previous method
- First method
- Last method
- GoToRecord method
- GoToKey method
- FindFirstField method
- FindNextField method
- FindPreviousField method
Navigation operates within the page's current dataset and filters. GoToRecord requires a record from the page's source table. GoToKey requires values for all primary-key fields. Filter large datasets before searching.
Related information
Testing the application overview
Test the advanced sample extension