private void GetUIElements(List <SAPEventElement> list, GuiSession session, string Parent, GuiComponent Element) { var msg = new SAPEventElement(Element, session.Info.SystemName, Parent, false); list.Add(msg); if (Element.ContainerType) { if (Element is GuiVContainer vcon) { for (var i = 0; i < vcon.Children.Count; i++) { GetUIElements(list, session, Element.Id, vcon.Children.ElementAt(i)); } } else if (Element is GuiContainer con) { for (var i = 0; i < con.Children.Count; i++) { GetUIElements(list, session, Element.Id, con.Children.ElementAt(i)); } } else if (Element is GuiStatusbar sbar) { for (var i = 0; i < sbar.Children.Count; i++) { GetUIElements(list, session, Element.Id, sbar.Children.ElementAt(i)); } } } }
private void ep_Session_Expanded(object sender, RoutedEventArgs e) { _app = null; try { _app = SAPTestHelper.GetSAPGuiApp(1); List <SAPSessionVM> sessions = new List <SAPSessionVM>(); for (int i = 0; i < _app.Children.Count; i++) { GuiConnection cn = _app.Children.ElementAt(i) as GuiConnection; for (int j = 0; j < cn.Children.Count; j++) { GuiSession s = cn.Children.ElementAt(j) as GuiSession; if (!s.Busy) { sessions.Add(new SAPSessionVM() { Id = s.Id, System = s.Info.SystemName, Transaction = s.Info.Transaction }); } } } lv_Sessions.ItemsSource = sessions; } catch { } }
public static int FindColumnIndex(string id, GuiTableControl table, GuiSession session, string columnName) { if (table == null && string.IsNullOrEmpty(id)) { throw new Exception("Parameters for the Target object not provided: id or GuiTableControl object"); } if (session == null) { throw new Exception("SAP session parameter is required and was not provided."); } if (table == null) { table = (GuiTableControl)(session).FindById(id); } IEnumerator <GuiTableColumn> cols = table.Columns.Cast <GuiTableColumn>().GetEnumerator(); int counter = 0; string colname; while (cols.MoveNext()) { colname = ((GuiComponent)cols.Current).Name; if (colname.ToUpper().Trim().Replace(" ", "").Equals(columnName.Trim().ToUpper().Replace(" ", ""))) { return(counter); } ; counter++; } return(-1); }
/// <summary>Start a new transaction</summary> /// <param name="transactionID">Transaction ID</param> /// <param name="expectedTitle">Title of the transaction. This is used for validation.</param> public static GuiFrameWindow BeginTransaction(this GuiSession session, string transactionID, string expectedTitle) { // force current transaction to end, preventing any blocking(eg: model dialog) session.EndTransaction(); Logger.Instance.Debug("Starting transaction : " + transactionID); session.StartTransaction(transactionID); var window = session.ActiveWindow; if (window.Text != expectedTitle) { const string Message = "You do not have the correct permission to access this transaction. Or, such transaction does not exist."; var context = new Dictionary <string, object> { { "TransactionID", transactionID }, { "Expected Title", expectedTitle }, { "WindowTitle", window.Text }, { "StatusMessage", window.FindByName <GuiStatusbar>("sbar").Text }, }; Logger.Instance.Error("Unable to access personal data"); throw new InvalidOperationException(Message + Environment.NewLine + context.Prettify()) .BindContext(context); } return(window); }
public static int[] FindColumnIndexByName(string id, GuiTableControl table, GuiSession session, string columnTitle) { if (table == null && string.IsNullOrEmpty(id)) { throw new Exception("Parameters for the Target object not provided: id or GuiTableControl object"); } if (session == null) { throw new Exception("SAP session parameter is required and was not provided."); } if (table == null) { table = (GuiTableControl)(session).FindById(id); } List <int> output = new List <int>(); int index = 0; foreach (GuiTableColumn c in table.Columns) { if (columnTitle.ToLower().Trim().Equals(c.Title.ToLower().Trim())) { output.Add(index); } index++; } return(output.ToArray()); }
public string Grid_GetCellValue(string GridID, Int32 rowIndex, string columnID) { GuiSession SapSession = getCurrentSession(); GuiGridView gridView = (GuiGridView)SapSession.ActiveWindow.FindById(GridID, "GuiGridView"); return(gridView.GetCellValue(rowIndex, columnID)); }
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 GuiConnection CreateConnection(string description, string user, string password, string language) { CSapROTWrapper sapROTWrapper = new CSapROTWrapper(); object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); object engine = SapGuilRot.GetType().InvokeMember("GetSCriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null); GuiApplication app = (GuiApplication)engine; GuiConnection conn; if (app.Connections.Count == 0) { conn = app.OpenConnection(description); GuiSession session = conn.Children.ElementAt(0) as GuiSession; GuiTextField name = (GuiTextField)session.FindById("wnd[0]/usr/txtRSYST-BNAME"); GuiPasswordField pass = (GuiPasswordField)session.FindById("wnd[0]/usr/pwdRSYST-BCODE"); GuiTextField lang = (GuiTextField)session.FindById("wnd[0]/usr/txtRSYST-LANGU"); GuiMainWindow mainWindows = (GuiMainWindow)session.FindById("wnd[0]"); name.Text = user; pass.Text = password; lang.Text = language; mainWindows.SendVKey(0); } else { conn = (GuiConnection)app.Connections.ElementAt(0); } return(conn); }
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; } } }
public void ComboBox_SelectItem_Using_Key(string ControlID, string ItemKey) { GuiSession SapSession = getCurrentSession(); GuiComboBox gridView = (GuiComboBox)SapSession.ActiveWindow.FindById(ControlID, "GuiComboBox"); gridView.Key = ItemKey; }
public void GridSelectAll(string GridID) { GuiSession SapSession = getCurrentSession(); GuiGridView gridView = (GuiGridView)SapSession.ActiveWindow.FindById(GridID, "GuiGridView"); gridView.SelectAll(); }
public string Grid_CountRows(string GridID) { GuiSession SapSession = getCurrentSession(); GuiGridView gridView = (GuiGridView)SapSession.ActiveWindow.FindById(GridID, "GuiGridView"); return(gridView.RowCount.ToString()); }
public void ComboBox_SelectItem_Using_ItemTextcontains(string ControlID, string ItemTextContains) { GuiSession SapSession = getCurrentSession(); GuiComboBox gridView = (GuiComboBox)SapSession.ActiveWindow.FindById(ControlID, "GuiComboBox"); //GuiComponentCollection output = gridView.AccLabelCollection; //Console.WriteLine("AccText Collection"); //foreach (GuiLabel o in output) { // Console.WriteLine(o.Text); //} //var value = gridView.Value; //Console.WriteLine("Value:" + value); //var value1 = gridView.Text; //Console.WriteLine("Text:" + value1); //var acctext = gridView.Text; //Console.WriteLine("AccText:" + acctext); GuiCollection entries = gridView.Entries; String key = ""; foreach (GuiComboBoxEntry o in entries) { if (o.Value.Contains(ItemTextContains)) { key = o.Key; break; } } if (key == "") { throw new Exception("The item text:" + ItemTextContains + " is not contains in any of combobox itemlist"); } gridView.Key = key; }
public string GetWindowText(string strWindowID) { GuiSession SapSession = getCurrentSession(); var wndWindow = SapSession.ActiveWindow.FindById(strWindowID, "GuiMainWindow"); if (wndWindow.Type == "GuiMessageWindow") { GuiMessageWindow wndMsgWindow = (GuiMessageWindow)wndWindow; return(wndMsgWindow.MessageText); } else if (wndWindow.Type == "GuiFrameWindow") { GuiFrameWindow wndFrmWindow = (GuiFrameWindow)wndWindow; return(wndFrmWindow.AccText); } else if (wndWindow.Type == "GuiMainWindow") { GuiMainWindow wndMainWindow = (GuiMainWindow)wndWindow; return(wndMainWindow.AccText); } else if (wndWindow.Type == "GuiModalWindow") { GuiModalWindow wndMainWindow = (GuiModalWindow)wndWindow; return(wndMainWindow.PopupDialogText); } else { return(""); } }
public static GuiFrameWindow QueryPA20(this GuiSession session, int employeeID, string it, string sty = null, bool asListView = false) { const string TransactionTitle = "Afficher données de base personnel"; var window = session.BeginTransaction("PA20", TransactionTitle); Logger.Instance.Debug("Accessing personal data: emp={0}, it={1}, sty={2}, mode={3}", employeeID, it, sty ?? "null", asListView ? "list" : "detail"); window.FindByName <GuiCTextField>("RP50G-PERNR").Text = employeeID.ToString(); window.FindByName <GuiCTextField>("RP50G-CHOIC").Text = it; window.FindByName <GuiCTextField>("RP50G-SUBTY").Text = sty; window.SendVKey(asListView ? 20 : 7); // Ctrl+F8 vs F7 // if the title remains the same, that means we have failed to access the data if (window.Text == TransactionTitle) { const string Message = "The employee's personal data can not be accessed. The employee's ID may be incorrect, or there is no record for the requested infotype. Or. you do not have the correct permission to access this infotype."; var context = new Dictionary <string, object> { { "EmployeeID", employeeID }, { "InfoType", it }, { "SubType", sty }, { "AsListView", asListView }, { "StatusMessage", window.FindByName <GuiStatusbar>("sbar").Text } }; Logger.Instance.Error("Unable to access infotype." + context.Prettify()); throw new InvalidOperationException(Message + Environment.NewLine + context.Prettify()) .BindContext(context); } return(window); }
public static GuiSession NewSession(GuiSession currentSession) { if (currentSession == null) { currentSession = GetCurrentSession(); } GuiConnection connection = SAPGui.GetConnection(); int currNumSessions = connection.Children.Count; GuiSession session = currentSession; session.CreateSession(); System.Threading.Thread.Sleep(500); int count = 0; while (connection.Children.Count <= currNumSessions && count < 20) { System.Threading.Thread.Sleep(500); count++; connection = SAPGui.GetConnection(); } return(connection.Children.ElementAt(connection.Children.Count - 1) as GuiSession); }
public static GuiSession GetCurrentSession() { GuiConnection connection = SAPGui.GetConnection(); GuiSession session = connection.Children.ElementAt(0) as GuiSession; return(session); }
public void Grid_Select_Row(string GridID, string rowIndex) { GuiSession SapSession = getCurrentSession(); GuiGridView gridView = (GuiGridView)SapSession.ActiveWindow.FindById(GridID, "GuiGridView"); gridView.SelectedRows = rowIndex; }
public void Grid_SelectRow_AndDoubleClick(string GridID, string rowIndex) { GuiSession SapSession = getCurrentSession(); GuiGridView gridView = (GuiGridView)SapSession.ActiveWindow.FindById(GridID, "GuiGridView"); gridView.SelectedRows = rowIndex; gridView.DoubleClickCurrentCell(); }
public bool MenuSelectionByID(string strMenuID) { GuiSession SapSession = getCurrentSession(); GuiMenu menu = (GuiMenu)SapSession.ActiveWindow.FindById(strMenuID, "GuiMenu"); menu.Select(); return(true); }
public string Get_TextEditBox_Value_ByID(string strControlID) { GuiSession SapSession = getCurrentSession(); //GuiTextField txtControl = (GuiTextField)SapSession.ActiveWindow.FindById(strControlID, "GuiTextField"); GuiTextedit txtControl = (GuiTextedit)SapSession.ActiveWindow.FindById(strControlID, "GuiTextedit"); return(txtControl.Text); }
void _sapGuiSession_Destroy(GuiSession Session) { if (OnDestroySession != null) { OnDestroySession(this, Session); } _sapGuiSession = null; }
public void Grid_SelectCell_AndDoubleClick(string GridID, string rowIndex, string columnID) { GuiSession SapSession = getCurrentSession(); GuiGridView gridView = (GuiGridView)SapSession.ActiveWindow.FindById(GridID, "GuiGridView"); gridView.SetCurrentCell(Convert.ToInt32(rowIndex), columnID); gridView.DoubleClickCurrentCell(); }
public string Table_GetCellValue(string TableID, int rowIndex, int columnIndex) { GuiSession SapSession = getCurrentSession(); GuiTableControl tblControl = (GuiTableControl)SapSession.ActiveWindow.FindById(TableID, "GuiTableControl"); tblControl.SetFocus(); return(tblControl.GetCell(Convert.ToInt32(rowIndex), Convert.ToInt32(columnIndex)).Text); }
private void Current_OnSetSession(object sender, GuiSession session) { session.EndRequest -= session_EndRequest; session.EndRequest += session_EndRequest; session.Destroy -= session_Destroy; session.Destroy += session_Destroy; showSessionInfo(session); }
void SAPComponents_OnSetSession(GuiSession session) { _session = session; this.IsEnabled = true; clearContent(); _session.Destroy -= _session_Destroy; _session.Destroy += _session_Destroy; }
void getSession(GuiSession session) { session.EndRequest -= session_EndRequest; session.EndRequest += session_EndRequest; session.Destroy -= session_Destroy; session.Destroy += session_Destroy; showSessionInfo(session); }
public static void testConnection() { SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper(); object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null); GuiConnection connection = (engine as GuiApplication).OpenConnection("BOX DESCRIPTION"); GuiSession session = connection.Children.ElementAt(0) as GuiSession; }
public bool Grid_ToolBarButton_PressByName(string GridID, string ButtonName) { GuiSession SapSession = getCurrentSession(); GuiGridView gridView = (GuiGridView)SapSession.ActiveWindow.FindById(GridID, "GuiGridView"); gridView.PressToolbarButton(ButtonName); return(true); }
public void SetSession(GuiApplication application, GuiConnection connection, GuiSession session) { this._sapGuiApplication = application; this._sapGuiConnection = connection; this._sapGuiSession = session; _currentScreen = new ScreenData(session.Info.SystemName, session.Info.Transaction, session.Info.Program, session.Info.ScreenNumber, session.ActiveWindow.Text); hookSessionEvent(); }
public void OpenConnection(string server, int secondsOfTimeout = 10) { _sapGuiApplication = SAPTestHelper.GetSAPGuiApp(secondsOfTimeout); _sapGuiApplication.OpenConnectionByConnectionString(server); var index = _sapGuiApplication.Connections.Count - 1; this._sapGuiConnection = _sapGuiApplication.Children.ElementAt(index) as GuiConnection; index = _sapGuiConnection.Sessions.Count - 1; this._sapGuiSession = _sapGuiConnection.Children.Item(index) as GuiSession; }