After two previous posts I thought all is done about test automation and graphic user interface, reports and pages. But this week I notice there is a new question on the table: How to manage report request page. Surprisingly, I haven´t found too much practical information about this. I think this happens due is very similar to modal page handler, but any case I made a hands-on.
Lab: Copy Item.
For our hands-on we will test standard “Copy Item” report this way:
[Test]
[HandlerFunctions('RequestPageHandler')]
procedure CopyItem()
var
TestItem: Record Item;
begin
//Given
FakeCreateItem(GlobalSourceItem);
SetNewItemGlobalNo();
asserterror TestItem.get(NewItemNoGlobal);
//When
Report.RunModal(Report::"Copy Item", true, false);
//then
TestItem.get(NewItemNoGlobal);
end;
This new test function creates a new item and copy it in a new item number generated in “SetNewItemGlobalNo” function. Before running “Copy Item” report, we check that Item does not exist yet. After report running we check that then the new item exists.
“Copy Item” report has many options in its request page, so we have to fill at least basic ones. We do this feature declaring a request page handler function:
[RequestPageHandler]
procedure RequestPageHandler(var CopyItem: TestRequestPage "Copy Item");
begin
CopyItem.SourceItemNo.SetValue(GlobalSourceItem."No.");
CopyItem.TargetItemNo.SetValue(NewItemNoGlobal);
CopyItem.OK().Invoke();
end;
With the code above we set the source and target item number, and then we push ok button with “invoke” statement.
As we can see, very similar to modal page handling, but for me was important to check it and make a non-hello-world example.
There is also another handler that can be raised before report runs, report handler. I said “can be raised” because this is an optional handler in test functions: if you execute a report inside a test function without this handler it does not crash unlike other handlers, request page handler included. This is the behavior of the test function execution without request page handler:
*This post is locked for comments