Testcodeunits: Strange behavior when executing an action through invoke

As you can already see from the title, I noticed a strange behavior when executing page actions on a testpage through invoke(). I am working on BC16.
I created a "Sales Header" in my codeunit and added a few "Sales line"'s. Then I wanted to load the page by a TestPage object and click the action "Post." Here is the code:
codeunit 60001 "Test Codeunit"
{
    Subtype = Test;

    trigger OnRun()
    begin

    end;

    [Test]
    procedure TestOne()
    var
        SalesHeader: Record "Sales Header";
        SalesLine: Record "Sales Line";
        SalesOrder: TestPage "Sales Order";
    begin
        // Create a Sales Order with "External Document No", and set the "Due Date" to the past (-10)
        SalesHeader.Init();
        SalesHeader.Validate("Document Type", SalesHeader."Document Type"::Order);
        SalesHeader.Validate("Sell-to Customer No.", '01121212');
        SalesHeader.Validate("Due Date", Workdate() - 10);      
        SalesHeader.Validate("External Document No.", '123'); 
        SalesHeader.Insert(true);

        // Create 2 Corresponding random Sales Lines
        CreateSalesLine(SalesHeader, SalesLine.Type::Item);
        CreateSalesLine(SalesHeader, SalesLine.Type::Item);

        // Goto to the Corresponding Sales Order Page and post that stuff.
        SalesOrder.OpenEdit();
        SalesOrder.GoToKey(SalesHeader."Document Type", SalesHeader."No.");
        SalesOrder.Post.Invoke();
    end;
}

I now expect that the execution of the test informs me that I have not handled the UI window for selecting the posting type, as it would appear if I used the web client normally:
krx96suta7ln.png

Instead of that, it informs me that i am leaving the Page without releasing:
ishj050ee7zl.png

That would correspond to this Message in the web client when leaving an order:
f8z9mn17fzw7.png

Does anyone know whats wrong here? Why am i leaving the Page in my test and not start the posting?

Thanks for your time!

Best Answer

Answers

  • ImperatorMingImperatorMing Member Posts: 13
    Thanks, i already did this and it works for me.

    But I am still amazed. As a user, I can also post without realsing before. Why do I have to do this explicitly in my test? Seems strange.

    Nerver the less, thanks for help.
Sign In or Register to comment.