Beispiel #1
0
        public void Execute(ActionContext context)
        {
            Console.WriteLine("Button press action execution");
            GuiSession session = context.GetSession();
            GuiButton  button  = (GuiButton)session.FindById(path);

            button?.Press();
        }
        public bool ButtonPressByID(string strControlID)
        {
            GuiSession SapSession = getCurrentSession();
            GuiButton  button     = (GuiButton)SapSession.ActiveWindow.FindById(strControlID, "GuiTextField");

            button.SetFocus();
            button.Press();
            return(true);
        }
        public bool ButtonPressByID_Using_MainWindowName(string MainWindowName, string strControlID)
        {
            GuiSession SapSession = getCurrentSession(MainWindowName);
            //SapSession.SuppressBackendPopups = true;
            GuiButton button = (GuiButton)SapSession.ActiveWindow.FindById(strControlID, "GuiTextField");

            button.SetFocus();
            button.Press();
            //SapSession.SuppressBackendPopups = false;
            return(true);
        }
        public bool logoff()
        {
            GuiSession SapSession = getCurrentSession();

            //Log Off the SAP
            SapSession.ActiveWindow.Close();
            GuiButton btnLogOffOk = (GuiButton)SapSession.FindById("/app/con[0]/ses[0]/wnd[1]/usr/btnSPOP-OPTION1");

            btnLogOffOk.SetFocus();
            btnLogOffOk.Press();

            return(true);
        }
Beispiel #5
0
        public static void Press(string id, GuiButton button, GuiSession session)
        {
            if (button == null && string.IsNullOrEmpty(id))
            {
                throw new Exception("Parameters for the Target object not provided: id or GuiButton object");
            }

            if (session == null)
            {
                throw new Exception("SAP session parameter is required and was not provided.");
            }

            if (button == null)
            {
                button = (GuiButton)(session).FindById(id);
            }
            button.SetFocus();
            button.Press();
        }
Beispiel #6
0
 		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
 			myland.SetFocus();
 			mylang.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();
 			
 		}
        /// <summary>
        /// This function will login into the SAP with provided credentials(same as manual login)
        /// </summary>
        /// <param name="SapSession"></param>
        /// <param name="myclient"></param>
        /// <param name="mylogin"></param>
        /// <param name="mypass"></param>
        /// <param name="mylang"></param>
        public string login(string servername, string myclient, string mylogin, System.Security.SecureString mypass, string mylang)
        {
            //GuiApplication appSAP = (GuiApplication)Marshal.GetActiveObject("SAPGUI");
            //GuiConnection connSAP = appSAP.OpenConnection(server, Sync: true);
            //GuiSession SapSession = (GuiSession)connSAP.Sessions.Item(0);

            //    System.IO.StreamWriter m_fswLogFile;
            //DateTime m_dtLastTimeLog = DateTime.MinValue;
            //int m_intTimeLogInterVal;

            //String strFilePath = "D:\\AA_Log_SAPAUto_Metabot.txt";

            //if (!System.IO.File.Exists(strFilePath)) {
            //    System.IO.File.Create(strFilePath).Close();
            //}
            ////Open the log file
            //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true);
            //m_fswLogFile.AutoFlush = true;
            //m_fswLogFile.WriteLine("Parameters");
            //m_fswLogFile.WriteLine(server);
            //m_fswLogFile.WriteLine(mylogin);
            //m_fswLogFile.WriteLine(mypass);
            //m_fswLogFile.WriteLine(mylang);
            //m_fswLogFile.WriteLine(SAPWindowName);
            //m_fswLogFile.Close();
            //m_fswLogFile = null;

            //Close the SAP if its opened, then open the new process
            KillProcess("saplogon");

            //Set the Exe Path and SAP Window name
            string          strSAPLoginPadPath = @"C:\Program Files (x86)\SAP\FrontEnd\SapGui\saplogon.exe";
            FileVersionInfo fi2                = FileVersionInfo.GetVersionInfo(strSAPLoginPadPath);
            string          strVersion         = fi2.ProductVersion.Substring(0, 3);
            String          strloginWindowName = "SAP Logon " + strVersion;

            //Open the SAP Logon Window
            StartProcess(strSAPLoginPadPath);

            //Wait for the window to be loaded.
            System.Threading.Thread.Sleep(1000);
            AutomationElement desktop = AutomationElement.RootElement;
            AutomationElement ele     = null;

            while (ele is null)
            {
                try
                {
                    ele = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, strloginWindowName));
                }
                catch { }
            }

            CSapROTWrapper sapROTWrapper = new CSapROTWrapper();
            object         rot           = sapROTWrapper.GetROTEntry("SAPGUI");
            object         engine        = rot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, rot, null);
            GuiConnection  connection    = (engine as GuiApplication).OpenConnection(servername);
            GuiSession     SapSession    = connection.Children.ElementAt(0) as GuiSession;

            //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true);
            //m_fswLogFile.AutoFlush = true;
            //m_fswLogFile.WriteLine("Going to get the controls for login");

            //m_fswLogFile.Close();
            //m_fswLogFile = null;

            GuiTextField client   = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-MANDT", "GuiTextField");
            GuiTextField login    = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField");
            GuiTextField pass     = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-BCODE", "GuiPasswordField");
            GuiTextField language = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-LANGU", "GuiTextField");

            //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true);
            //m_fswLogFile.AutoFlush = true;
            //m_fswLogFile.WriteLine("Enter credentials for login");

            //m_fswLogFile.Close();
            //m_fswLogFile = null;
            client.SetFocus();
            client.Text = myclient;
            login.SetFocus();
            login.Text = mylogin;
            pass.SetFocus();
            pass.Text = new System.Net.NetworkCredential(string.Empty, mypass).Password;
            language.SetFocus();
            language.Text = mylang;

            //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true);
            //m_fswLogFile.AutoFlush = true;
            //m_fswLogFile.WriteLine("click login");

            //m_fswLogFile.Close();
            //m_fswLogFile = null;
            //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();

            //Validate whether the login successfull or Not
            //If the error is "Already logged in by the same user, then click
            GuiStatusbar statusBar  = (GuiStatusbar)SapSession.FindById("wnd[0]/sbar");
            string       strMsg     = statusBar.Text;
            string       strMsgType = statusBar.MessageType;

            if (strMsg.Contains("User already logged on at another terminal") == true || strMsg.Contains("用户已经登录到其它终端") == true)//(strMsg == "W" || strMsgType == "E" ) //'Warning or Error
            {
                //Check whether is it showing the same terminal or different terminal
                string strWinText = ((GuiFrameWindow)SapSession.FindById("wnd[1]")).Text;
                strWinText = Environment.MachineName;
                if (strWinText.Contains(Environment.MachineName) == true)
                {
                    //This represents, the login in the same machine, then click continue with current login option
                    ((GuiRadioButton)SapSession.FindById("wnd[1]/usr/radMULTI_LOGON_OPT1")).Select();
                    ((GuiButton)SapSession.FindById("wnd[1]/tbar[0]/btn[0]")).Press();
                }
                else
                {
                    SapSession.ActiveWindow.Close();
                    return("SAP Error while logging in the SAP system, Error:\n" + strMsg);
                }
            }
            else if (strMsg.Length > 0 && strMsgType == "E")
            {
                SapSession.ActiveWindow.Close();
                return("SAP Error while logging in the SAP system, Error:\n" + strMsg);
            }

            return("success");
        }