I've written a test codeunit that is supposed to invoke an action on a page that opens a window, so I've defined a PageHandler in the HandlerFunctions property. However, the tests still throw an "Unhandled UI" error.
Here is the full Test Codeunit:
codeunit 78000 "Changelog Action Test CCL"
{
Description = 'Change Log Plus Action';
Subtype = Test;
trigger OnRun();
begin
IsInitialized := false;
OpenChangeLogPlus_ItemList();
OpenChangeLogPlus_ItemCard();
end;
var
LibraryRandom: Codeunit "Library - Random";
LibrarySetupStorage: Codeunit "Library - Setup Storage";
LibraryTestInitialize: Codeunit "Library - Test Initialize";
LibraryVariableStorage: Codeunit "Library - Variable Storage";
Assert: Codeunit "Library Assert";
IsInitialized: Boolean;
sEntryFilter: Text;
[Test]
[HandlerFunctions('ChangeLogPlusPageHandler')]
procedure OpenChangeLogPlus_ItemList()
var
recItem: Record Item;
pagItemList: TestPage "Item List";
begin
// [SCENARIO #0001]
// [GIVEN] A randomly selected item on the Item List page
Initialize();
GetRandomItem(recItem);
pagItemList.OpenView();
pagItemList.GoToRecord(recItem);
// [WHEN] Invoking the "Change Log Plus" action
pagItemList."Change Log Plus CCL".Invoke();
pagItemList.Close();
// [THEN] Filter matches Item Table No. only
Assert.AreEqual(recItem.GetFilters, sEntryFilter, 'Filter doesn''t match');
end;
[Test]
[HandlerFunctions('ChangeLogPlusPageHandler')]
procedure OpenChangeLogPlus_ItemCard()
var
recItem: Record Item;
pagItemCard: TestPage "Item Card";
begin
// [SCENARIO #0001]
// [GIVEN] A randomly selected item on the Item Card page
Initialize();
GetRandomItem(recItem);
pagItemCard.OpenView();
pagItemCard.GoToRecord(recItem);
// [WHEN] Invoking the "Change Log Plus" action
pagItemCard."Change Log Plus CCL".Invoke();
pagItemCard.Close();
// [THEN] Filter matches Item Table No. & Primary Key 1 only
Assert.AreEqual(recItem.GetFilters, sEntryFilter, 'Filter doesn''t match');
end;
[PageHandler]
procedure ChangeLogPlusPageHandler(var ChangeLogPlus: Page "Change Log Plus CCL");
var
recChangeLogEntry: Record "Change Log Entry";
begin
Clear(recChangeLogEntry);
ChangeLogPlus.GetRecord(recChangeLogEntry);
sEntryFilter := recChangeLogEntry.GetFilters();
ChangeLogPlus.Close();
end;
local procedure CreateItems(iCount: Integer)
var
recItem: Record Item;
iIndex: Integer;
begin
if iCount <= 0 then
iCount := 1;
while iIndex < iCount do begin
Clear(recItem);
recItem."No." := LibraryRandom.RandText(8);
if recItem.Insert(true) then
iIndex = 1;
end;
end;
local procedure GetRandomItem(var recItem: Record Item)
var
iSkip: Integer;
begin
recItem.FindFirst();
iSkip := LibraryRandom.RandIntInRange(0, recItem.Count - 1);
recItem.Next(iSkip);
end;
local procedure Initialize();
begin
LibraryTestInitialize.OnTestInitialize(Codeunit::"Changelog Action Test CCL");
ClearLastError();
LibraryVariableStorage.Clear();
LibrarySetupStorage.Restore();
if IsInitialized then
exit;
LibraryTestInitialize.OnBeforeTestSuiteInitialize(Codeunit::"Changelog Action Test CCL");
LibraryRandom.Init();
// CUSTOMIZATION: Prepare setup tables etc. that are used for all test functions
CreateItems(5);
IsInitialized := true;
Commit();
// CUSTOMIZATION: Add all setup tables that are changed by tests to the SetupStorage, so they can be restored for each test function that calls Initialize.
// This is done InMemory, so it could be run after the COMMIT above
// LibrarySetupStorage.Save(DATABASE::"[SETUP TABLE ID]");
LibraryTestInitialize.OnAfterTestSuiteInitialize(Codeunit::"Changelog Action Test CCL");
end;
}
And here is the procedure that is executed by the invoked action:
procedure OpenChangeLogFromRec(recordVariant: Variant; filterKeyBoolean: Boolean)
var
recChangeLogEntry: Record "Change Log Entry";
cuDataTypeManagement: Codeunit "Data Type Management";
inputRecordRef: RecordRef;
invalidErr: Label 'Not a valid Record: %1', Comment = '%1: The Variant passed to the procedure.';
begin
if not cuDataTypeManagement.GetRecordRef(recordVariant, inputRecordRef) then
Error(invalidErr, Format(recordVariant));
Clear(recChangeLogEntry);
recChangeLogEntry.SetRange("Table No.", inputRecordRef.Number);
if filterKeyBoolean then
recChangeLogEntry.SetRange("Primary Key Field 1 Value", inputRecordRef.KeyIndex(1).FieldIndex(1).Value);
Page.Run(Page::"Change Log Plus CCL", recChangeLogEntry);
end;
Lastly, here's the error message, as well as the page ID.

Report
All responses (
Answers (