//-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------------------------------------------------------------------
#-Begin-----------------------------------------------------------------
#-Includes------------------------------------------------------------
."$PSScriptRoot\COM.ps1"
#-Set SapGuiAuto = GetObject("SAPGUI")--------------------------------
$SapGuiAuto = Get-Object( , "SAPGUI")
If ($SapGuiAuto -isnot [__ComObject]) {
Exit
}
#-Set application = SapGuiAuto.GetScriptingEngine---------------------
$application = Invoke-Method $SapGuiAuto "GetScriptingEngine"
If ($application -isnot [__ComObject]) {
Free-Object $SapGuiAuto
Exit
}
#-Set connection = application.Children(0)----------------------------
$connection = Get-Property $application "Children" @(0)
If ($connection -eq $Null) {
Free-Object $SapGuiAuto
Exit
}
#-Set session = connection.Children(0)--------------------------------
$session = Get-Property $connection "Children" @(0)
If ($session -eq $Null) {
Free-Object $SapGuiAuto
Exit
}
#-Open SE16-----------------------------------------------------------
$ID = Invoke-Method $session "findById" @("wnd[0]/tbar[0]/okcd")
Set-Property $ID "text" @("/nse16")
$ID = Invoke-Method $session "findById" @("wnd[0]")
Invoke-Method $ID "sendVKey" @(0)
#-Open selection view for table DEMO_CR_CUSTOMRS----------------------
$ID = Invoke-Method $session "findById" @("wnd[0]/usr/ctxtDATABROWSE-TABLENAME")
Set-Property $ID "text" @("DEMO_CR_CUSTOMRS")
$ID = Invoke-Method $session "findById" @("wnd[0]/tbar[1]/btn[7]")
Invoke-Method $ID "press"
#-Open dialog "Number of Entries"-------------------------------------
$ID = Invoke-Method $session "findById" @("wnd[0]/tbar[1]/btn[31]")
Invoke-Method $ID "press"
#-Get the number of entries-------------------------------------------
$ID = Invoke-Method $session "findById" @("wnd[1]/usr/txtG_DBCOUNT")
$Value = Get-Property $ID "text"
#-If number of entries > 0--------------------------------------------
If ($Value -ne 0) {
#-Load libraries----------------------------------------------------
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Selenium\Selenium.WebDriverBackedSelenium.dll")
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Selenium\WebDriver.dll")
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Selenium\WebDriver.Support.dll")
#-Set path to chrome browser----------------------------------------
$Options = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$Options.BinaryLocation = "C:/Program Files/Google/Chrome/Application/chrome.exe"
#-Opens a web browser window----------------------------------------
$WebDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver("C:\Program Files\Selenium", $Options)
$WebDriver.Url = "http://nsp.stschnell.de:8630/sap/bc/webdynpro/sap/demo_wd_car_rental"
#-Do your activities in the browser---------------------------------
$WebDriver.FindElementById("WD1C").Clear()
$WebDriver.FindElementById("WD1C").SendKeys("00000001")
$WebDriver.FindElementByCssSelector("span.urBtnCntTxt").click()
$WebDriver.Close()
$WebDriver.Quit()
}
#-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.