Share this page

# Enhance SAP GUI scripts

This topic describes how to enhance SAP GUI protocol scripts.

In this topic:

## Insert steps interactively into an SAP GUI script

After recording, you can manually add steps to the script in either the Editor or Step Navigator. In addition to manually adding new functions, you can add new steps interactively for SAP GUI Vusers, directly from the snapshot. Using the right-click menu, you can add object-related steps.

When adding a step from within a snapshot, VuGen uses the Active Screen capability and determines the ID of each object in the SAP GUI client window (unless you disabled Active Screen snapshots in the SAPGUI > General recording options).

To insert a step interactively for a specific object:

1. Verify that you recorded the script when Active Screen snapshots were selected in the SAPGUI General node of the Recording Options (enabled by default).

2. Click within the Snapshot pane.

3. Move the mouse over the object for which you want to add a function. Make sure that VuGen recognizes the object and encloses it with a box.

4. Right-click the object, click Insert New Step, and then select a step from the list of steps that are available for the object.

   The step's Properties dialog box opens, with the Control ID of the object when relevant.

5. Enter a name for the object in the Description box and lick OK. VuGen inserts the new step after the selected step.

   Note: You can get the Control ID of the object for the purpose of pasting it into a specific location. To do this, select Copy Control ID from the right-click menu. You can past it into a Properties box or directly into the code from the Script view.

Back to top

## Add verification functions

When working with optional or dynamic windows or frames, you can use verification functions to determine if the window or object is available. An optional window is a window that does not consistently open during the SAP session. This function allow the Vuser script to continue running even if an optional window opens or an exception occurs.

The first example checks if a window is available. If the window is available, the Vuser closes it before continuing.

    if (!sapgui_is_object_available("wnd[1]"))
            sapgui_call_method("{ButtonID}",
                "press",
                LAST,
                AdditionalInfo=info1011");
    sapgui_press_button(.....)

The next example illustrates a dynamic object in the ME51N transaction. The Document overview frame is optional, and can be opened/closed by the Document overview on/off button.

The code checks the text on the Document overview button. If the text on the button shows Document overview on, click the button to close the Document overview frame.

        if(sapgui_is_object_available("tbar[1]/btn[9]"))
        {
            sapgui_get_text("Document overview on/off button",
                "tbar[1]/btn[9]",
                "paramButtonText",
                LAST);
            if(0 == strcmp("Document overview off", lr_eval_string("{paramButtonText}")))
                sapgui_press_button("Document overview off",
                    "tbar[1]/btn[9]",
                    BEGIN_OPTIONAL,
                        "AdditionalInfo=sapgui1013",
                    END_OPTIONAL);
        }

Back to top

## Retrieve information

When working with SAP GUI Vusers, you can retrieve the current value of an SAP GUI object using the sapgui_get_<xxx> functions. You can use this value as input for another business process, or display it in the output log.

The following example illustrates how to save part of a status bar message in order to retrieve the order number.

1. Navigate to the point where you want to check the status bar text, and select Insert New Step. Select the sapgui_status_bar_get_type function. This verifies that the Vuser can successfully retrieve text from the status bar.

2. Insert an if statement that checks if the previous statement succeeded. If so, save the value of the argument using sapgui_status_bar_get_param.

   This sapgui_status_bar_get_param function saves the order number into a user-defined parameter. In this case, the order number is the second index of the status bar string.

       sapgui_press_button("Save (Ctrl+S)",
           "tbar[0]/btn[11]",
           BEGIN_OPTIONAL,
               "AdditionalInfo=sapgui1038",
           END_OPTIONAL);
       sapgui_status_bar_get_type("Status");
       if(0==strcmp(lr_eval_string("{Status}"),"Success"))
         sapgui_status_bar_get_param("2", " Order_Number ");

   During test execution, the Execution log indicates the value and parameter name:

       Action.c(240): Pressed button " Save (Ctrl+S)"
       Action.c(248): The type of the status bar is "Success"
       Action.c(251): The value of parameter 2 in the status bar is "33232"

Back to top

## Save date information

When creating scripts that use dates, your script may not run properly. For example, if you record the script on June 2, and replay it on June 3, the date fields will be incorrect. Therefore, you need to save the date to a parameter during text execution, and use the stored value as input for other date fields. To save the current date or time during script execution, use the lr_save_datetime function. Insert this function before the function requiring the date information. Note that the format of the date is specific to your locale. Use the relevant format within the lr_save_datetime function. For example, for month.day.year, specify "`%m.%d.%Y`".

In the following example, lr_save_datetime saves the current date. The sapgui_set_text function uses this value to set the delivery date for two days later.

    lr_save_datetime("%d.%m.%Y", DATE_NOW + (2 * ONE_DAY),              "paramDateTodayPlus2");
    sapgui_set_text("Req. deliv.date",
            "{paramDateTodayPlus2}",
            "usr/ctxtRV45A-KETDAT",
            BEGIN_OPTIONAL,
                "AdditionalInfo=sapgui1025",
            END_OPTIONAL);

Back to top

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1 All View Local Help Center View Online Help Center Version: