Use of Request Page Handler Function in Automated Testing

To create tests that can be automated, you must handle cases when user interaction is requested by the code that is being tested. D365 BC provides UI handlers that run instead of the requested UI.

UI handlers provide the same exit state as the UI, For Example-

Test function has a FunctionType of RequestPageHandler that handles the Request Page while running the Test function.

If Test Function calls the Request Page, then we need to define the RequestPageHandler function, and this function will respond based on the response method defined within RequestPageHandler function.

If we will not define the RequestPageHandler and any request page comes up while running the Test Codeunit, then the test case will fail with the following error message-

To handle these types of run time issue while running the Test Codeunits, we need to follow below steps-

Step 1:  We need to define FunctionType as [RequestPageHandler] and procedure name as TransferToInvoiceHandler. In Parameters, define the Test Request Page and assign the “Name” of the Report ID for which Request Page is belongs to. In our case its Report ID 1094, hence we have defined the “Name “ as “Job Transfer to Sales Invoice “. Below screenshot for reference-

Step 2:  Then Inside TransferToInvoiceHandler we can define the response Method. In this case we have responded as OK. So, when Request Page is open then by this handler it will respond OK.

Step 3:  Then we need to go into the Test Function which contains the expected Request Page. In our case function " Test001_JobCreateSalesInvoice " contains the expected Request Page, so we need to go on to the function " Test001_JobCreateSalesInvoice " and Update the HandlerFunction as RequestPageHandler. In our case name of RequestPageHandler is TransferToInvoiceHandler, so defined the name of handler function. Below Screenshot for your reference-

Step 4: Once you define the RequestPageHandler Function, then the test function will execute successfully.


Hope this helps for those who are doing the automated testing in D365 Business Central.

Comment List