{"title":"TestPage.Trap() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/testpage/testpage-trap-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testpage/testpage-trap-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testpage/testpage-trap-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Traps the next test page that is invoked and assigns it to the test page variable.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":143,"chars":37},{"level":2,"title":"Parameters","slug":"parameters","at":180,"chars":97},{"level":2,"title":"Remarks","slug":"remarks","at":277,"chars":256},{"level":2,"title":"Example","slug":"example","at":533,"chars":725},{"level":2,"title":"Related information","slug":"related-information","at":1258,"chars":136}],"text":"> Version: _Available or changed with runtime version 1.0._\nTraps the next test page that is invoked and assigns it to the test page variable.\n## Syntax\n```al\n TestPage.Trap()\n```\n## Parameters\nTestPage\nType: testpage-data-type\nAn instance of the testpage-data-type data type.\n## Remarks\nOnly non-modal pages can be trapped. To trap modal pages that you invoke with the RunModal method or the ../page/page-runmodal--method, you must use the ModalPageHandler method. See Create Handler Methods<../../devenv-creating-handler-methods>.\n## Example\nThis example shows how to use the Trap method to trap a call to open a test page so that the opened page is assigned to a variable.\n```al\nlocal procedure TrapPage()\n\n    begin\n        CustomerCard.OpenEdit;\n        CustomerStatistics.Trap(); // Next page invoked will be trapped and assigned to the CustomerStatistics variable\n        CustomerCard.\"Customer/Item Statistics\".Invoke(); // Invokes an action from the Customer Card page\n        CustomerStatistics.\"Balance (LCY)\".AssertEquals(0); // Now that the CustomerStatistics test page is open, use the variable to test the page\n\n    end;\n\n    var\n        CustomerCard: TestPage \"Customer Card\";\n        CustomerStatistics: TestPage \"Customer Statistics\";\n\n```\n## Related information\ntestpage-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}