Hi
I’m doing some tests with page testing. Nice feature, but there is a lot to consider
For the moment I have two questions. First have a look at the scenario :
OnRun()
Code;
[Test] Code()
// Opens a blank customer card test page.
Customerpage.OPENNEW;
Customerpage."No.".SETVALUE('1234');
MESSAGE('A first message');
MESSAGE('A second message');
Customerpage.CLOSE;
[MessageHandler] FirstMsgHandler(_Msg : Text[1024])
IF _Msg <> 'A first message' THEN BEGIN
ERROR('Unexpected msg in FirstMsgHandler');
END;
[MessageHandler] SecondMsgHandler(_Msg : Text[1024])
IF _Msg <> 'A second message' THEN BEGIN
ERROR('Unexpected msg in SecondMsgHandler');
END;
Explanations to the above code:
- Codeunit is defined as a testing codeunit
- The OnRun trigger calls test function "code"
- Function „code“, property "HandlerFunctions" has the value of the 2 functions "FirstMsgHandler" and "SecondMsgHandler"
So now the questions:
Question 1:
Test fails, because FirstMsgHandler throws an error because of wrong text. How to fix? Can one test function properly handle more than 1 message? Or should the MessageHandler handle more than 1 text?
Question 2:
If in function code „MESSAGE('A second message')" is deactivated, I get an error which says „The following UI handlers were not executed: SecondMsgHandler“. Obviously I don’t understand how and when the message handlers are triggered and how the messages are tied to a specific handler if more than one handler is present..... Maybe some of you knows more about it.
Thx in advance
Thomas
Comments
Software Design Engineer II
Dynamics NAV Office 365
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks for your help. Given to the assumption, that we don't want to change existing object code, is there a workaround?
Thanks in advance.
Thomas
Question 1:
Test fails, because FirstMsgHandler throws an error because of wrong text. How to fix? Can one test function properly handle more than 1 message? Or should the MessageHandler handle more than 1 text?
The first messagehandler will catch both messages. You can use enqueue/dequeue to identify the text of the expected message, something like this:
LibraryVariableStorage.Enqueue('A first message');
MESSAGE('A first message');
LibraryVariableStorage.Enqueue('A second message');
MESSAGE('A second message');
And then in the messagehandler you can do like
LibraryVariableStorage.Dequeue(TheMessage);
IF _Msg <> TheMessage THEN BEGIN
ERROR('Unexpected msg in MsgHandler');