How to connect Robot whit SAP GUI

Hi guys,

I need to autometed some tests in the SAP environment, so I need to connect the Robot with the SAP GUI, I know that there is library for that, my I don’t know how to use it. I tried the steps below, but dind’t work and I don’t know what to do.

*** Settings ***
Library SapGuiLibrary
Library Process
Variables …/Data/SAP.py

*** Test Cases ***
Connect with SAPGUI
Start Process {Winium} Run Process {saplogon}
Connect To Session

I’m on a RB basic level, so any help will be great.

Thank in advance.

hard to help you with so few information … you may have error messages ?

No error because I think I think something is missing.

Could someone who has already established this type of connection set an example here?

Did you ever get this working?

in the SapGuiLibrary documentation there is quite an important not about having logon pad open before calling Connect To Session

So I’ll assume that the line Start Process {Winium} Run Process {saplogon} is doing that and that logon pad is open.

I haven’t used this library myself so everything here is a guess based on the doco and my limited use of SAPGUI with loadrunner.

1st thing I would try is

${conn}=    Connect To Session
Log    ${conn}

and see what happens

next I would try

Connect To Session
Open Connection    <connection_name>

where <connection_name> is an entry in you login pad, watch the desktop of the machine you are running the robot file on and see if that connection opens

Also this should be obvious but, only 1 SAPGUI at a time, before you run your robot make sure all existing SAPGUI windows (including logon pad) are closed.

Hope that helps,

Dave.

Thanks for the help, but my problem was that the script was not configured to run on the server side, right after being configured by the administrator the connection via Robot worked. :+1:

1 Like

Great, glad you got a solution :+1:t3:

Hi you said connection name is an entry in login pad, can you please explain!, what this entry is! bcz im having trouble opening an connection

Hi Dhina,

Usually when you have multiple SAP environments the SAP GUI uses the login pad window to display the list of environments you can login to, if you are not seeing the login pad window when you start the SAP GUI you might need to discuss with your SAP administrator.

I’m no expert in SAP GUI as I have only automated it a few times.

Dave.

Hi damies we have done this
" ${sap_connection}= Set Variable -01- Nissan SAP

SapGuiLibrary.Open Connection    ${sap_connection}" 

and we got an error “Cannot find an open Sap Login Pad, is Sap Logon Pad open?”.

Whats happening is sap lgpad is opening but its not selecting and opening an specific server connection.Can you please help with this.

The OP’s issue was actually not having scripting enabled on the server side, with SAP GUI it needs to be enabled on the server and the client (GUI).

I found an article showing how to enable it, can you check you have scripting enabled first, as the problem you describe sounds like it’s not enabled.

Dave.

Hi Dave
First of all thanks for your reply… I am blocked on this issue as im from java selenium background and im new to RPA and python… Coming to scripting i have enabled it in client and server… As fast as my progress we are able to launch the sap exe fine but not able to connect to an connection due to some issue with connection name.This is the name of the connection i want to connect to but its throwing an error

“ValueError: Cannot open connection ‘40 R40 S/4 AS2B Recette’, please check connection name.”. Sap logon pad is opening fine but not able to connect to a session

This is my code in short
Variable
${sap_connection}= 40 R40 S/4 AS2B Recette

Test case
SapGuiLibrary.Connect To Session
SapGuiLibrary.Open Connection ${sap_connection}

If I’m not mistaken, / is an escape character in RB, so you need to put two // in your string

So you code will be like this:

Variable
${sap_connection}= 40 R40 S//4 AS2B Recette

Test case
SapGuiLibrary.Connect To Session
SapGuiLibrary.Open Connection ${sap_connection}

Hi ,

I tried this its giving the same error

image.png

Hi Dhina,

From that screen shot I would say “spaces spaces spaces”

I would say that name is not actually

40 R40 S/4 AS2B Recette

but

40   R40 S/4 AS2B Recette

and the line below is

98  PAS SSO  40   R40 S/4 AS2B Recette

But as you may know multiple spaces has a special meaning in Robot Framework

I would suggest you use the SAP Scripting Tracker to check what the name is exactly (including all the spaces) and then construct your variable as below (including @joseilton’s feedback)

${sap_connection}	40${SPACE}${SPACE}${SPACE}R40 S\/4 AS2B Recette

See escaping for more details.

Hope that helps,

Dave.

1 Like

Hi Dave, thanks for you help, really appreciate it.
After correcting the space and trying with this version of variable
“40${SPACE}${SPACE}${SPACE}${SPACE}${SPACE}R40${SPACE}S/4${SPACE}AS2B${SPACE}Recette” it is working.
Again Thanks a lot.

2 Likes

Yes, you are mistaken :frowning:
The escape character is \ (in almost every system, language, except DOS/Windows :wink: ).
But in Python (and because of that in RobotFramework), it must be escaped itself, so: \\.

1 Like