Skip to main content

SAP Driver

SAP Driver

This page describes only Sap Driver specific features and methods which may be different in other drivers.

Implementation which is common for all drivers is described in Drivers page. Please, read it before.

Prepare node for SAP Automation


SAP driver automates the actions are performed against SAP desktop client. Under the hood SAP driver employs ActiveX Component which requires manual steps need to be done ones by node administrator to prepare node for SAP automation:

You also need to setup SAP Client connections that could be done by SAP user.

Prepare your SAP Server for RPA

Enable SAP Scripting on SAP Server

It is recommended to download Tracker from https://tracker.stschnell.de/

One must be able to run Tracker against SAP Frontend and see its object tree after completing this step.

Enable scripting on client side, switch off the notifications.

Enable scripting on server:

  1. Log into created connection using your credentials;
  2. Run rz11 transaction code;
  3. Type in sapgui/user_scripting parameter name and press Enter;
  4. Make sure current value is set to TRUE, otherwise change it using upper menu.
For quick reference please check short SAP example.

Driver Initialization

You can initialize the driver in your automation process by the following way:

@Driver
private SapDriver sapDriver;

Driver Params


Param nameMeasureDefault ValueDescription
DriverParams.All.EXPLICITLY_WAIT_TIMEOUT_SECONDSseconds5Wait functions default timeout in seconds.
DriverParams.All.EXPLICITLY_WAIT_POLLING_INTERVAL_MILLISECONDSmilliseconds500Wait functions default pooling interval in milliseconds.

Opening and closing SAP application


To use SAP driver you have to start SAP session first. To do so you can either employ desktop driver or make use of sapshcut utility bundled with SAP Logon distribution.

Open SAP using sapshcut utility

  1. Run sapshcut command with all the necessary arguments such as user and password, SID and client and others

    String sapPath = "C:/Program Files (x86)/SAP/FrontEnd/SAPgui/sapshcut";
    String user = "userid";
    String password = "password";
    String system = "S4H";
    String client = "100";
    
    getDriver().get(sapPath, user, password, "EN", system, null, null, client, tCode, null);
    Run sapshcut -help in command line to find out more avaiable arguments
  2. After a certain time when SAP Frontend window appears the SapDriver session can be safely initialized

Open SAP using DesktopDriver

  1. Start SAP Logon using desktop driver.

    @Driver
    private DesktopDriver desktopDriver;
    ...
    
    desktopDriver.get("C:/Program Files (x86)/SAP/FrontEnd/SAPgui/saplogon.exe");
  2. Select the required connection from list and run it.

    DesktopSearch.UIQuery connectionQuery = DesktopSearch.UIQuery.builder().tagName("Text").name(sapConnectionName).build();
    DesktopElement connection = getDriver().findElement(DesktopSearch.query(connectionQuery));
    connection.sendKeys(Keys.ENTER);
  3. SAP Frontend window will open which is a subject to SAP driver automation.

    @Driver
    private SapDriver sapDriver;
    
    sapDriver.get();
  4. Log into SAP Frontend with required credentials and perform other AP related actions using SAP Driver.

    sapDriver.findElementById("wnd[0]/usr/txtRSYST-BNAME").setText(user);
    sapDriver.findElementById("wnd[0]/usr/pwdRSYST-BCODE").setText(password);
    sapDriver.findElementById("wnd[0]").sendKeys(SapKeyCode.ENTER);
    
    // other actions after user has been authenticated
  5. Logout from SAP Frontend with SAP Driver

    // logs out without prompt using command input
    sapDriver.findElementById("wnd[0]/tbar[0]/okcd").setText("/nex");

Working with UI Elements


Inspector

To define SAP Element ID run Scripting Tracker and refresh the object tree. Next click on target element using arrow button and copy value from ID field.

Below is the example of retreiving id for Material input field.

@FindBy(xpath = "/app/con[0]/ses[0]/wnd[0]/usr/ctxtMATNR-LOW")
private SapElement materialField;

Find elements

Please, check the table which locators are supported by SapDriver:

Selector type

SapSearch.sapId
SapSearch.sapName

The initialized SAP driver can be used to locate page elements.

In order to do so the field ID must be passed to sapDriver.findElement(By sapId).

Now we can access this field inside AP as following:

SapElement descriptionInput = sapDriver.findElement(SapSearch.sapId("wnd[0]/usr/txtRSYST-BNAME"));
descriptionInput.setText("EasyRPA material");