我正在尝试模拟用户,在列表页面(即项目列表)上选择一条记录。这是为了测试一个程序,该程序打开所述列表页面,等待用户输入,如果用户按下确定,则将列表页面中的选定行作为行添加到文档中(即采购行/采购标题)
[Test]
[HandlerFunctions('ItemListOkModalPageHandler')]
procedure TestAddItemLineItemList()
var
LRec_PurchaseHeader: Record "Purchase Header";
LRec_PurchaseLine: Record "Purchase Line";
LC_PageHelper: Codeunit "Page Helper";
begin
//[GIVEN] given
CreatePurchaseOrder(LRec_PurchaseHeader);
LRec_PurchaseLine.SetRange("Document Type", LRec_PurchaseHeader."Document Type");
LRec_PurchaseLine.SetRange("Document No.", LRec_PurchaseHeader."No.");
LRec_PurchaseLine.SetRange(Type, "Purchase Line Type"::Item);
GC_LibraryAssert.RecordIsEmpty(LRec_PurchaseLine);
//[WHEN] when
LC_PageHelper.AddMultiplePurchaseLines(LRec_PurchaseHeader);
//[THEN] then
GC_LibraryAssert.RecordCount(LRec_PurchaseLine, 1); // error happens here
end;
[ModalPageHandler]
procedure ItemListOkModalPageHandler(var PTP_ItemList: TestPage "Item List");
begin
PTP_ItemList.First();
PTP_ItemList.OK().Invoke();
end;
尝试以这种方式执行此操作时,我收到以下错误消息:
Error:
Assert.RecordCount failed. Expected number of Purchase Line entries: 1. Actual: 0.
任何建议,我做错了什么?
编辑:程序代码 AddMultiplePurchaseLines
procedure AddMultiplePurchaseLines(PRec_PurchaseHeader: Record "Purchase Header")
var
LRec_Item: Record Item;
LP_ItemList: Page "Item List";
begin
PRec_PurchaseHeader.TestField(Status, "Purchase Document Status"::Open);
if GuiAllowed then begin
LP_ItemList.LookupMode(true);
if LP_ItemList.RunModal() = Action::LookupOK then begin
LRec_Item.SetFilter("No.", LP_ItemList.GetSelectionFilter());
AddPurchaseOrderItemLines(PRec_PurchaseHeader, LRec_Item);
end;
end;
end;