SAP Succes story

Hi we are looking at a new testing tool and i love Robot framework but the client has some doubt about testing SAP with Robot framework and the SAP libraries.

Have some one some succes stories that the can/want to share?

Hi @atenwolde

Yes, it is actually rather fun to automate :slight_smile: You can use library: SapGuiLibrary With Robot Framework, in terms of success, its no different from the web or a Windows application, and it really comes down to the person creating and maintaining the suite/project. One thing that will differ heavily from SAP to Web is that of the business “knowings”, at least at my company, the transactional workings are split across people, as they all maintain there own areas, which makes someone who knows nothing or little in automating the correct outcome of a transaction, or the use of a transaction for how its intended hard without them sharing said information, and I’d say thats the biggest problem you could face.

I will share an example and the general basis as far as setup goes, in case you want to throw together a working demo for you’re clients.

Some things to be aware of:
→ You’ll need to disable the script popup within “customise local layout (alt+f12)” > options > Accessibility & Scripting > Scripting:

If you are unable to change these values or dont see them, then youll need to speak to your systems administrator, but youll want to disable/set false to those three checkboxes under “Enable scripting” (apologies on the SAP theme; it works best for me, and these options here are the same regardless of SAP versions)

Secondly, youll need a UI inspector, I use Scripting Tracker An example below is the password input field using the said inspector:

(there be others out there, but this works for me)

Other than that, its fairly straight-forward :slight_smile: Once you get comfortable with the locator struggle, you will almost definitely face it at times.

See below for an example of opening and running a transaction (I have ripped out parts of my current project for you, so I will keep the file structure visible and libraries):

sap_commons.robot:

*** Settings ***
Library     SapGuiLibrary       screenshots_on_error=True   screenshot_directory=./sap_runners/screenshots/
Library     DateTime
Library     OperatingSystem
Library     String
Library     Collections

*** Variables ***
${SAP_WIN_0}              /app/con[0]/ses[0]/wnd[0]
${SAP_WIN_1}              /app/con[0]/ses[0]/wnd[1]
${SAP_WIN_2}              /app/con[0]/ses[0]/wnd[2]
${SAP_MENU_SYSTEM}        ${sapWin0}/mbar/menu[4]
${SAP_TOOL_WIN_0_BAR_0}          ${sapWin0}/tbar[0]
${SAP_TOOL_WIN_0_BAR_1}          ${sapWin0}/tbar[1]
${SAP_TOOL_WIN_1_BAR_0}          ${sapWin1}/tbar[0]
${SAP_TOOL_WIN_1_BAR_1}          ${sapWin1}/tbar[1]

# SAP Connections:
&{CONNECTION_DICT}
...    HED=ECC6${SPACE}${SPACE}HED${SPACE}\[Note: Group/Server desc here]${SPACE}Dev${SPACE}System${SPACE}HANA
...    HEQ=ECC6${SPACE}${SPACE}HEQ${SPACE}\[Note: Group/Server desc here]${SPACE}QA${SPACE}system${SPACE}HANA
...    HBP=ECC6${SPACE}${SPACE}HBP${SPACE}\[Note: Group/Server desc here]

${USERNAME}     
${PASSWORD}     

Note: I have removed my server SAP names above but noted where they go^

main_sap_keywords.robot

*** Settings ***
Resource    ../resources/sap_commons.robot
Library     Process

*** Variables ***
${PROCESS}      ${Empty}

*** Keywords ***
launch sap.exe
     [Arguments]       ${wait_time}=5
     ${PROCESS}        process.start process        C:\\Program${SPACE}Files${SPACE}(x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe
     ${is_running}      process.is process running
     IF    ${is_running}
       set test variable      ${PROCESS}
       builtin.sleep          ${wait_time}
     END

Connect And Open ${env} Session
     [Documentation]    Connects and opens the given env connection and the maxmise window
     SapGuiLibrary.Connect To Session
     ${has_session}    run keyword and return status     SapGuiLibrary.connect to existing connection        ${CONNECTION_DICT.${env}}
     IF   ${has_session}
        fail    Session already active please close any open '${env}' connections.
     END
     Sapguilibrary.open connection      ${CONNECTION_DICT.${env}}
     SapGuiLibrary.maximize window    0

SAP Gui Login
     IF  '${USERNAME}' != '${NONE}'
           SapGuiLibrary.input text           ${SAP_WIN_0}/usr/txtRSYST-BNAME        ${username}
     ELSE
        fail    No username entered, please add -v username:username
     END

     IF  '${PASSWORD}' != '${NONE}'
           SapGuiLibrary.input password       ${SAP_WIN_0}/usr/pwdRSYST-BCODE        ${password}
     ELSE
        fail    No password entered, please add -v password:password
     END

     SapGuiLibrary.click element        ${SAP_WIN_0}/tbar[0]/btn[0]
     #TODO: capture failure on logon and return message
     Has System Messages
     Has Login Information Message
     Has Password Attempts Information Message

Has System Messages
    [Tags]   robot:private
    #TODO: log message value?
    TRY
        disable screenshots on error
        ${has_sys_messages}   SapGuiLibrary.get value    ${SAP_WIN_1}/usr/lbl[1,2]
        enable screenshots on error
        IF  "${has_sys_messages}" == "Message Text"
            send vkey           12
        END
    EXCEPT
       return from keyword
    END

Has Login Information Message
    [Tags]   robot:private
    ${info_message}      SapGuiLibrary.get value    /app/con[0]/ses[0]/wnd[0]/sbar
    IF  "${info_message}" != ""
         fail    ${info_message}
    END

Has Password Attempts Information Message
    [Tags]   robot:private
    TRY
        disable screenshots on error
        ${info_message}      SapGuiLibrary.get value    ${SAP_WIN_1}/usr/txtMESSTXT1
        ${has_info_messages}         Run Keyword And Return Status       Should Contain      ${info_message}         Number of failed password logon attempts
        enable screenshots on error
        IF  ${has_info_messages}
            log     ${info_message}
            send vkey           0
        END
    EXCEPT
        return from keyword
    END

Close SAP connections
    process.terminate process       ${PROCESS}      ${true}
    ${has_stopped}     run keyword and return status     process should be stopped       ${PROCESS}
    IF    not ${has_stopped}
            ${has_stopped}     process.terminate process       ${PROCESS}      ${true}
    END

Note: Save you the drama of unexpected errors you may need to handle upon login, these above are my main SAP keywords.

Example test:

*** Settings ***
Documentation    Just an example
Resource    ../sap_keywords/main_sap_keywords.robot
Resource    ../sap_keywords/zwidr_keywords.robot

Test Setup       launch sap.exe
Test Teardown    Close SAP connections

*** Variables ***
# === SAP Envoirment ===
${ENV}

*** Test Cases ***
ZWIDR - Retreive Technical Order from IDOC
    [Tags]    example
    Connect and open ${ENV} session
    SAP Gui Login
    run transaction        ZWIDR

I use a dictionary for the connections as I cover three envoirments, Though we dont run into HBP, I store my common variables here as well (I know some will keep a separate variables file, but I tend to keep my variables for the location they are used for unless common, then they go into here, personal taste from my C# projects), I then pass these start up variables as args

Hopefully, that at least gives you some insight, I believe many others use the RPA library

3 Likes

Thanks for sharing. I was playing with it and has some fun. I like it very much. The client thats hiring me wants some names of companies that has also succes wit RF. Are you allowd to share?

1 Like

Not a problem, I will PM you, and it is nice to be able to speak or share parts around SAP Automation, as it is few and far asked or seen.

2 Likes

We’re also using Robot Framework to run automated tests on a Desktop SAP system using SapGuiLibrary.

I recommend to also have a look at the new kid on the block, the roboSAPiens Library

1 Like

I understood that SAP has a partnership with Tricentis and nowadays comes bundled with a special Tricentis TOSCA version for testing - is that possible?
I think that was one reason why one of our projects uses TOSCA for automation of SAP (while another project uses Robot Framework)

1 Like

Hi @atenwolde, I am the author of RoboSAPiens, a library for automating the SAP GUI using text labels to select elements. For example, to fill in the login form (the password will not be written to the RF log!):

Fill Text Field   User       Username
Fill Text Field   Password   12345

As you can see, this is much simpler than using SapGuiLibrary with the Scripting Tracker.

I presented the library at the online RoboCon 2024 on Febrary 29th. Afterwards I talked to Frank, the author of SapGuiLibrary, and he said that since there is now a library for SAP automation that is maintained and offers a better user experience, he will deprecate his library and recommend RoboSAPiens.

As I said in the presentation, I have been developing RoboSAPiens since the summer of 2021 for a state development bank in Germany. The use cases have been:

  • Data-driven creation of application forms (15 forms per application in 30 sec.)
  • Compare forms between two servers (visual diff using screenshots)
  • Archive 5k forms (as JSON and PNG in 10 hours)

RoboSAPiens is being used by domain experts to automate processes and it is gaining a lot of traction in the bank.

There are some commercial tools that automate the SAP GUI. The main selling points are typically a component repository and record and replay functionality.

In my experience the text selectors are pretty stable and since there is no need for mapping IDs to human-readable selectors, the component repository is not as useful as it could be for web automation.

Record and replay generates code, which uses the SAP Scripting API directly with either the original IDs or the IDs from the component repository, which are mapped to those IDs. Therefore, the readability of the scripts is not as good as using keywords written by domain experts.

Hope this helps. If you have any questions I will be happy to answer them :slight_smile:

4 Likes

Hi @Marduk
I will take a look at RoboSAPiens (actually never come across this library upon initially looking automating SAP), Could I ask how you handle Grid Shell tables? I found these to be the most painful with the SapGuiLibrary as you can’t interact with the rows, I came to a coded workaround, so just curious.
Thanks

Hi @_daryl,

RoboSAPiens offers a uniform API for GuiTableControl, GuiGridView and GuiTree. It allows selecting rows, interacting with all kinds of cells and also with the toolbar of GuiGridView. The uniform API allows identifying cells using a row identifier and a column identifier.

The row identifier is either the row number or the contents of a cell in that row. The column identifier is one of the titles of the column (the title may change when the column is resized).

RoboSAPiens was only recently added to the Resources section of the RF home page. If you find it useful don’t forget to star it on GitHub in order to increase its visibility on the home page :slight_smile:

3 Likes

Thanks, I will have a play when and if time allows :sweat_smile:
I will be sure to do so.
Thanks again

1 Like

Thank you Marduk,

This library looks very good, how stabiel is it when SAP changed the screen layout?

Every keyword first searches for an element in the cache, if it is not found then the cache is rebuilt and the element is searched again. In addition, if the window title changes, a button is pressed or a tab is selected the cache is rebuilt.

In my experience it works pretty well and it’s fast. But of course, the more people use it the better statistics we will have :wink:

3 Likes

Hello @Marduk!

First of all: Thank you for taking the time to develop your robosapiens library! It’s so intuitive and easy to use! I’m just trying RF for the first time and your approach seems so much better than the “traditional” RFLibrary. However, I’ve gotten to a point where am not able to keep going in my script.

My situation is that I’m stuck on a screen where there’s a button that I cannot press by it’s on-screen label.

I even tried the receding tool and I got this python code generated:

session.findById(“wnd[0]”).resizeWorkingPane(137, 25, False)
** session.findById(“wnd[0]/usr/tabsTABSTRIP1/tabpTAB9/ssubSUB1:SAPLPRGN_TREE:0321/cntlTOOL_CONTROL/shellcont/shell”).pressButton(“TB03”)**

I can see that the is actually a bit complicated as it is a button that also has like a pull down menu on the side. I’ll try to upload an image to see if there’s any hint on how to make it work.

Hi @Elbenco,

I’m glad that you find RoboSAPiens useful and intuitive. Being user-friendly is its core design principle.

I did some research and found out that the button is in a toolbar. As you point out there are toolbar buttons with a context menu and those are currently not supported. Tomorrow I will release a new version that fixes that.

Cheers,
Marduk

Great news!!! I’ll stay tuned!

I’m really excited about this tool, and hopefully could contribute somehow.

Yes, of course! Reporting things that don’t work, are not user friendly or not clearly explained in the documentation are great ways to contribute.

By the way, I thought tomorrow is Monday. I will release the new version on Monday :slight_smile:

1 Like

:+1:

By the way, this is the screen I’m referring to, it’s in the PFCG Tx to maintain security roles. I’m trying to press the hilighted button

Hi @Elbenco,

I don’t seem to have the permission to click that button, but I found a similiar button and with the new Version 1.2.26 I was able to click it:

Please try it and let me know how it goes :slight_smile:

1 Like

It worked!

Thank you!!

I’ll keep going with my test this week and keep you posted. :tada::tada:

1 Like

@Marduk

Thanks for this repository, it is great to see someone building a new sap auto library.

I saw this thread over here Need help with RoboSAPiens - Libraries - Robot Framework

Do you know why this person might be having trouble connecting to the server?

Maybe you can DM me also I have a few questions about the keywords I am not sure how to answer.

Thanks.