Dealing with Messages

Up to now, we have treated messages passively – if they arrive, they are recorded in the log. However, eCATT offers better ways for processing messages. The main way is to use the MESSAGE…ENDMESSAGE block.

The simplest function of the MESSAGE…ENDMESSAGE block is to collect all messages that occur from commands enclosed between the MESSAGE and ENDMESSAGE commands. The MESSAGE command also allows you to specify how eCATT reacts to particular categories of messages or even to specific messages.

When you recorded the transaction EC_TUTORIAL_SAPGUI and made a successful booking, the system delivered a success message. Each time that you execute that test script, you want to know that that particular success message occurs. Therefore, you define a rule, in the command interface of the MESSAGE command, which will cause the script to fail if the message does not occur.

In the first part of this exercise, you will create a MESSAGE…ENDMESSAGE block that encloses no commands. Using the start options, you will cause the execution to terminate when the required message does not appear. In the second part of the exercise, you will position the ENDMESSAGE command so that the block contains the SAPGUI commands that you recorded earlier. Assuming the transaction replays correctly, the required message will appear and the test script will pass. Finally, you will write a few lines of code to extract the variable part of the message so that it is available for possible further use.

Procedure

       1.      In the command editor, double click the command interface of the SAPGUI command that contains the message text Flight was booked successfully. If you were careful during the recording, that will be the last SAPGUI command in your script.

The screenshot above shows the command interface displayed in the easy mode . Beside the Message node, are the message type (S), message ID (ECDEMO), and the message number (024). The variable part of this message is recorded beside the Parameter 1 node. You cannot parameterize the message parts of a SAPGUI command interface.

       2.      Add a few empty lines in the command editor before the SAPGUI commands. Place the cursor before the existing commands.

       3.      Use the Pattern function to insert the MESSAGE…ENDMESSAGE block. Accept the default interface name as shown.

       4.      Double click the command interface (MSG_1) of the MESSAGE command. The command interface is displayed in the structure editor to the right of the command editor.

       5.      Choose  and enter the following:

Field

Entry

MODE

'R'

MSGTYP

'S'

MSGID

'ECDEMO'

MSGNR

024

You have defined a rule that requires a particular message to occur.

       6.      In the start options, change the error behavior to terminate when an error occurs.

       7.      Execute the script.

The log shows that the required message did not appear.

       8.      Go back to the test script and cut and paste the ENDMESSAGE command so that it is after the SAPGUI commands.

       9.      Execute the test script. This time the log should be green.

   10.      As you can see, the required message has occurred. Depending on what you recorded, you may get other messages. As we have not specified any rules to deal with them, they will be handled by default rules.

   11.      Go back to the test script editor and add the following lines to the end of the script:

V_MESSAGES = E_MSG_1[1]-MIDX.

E_BOOKINGNUMBER = E_MSG_1[V_MESSAGES]-MSGV1.

LOG ( E_BOOKINGNUMBER ).

The field MIDX of the first row of the ENDMESSAGE command interface always contains the number of messages captured in the ENDMESSAGE command. Here, you assign that value to a parameter V_MESSAGES. (Instead of E_MSG_1[1]-MIDX, which was required in previous releases, you can use the special parameter &TFILL).

The second statement assigns the first variable part of the last message to the parameter E_BOOKINGNUMBER. For the sake of simplicity, we make the assumption that the message is always the last one. More generally, you could loop through the command interface to find the message that you are interested.

The third statement is just a convenient command to simply show the extracted value being used.

   12.      In the parameter list, create the export parameter E_BOOKINGNUMBER and the local variable V_MESSAGES. You can use  to toggle between display of parameters and command interfaces in the parameter list.

   13.      Save and execute the test script.

Result

You have captured a message and read the value from its variable part.