Hello community,

more and more loses the SAP GUI for Windows his unique postion as primary UI and also more and more are desktop applications replaced with web applications. The SAP GUI for Windows offers for automation approaches the SAP GUI Scripting, a consolidated and technical reliable way. For web browser wrotes Prakash Upadhyay in his great blog about START (Simple Test Automation for Regression Tests) an UI Automation Framework to automate the testing of application. START bases on Selenium WebDrivers. So I think it could be advantageous to combine SAP GUI Scripting and Selenium.

So I advanced my Scripting Tracker to create also Java code, to offer the possibilty to combine SAP GUI Scripting on this language platform. To use SAP GUI Scripting with Java you need the Java COM Bridge (JaCoB).

For the web activities I use in my context the chrome web driver, an x86 application, because I use the Chrome browser. So it is necessary to use the x86 (i586) version of the JDK, also for the SAP GUI for Windows. To record the activities on the web browser I use Firefox with Selenium IDE. You see it is a very heterogeneous development environment. But after all, it works. Here an example code how to combine SAP GUI for Windows activities with any activities in a web browser. In the example I combine information from the TAC SE16 from the table DEMO_CR_CUSTOMRS with a web dynpro application DEMO_WD_CAR_RENTAL – this is not really useful but shows the horizons.

//-Begin----------------------------------------------------------------

package de.stschnell;

  //-Import-------------------------------------------------------------
  import com.jacob.activeX.*;
  import com.jacob.com.*;
  import java.util.HashMap;
  import java.util.Map;
  import org.openqa.selenium.*;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.chrome.ChromeOptions;
  import org.openqa.selenium.remote.*;
  
public class SAPGUIScriptingWithSelenium {

  public static void main(String[] args) {

    //-Variables--------------------------------------------------------
    ActiveXComponent SAPROTWr, GUIApp, Connection, Session, Obj;
    Dispatch ROTEntry;
    Variant Value, ScriptEngine;
    String cnt = "0";

    ComThread.InitSTA();

    //-Set SapGuiAuto = GetObject("SAPGUI")-----------------------------
    SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");
    try {
      ROTEntry = SAPROTWr.invoke("GetROTEntry", "SAPGUI").toDispatch();
      //-Set application = SapGuiAuto.GetScriptingEngine----------------
      ScriptEngine = Dispatch.call(ROTEntry, "GetScriptingEngine");
      GUIApp = new ActiveXComponent(ScriptEngine.toDispatch());

      //-Set connection = application.Children(0)-----------------------
      Connection = new ActiveXComponent(
        GUIApp.invoke("Children", 0).toDispatch()
      );
      //-Set session = connection.Children(0)---------------------------
      Session = new ActiveXComponent(
        Connection.invoke("Children", 0).toDispatch()
      );

      //-Open SE16------------------------------------------------------
      Obj = new ActiveXComponent(Session.invoke("findById", 
        "wnd[0]/tbar[0]/okcd").toDispatch());
      Obj.setProperty("text", "/nse16");
      Obj = new ActiveXComponent(Session.invoke("findById", 
        "wnd[0]").toDispatch());
      Obj.invoke("sendVKey", 0);

      //-Open selection view for table DEMO_CR_CUSTOMRS-----------------
      Obj = new ActiveXComponent(Session.invoke("findById", 
        "wnd[0]/usr/ctxtDATABROWSE-TABLENAME").toDispatch());
      Obj.setProperty("text", "DEMO_CR_CUSTOMRS");
      Obj = new ActiveXComponent(Session.invoke("findById", 
        "wnd[0]/tbar[1]/btn[7]").toDispatch());
      Obj.invoke("press");

      //-Open dialog "Number of Entries"--------------------------------
      Obj = new ActiveXComponent(Session.invoke("findById", 
        "wnd[0]/tbar[1]/btn[31]").toDispatch());
      Obj.invoke("press");

      //-Get the number of entries--------------------------------------
      Obj = new ActiveXComponent(Session.invoke("findById", 
        "wnd[1]/usr/txtG_DBCOUNT").toDispatch());
      Value = Obj.getProperty("text");
      cnt = Value.toString();

    } catch (Exception e) {
      System.out.println(
        e.getMessage().toString()
      );
    } finally {
      ComThread.Release();
    }
          
          
    //-If number of entries > 0-----------------------------------------
    if (cnt != "0") {

      //-Set path to chromedriver---------------------------------------
      System.setProperty(
        "webdriver.chrome.driver",
        "C:/Program Files/Selenium/chromedriver.exe");

      //-Set path to chrome browser-------------------------------------
      Map<String, Object> chromeOptions = new HashMap<String, Object>();
      chromeOptions.put("binary", "C:/Program Files/Google/Chrome/Application/chrome.exe");
      DesiredCapabilities capabilities = DesiredCapabilities.chrome();
      capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);        
    
      //-Opens a web browser window-------------------------------------
      WebDriver driver = new ChromeDriver(capabilities);

      //-Do your activities in the browser------------------------------
      driver.get("http://nsp.stschnell.de:8630/sap/bc/webdynpro/sap/demo_wd_car_rental");
      driver.findElement(By.id("WD1C")).clear();
      driver.findElement(By.id("WD1C")).sendKeys("00000001");
      driver.findElement(By.cssSelector("span.urBtnCntTxt")).click();

      driver.close();
      driver.quit();

    }

    System.exit(0);
  
  }          

}

//-End------------------------------------------------------------------

Here Scripting Tracker which  records Java code from the SAP GUI for Windows activities:

Here Firefox with Selenium IDE to record web activities:

Here the SAP GUI for Windows with SAP GUI Scripting and Eclipse in debug mode side by side:

Here Chrome with Eclipse in debug mode side by side:

On this way is it possible to combine SAP GUI Scripting with e.g. WebDynpro or UI5 applications. So you can reach a higher integration level in your automation approaches.

Enjoy it.

Cheers
Stefan

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply