我想使用C#语言自动化SAP GUI窗口.我能够在VBScript中完成它,但代码重用是可怕的.除了Id喜欢使用线程而不是运行80个或更多进程.我在哪里可以找到有关如何执行此操作的任何文档和示例?这是我正在使用的代码.基本上,我面临的问题是 - 如何建立与SAP GUI的连接,然后动态创建SAP GUI,然后开始进行交易并在某些字段中输入文本.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using White.Core.Factory;
using White.Core.UIItems.Finders;
using White.Core.InputDevices;
using System.Threading;
using System.Diagnostics;
using SAP.Connector;
using SAP;
namespace SAP_Automation
{
class Program
{
public static void Main(string[] args)
{
string ExeSourceFile = @"C:\Program Files\SAP\SapSetup\setup\SAL\SapLogon.s8l";
White.Core.Application _application;
White.Core.UIItems.WindowItems.Window _mainWindow;
var c = SAP.Connector.Connection.GetConnection("**");
var c = new SAPConnection("ASHOST=*; GWHOST=*; GWSERV=*; ASHOST=*; SYSNR=00;USER=user; PASSWD=**;");
c.Open();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我可以创建连接,但我不知道如何创建GUI的会话并开始在字段中输入文本.任何例子和样品将不胜感激.
tyh*_*tyh 25
这可能是坏死线程,但我处于类似的情况,我工作.我们需要SAP GUI Automation进行测试,以便与我们用C#编写的本土自动化平台的其他部分集成.我帮助创建了一个解决方案,该解决方案利用SAP提供的GUI自动化库,可以用作SAP自动化层的基础.
SAP文件安装中是否存在以下文件?x:\ Program Files\SAP\FrontEnd\SAPGui\sapfewse.ocx?
如果是这样,请将其添加到Visual Studio(或您正在使用的任何IDE)作为参考.它基本上是一个类库,其中包含一组允许您与之交互的SAP特定对象.它非常有效,因为它可以从SAP GUI中显示您需要的大部分内容.我们在其他尝试中发现SAP中的许多对象都不可用.
这是我做过的概念的早期证明.使用连接字符串启动SAP,输入凭据,导航到事务代码.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using SAPFEWSELib;
namespace SAPGuiAutomated
{
//created a class for the SAP app, connection, and session objects as well as for common methods.
public class SAPActive
{
public static GuiApplication SapGuiApp { get; set; }
public static GuiConnection SapConnection { get; set; }
public static GuiSession SapSession { get; set; }
public static void openSap(string env)
{
SAPActive.SapGuiApp = new GuiApplication();
string connectString = null;
if (env.ToUpper().Equals("DEFAULT"))
{
connectString = "1.0 Test ERP (DEFAULT)";
}
else
{
connectString = env;
}
SAPActive.SapConnection = SAPActive.SapGuiApp.OpenConnection(connectString, Sync: true); //creates connection
SAPActive.SapSession = (GuiSession)SAPActive.SapConnection.Sessions.Item(0); //creates the Gui session off the connection you made
}
public void login(string myclient, string mylogin, string mypass, string mylang)
{
GuiTextField client = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-MANDT", "GuiTextField");
GuiTextField login = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField");
GuiTextField pass = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-BCODE", "GuiPasswordField");
GuiTextField language = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-LANGU", "GuiTextField");
client.SetFocus();
client.text = myclient;
login.SetFocus();
login.Text = mylogin;
pass.SetFocus();
pass.Text = mypass;
language.SetFocus();
language.Text = mylang;
//Press the green checkmark button which is about the same as the enter key
GuiButton btn = (GuiButton)SapSession.FindById("/app/con[0]/ses[0]/wnd[0]/tbar[0]/btn[0]");
btn.SetFocus();
btn.Press();
}
}
//--------------------------//
//main method somewhere else
public static void Main(string[] args)
{
SAPActive.openSAP("my connection string");
SAPActive.login("10", "jdoe", "password", "EN");
SAPActive.SapSession.StartTransaction("VA03");
}
Run Code Online (Sandbox Code Playgroud)
你是对的,没有很多关于这个主题的文件.以下是一些帮助我入门的资料
- 我们计划的原始来源 http://scn.sap.com/thread/1729689
- 关于API的文档(对于VB和javascript,但一般规则和对象是相同的).绝对阅读SAP GUI Runtime层次结构上的部分.它会回答很多问题. http://www.synactive.com/download/sap%20gui%20scripting/sap%20gui%20scripting%20api.pdf