Exemple #1
0
        public bool Login(string UserName, string Password, string Client, string Language)
        {
            BeforeLogin?.Invoke(Session, new EventArgs());
            Session.FindById <GuiTextField>("wnd[0]/usr/txtRSYST-BNAME").Text = UserName;
            Session.FindById <GuiTextField>("wnd[0]/usr/pwdRSYST-BCODE").Text = Password;
            Session.FindById <GuiTextField>("wnd[0]/usr/txtRSYST-MANDT").Text = Client;
            Session.FindById <GuiTextField>("wnd[0]/usr/txtRSYST-LANGU").Text = Language;
            var window = Session.FindById <GuiFrameWindow>("wnd[0]");

            window.SendVKey(0);
            GuiStatusbar status = Session.FindById <GuiStatusbar>("wnd[0]/sbar");

            if (status != null && status.MessageType.ToLower() == "e")
            {
                Connection.CloseSession(Session.Id);
                FailLogin?.Invoke(Session, new EventArgs());
                return(false);
            }
            AfterLogin?.Invoke(Session, new EventArgs());
            GuiRadioButton rb_Button = Session.FindById <GuiRadioButton>("wnd[1]/usr/radMULTI_LOGON_OPT2");

            if (rb_Button != null)
            {
                rb_Button.Select();
                window.SendVKey(0);
            }
            return(true);
        }
Exemple #2
0
        void _session_EndRequest(GuiSession Session)
        {
            GuiStatusbar status = _session.FindById <GuiStatusbar>("wnd[0]/sbar");

            if (status != null)
            {
                switch (status.MessageType)
                {
                case "E":
                    if (RequestError != null)
                    {
                        RequestError();

                        Thread.Sleep(1000);
                    }

                    break;

                case "S":

                    break;

                default:

                    break;
                }
            }
        }
Exemple #3
0
        void _sapGuiSession_StartRequest(GuiSession Session)
        {
            GuiStatusbar status = _sapGuiSession.FindById <GuiStatusbar>("wnd[0]/sbar");

            if (status != null)
            {
                switch (status.MessageType)
                {
                case "E":
                    Thread.Sleep(2000);
                    break;

                case "S":
                    Thread.Sleep(2000);
                    break;

                case "W":
                    Thread.Sleep(2000);
                    break;

                default:
                    break;
                }
            }
            autoScreenShot();
        }
 public static T FindDescendantByProperty <T>(this GuiStatusbar Statusbar, Func <T, bool> Property = null)
     where T : class
 {
     if (Property == null)
     {
         Property = new Func <T, bool>(t => true);
     }
     return(findDescendantByPropertyTemplate <T>(Statusbar.Children, Property));
 }
        public static void StatusBarDoubleClick(string id, GuiStatusbar statusbar, GuiSession session)
        {
            if (statusbar == null && string.IsNullOrEmpty(id))
            {
                throw new Exception("Parameters for the Target object not provided: id or GuiStatusbar object");
            }

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

            if (statusbar == null)
            {
                statusbar = (GuiStatusbar)(session).FindById(id);
            }
            statusbar.DoubleClick();
        }
Exemple #6
0
        void _sapGuiSession_EndRequest(GuiSession Session)
        {
            ScreenDatas.Add(_currentScreen);
            Tuple <string, string, string, int, string> sessionInfo = new Tuple <string, string, string, int, string>(Session.Info.SystemName, Session.Info.Transaction, Session.Info.Program, Session.Info.ScreenNumber, Session.ActiveWindow.Text);


            GuiStatusbar status = _sapGuiSession.FindById <GuiStatusbar>("wnd[0]/sbar");

            if (status != null)
            {
                switch (status.MessageType)
                {
                case "E":
                    _currentScreen.Status = ScreenStatus.Fail;
                    if (OnRequestError != null)
                    {
                        OnRequestError(this, new SAPRequestInfoArgs(status.Text));
                    }
                    break;

                case "S":
                    _currentScreen.Status = ScreenStatus.Success;
                    if (OnRequestSuccess != null)
                    {
                        OnRequestSuccess(this, new SAPRequestInfoArgs(status.Text));
                    }
                    break;

                case "W":
                    _currentScreen.Status = ScreenStatus.Warning;
                    if (OnRequestWarning != null)
                    {
                        OnRequestWarning(this, new SAPRequestInfoArgs(status.Text));
                    }
                    break;

                default:
                    _currentScreen.Status = ScreenStatus.Pass;
                    break;
                }
            }

            newScreen(sessionInfo);
        }
        public Tuple <String, String> StatusTextAndMessageType()
        {
            GuiSession   SapSession = getCurrentSession();
            GuiStatusbar statusBar  = (GuiStatusbar)SapSession.ActiveWindow.FindById("sbar");

            ////Adding log
            //System.IO.StreamWriter m_fswLogFile;
            //string strFilePath = @"E:\Excel Data\statustextlog.txt";
            //DateTime m_dtLastTimeLog = DateTime.MinValue;

            //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true);
            //m_fswLogFile.AutoFlush = true;
            //m_fswLogFile.WriteLine("Satusbar text captured: Type:" + statusBar.MessageType + " Status Text:" + statusBar.Text);

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

            return(new Tuple <string, string>(statusBar.MessageType, statusBar.Text));
        }
        public void Login(string UserName, string Password, string Client, string Language)
        {
            if (BeforeLogin != null)
            {
                BeforeLogin(_sapGuiSession, new EventArgs());
            }

            _sapGuiSession.FindById <GuiTextField>("wnd[0]/usr/txtRSYST-BNAME").Text = UserName;
            _sapGuiSession.FindById <GuiTextField>("wnd[0]/usr/pwdRSYST-BCODE").Text = Password;
            _sapGuiSession.FindById <GuiTextField>("wnd[0]/usr/txtRSYST-MANDT").Text = Client;
            _sapGuiSession.FindById <GuiTextField>("wnd[0]/usr/txtRSYST-LANGU").Text = Language;


            var window = _sapGuiSession.FindById <GuiFrameWindow>("wnd[0]");

            window.SendVKey(0);

            GuiStatusbar status = _sapGuiSession.FindById <GuiStatusbar>("wnd[0]/sbar");

            if (status != null && status.MessageType.ToLower() == "e")
            {
                _sapGuiConnection.CloseSession(_sapGuiSession.Id);
                if (FailLogin != null)
                {
                    FailLogin(_sapGuiSession, new EventArgs());
                }
                return;
            }

            if (AfterLogin != null)
            {
                AfterLogin(_sapGuiSession, new EventArgs());
            }

            GuiRadioButton rb_Button = _sapGuiSession.FindById <GuiRadioButton>("wnd[1]/usr/radMULTI_LOGON_OPT2");

            if (rb_Button != null)
            {
                rb_Button.Select();
                window.SendVKey(0);
            }
        }
        public string login_SSO(string servername)
        {
            //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;

            //Start SAP Login 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;

            //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();
                    throw new Exception("SAP Error while logging in the SAP system, Error:\n" + strMsg);
                }
            }
            else if (strMsg.Length > 0 && strMsgType == "E")
            {
                //SapSession.ActiveWindow.Close();
                throw new Exception("SAP Error while logging in the SAP system, Error:\n" + strMsg);
            }

            return("success");
        }
        /// <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");
        }
 public static IEnumerable <T> FindAllByName <T>(this GuiStatusbar Statusbar, string Name)
     where T : class
 {
     return(findAllByNameTemplate <T>(Name, Statusbar.FindAllByName));
 }
Exemple #12
0
 public static T FindById <T>(this GuiStatusbar Statusbar, string Id)
     where T : class
 {
     return(findByIdTemplate <T>(Id, Statusbar.FindById));
 }
Exemple #13
0
 public static T FindByName <T>(this GuiStatusbar Statusbar, string Name)
     where T : class
 {
     return(findByNameTemplate <T>(Name, Statusbar.FindByName));
 }
Exemple #14
0
 public static T FindChildByProperty <T>(this GuiStatusbar Statusbar, Func <T, bool> Property = null)
     where T : class
 {
     return(findChildByPropertyTemplate <T>(Statusbar.Children, Property));
 }
 public static T FindByNameEx <T>(this GuiStatusbar Statusbar, string Name, int TypeId)
     where T : class
 {
     return(findByNameExTemplate <T>(Name, TypeId, Statusbar.FindByNameEx));
 }
Exemple #16
0
 public static IEnumerable <T> FindDescendantsByProperty <T>(this GuiStatusbar Statusbar, Func <T, bool> Property = null)
     where T : class
 {
     return(findDescendantsByPropertyTemplate <T>(Statusbar.Children, Property));
 }