# TestPage.Trap() Method
> Version: _Available or changed with runtime version 1.0._
Traps the next test page that is invoked and assigns it to the test page variable.
## Syntax
```al
 TestPage.Trap()
```
## Parameters
TestPage
Type: testpage-data-type
An instance of the testpage-data-type data type.
## Remarks
Only 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>.
## Example
This 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.
```al
local procedure TrapPage()

    begin
        CustomerCard.OpenEdit;
        CustomerStatistics.Trap(); // Next page invoked will be trapped and assigned to the CustomerStatistics variable
        CustomerCard."Customer/Item Statistics".Invoke(); // Invokes an action from the Customer Card page
        CustomerStatistics."Balance (LCY)".AssertEquals(0); // Now that the CustomerStatistics test page is open, use the variable to test the page

    end;

    var
        CustomerCard: TestPage "Customer Card";
        CustomerStatistics: TestPage "Customer Statistics";

```
## Related information
testpage-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

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. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/testpage/testpage-trap-method/
