/// <summary> /// Sets the text portion of the TextValueWithTypeControl to the specified text by sending keystrokes /// </summary> /// <param name="text">The text to set the text portion of the TextValueWithTypeControl to</param> public void SetText(string text) { GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "TextBox", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call; IntPtr textboxHandle = GUI.m_APE.GetValueFromMessage(); GUITextBox textBox = new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Handle, textboxHandle)); // Select the item textBox.SetText(text); }
/// <summary> /// Sets the text portion of the combobox to the specified text by sending keystrokes /// </summary> /// <param name="text">The text to set the text portion of the combobox to</param> public void SetText(string text) { GUITextBox comboboxTextBox = GetTextBox(); Input.Block(); try { comboboxTextBox.SetText(text); } catch when(Input.ResetInputFilter()) { // Will never be reached as ResetInputFilter always returns false } finally { Input.Unblock(); } }
/// <summary> /// Sets the text portion of the combobox to the specified text by sending keystrokes /// </summary> /// <param name="text">The text to set the text portion of the combobox to</param> public void SetText(string text) { //Get the style GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "DropDownStyle", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "ToString", MemberTypes.Method); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call string Style = GUI.m_APE.GetValueFromMessage(); if (Style == "DropDownList") { throw new Exception("ComboBox Edit control is not editable"); } //get the editbox child window GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "childEdit", MemberTypes.Field); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call IntPtr EditBox = (IntPtr)GUI.m_APE.GetValueFromMessage(); Input.Block(Identity.ParentHandle, Identity.Handle); try { GUITextBox comboboxTextBox = new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Handle, EditBox), new Identifier(Identifiers.TechnologyType, "Windows Native")); comboboxTextBox.SetText(text); } finally { Input.Unblock(); } }
/// <summary> /// Sets the text portion of the up down control to the specified text /// </summary> /// <param name="text">The text to set the control to</param> public void SetText(string text) { //Get the selectedText property GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "upDownEdit", MemberTypes.Field); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call dynamic UpDownEditControl = GUI.m_APE.GetValueFromMessage(); if (UpDownEditControl == null) { throw new Exception("Failed to find the updown edit control"); } IntPtr UpDownEditHandle = UpDownEditControl; GUITextBox UpDownEdit = new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Handle, UpDownEditHandle)); UpDownEdit.SetText(text); }
/// <summary> /// Sets the text of the generic walker control /// </summary> /// <param name="text">The text to set the control to</param> public void SetText(string text) { Stopwatch timer; string currentText; Input.Block(Identity.ParentHandle, Identity.Handle); try { IntPtr textboxHandle; if (Identity.TypeNameSpace == "LzGenericWalker") { GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "txtText", MemberTypes.Field); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call textboxHandle = GUI.m_APE.GetValueFromMessage(); } else { GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "WalkerTextBox", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call textboxHandle = GUI.m_APE.GetValueFromMessage(); } GUITextBox textbox = new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Handle, textboxHandle)); currentText = GUI.m_APE.GetWindowTextViaWindowMessage(textboxHandle); if (text == currentText) { GUI.Log("Ensure " + Identity.Description + " is set to " + text, LogItemType.Action); } else { if (currentText != "") { textbox.SingleClick(MouseButton.Left); //textbox.MouseDoubleClick(MouseButton.Left); //Select everything in the textbox base.SendKeys("{HOME}+{END}"); string selectedText; //wait for .selectedText to = Text timer = Stopwatch.StartNew(); while (true) { //Get the selectedText property GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, textboxHandle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "SelectedText", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call selectedText = GUI.m_APE.GetValueFromMessage(); if (currentText == selectedText) { break; } if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut) { throw new Exception("Failed to select all the text of the " + Description); } Thread.Sleep(15); } } // Get an array of each character token for example a or {+} string[] tokens = Tokenise(text); string unescapedText = Unescape(text); switch (tokens.Length) { case 0: break; case 1: GUI.Log("Type [" + unescapedText.Substring(0, 1) + "] into the " + Identity.Description, LogItemType.Action); base.SendKeysInternal(tokens[0]); break; default: //Send first 2 characters GUI.Log("Type [" + unescapedText.Substring(0, 2) + "] into the " + Identity.Description, LogItemType.Action); base.SendKeysInternal(tokens[0] + tokens[1]); //Wait for popup GUI.Log("Wait for the generic walker popup to appear", LogItemType.Action); timer = Stopwatch.StartNew(); bool isDropped = false; while (true) { //Get the state of the popup control if (Identity.TypeNameSpace == "LzGenericWalker") { GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "IsDropped", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call isDropped = GUI.m_APE.GetValueFromMessage(); } else { string PopupState; GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "PopupState", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "ToString", MemberTypes.Method); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call PopupState = GUI.m_APE.GetValueFromMessage(); if (PopupState == "Open") { isDropped = true; } } if (isDropped) { if (Identity.TypeNameSpace == "LzGenericWalker") { WaitForTimer("tmrResize"); } break; } if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut) { throw new Exception("Failed to find the " + Description + " dropdown"); } Thread.Sleep(15); } //Send rest of characters if (tokens.Length > 2) { // Clear the first 2 characters as they have already been sent tokens[0] = ""; tokens[1] = ""; GUI.Log("Type [" + unescapedText.Substring(2) + "] into the " + Identity.Description, LogItemType.Action); base.SendKeysInternal(string.Join("", tokens)); } break; } //wait for .Text to == text timer = Stopwatch.StartNew(); while (true) { currentText = GUI.m_APE.GetWindowTextViaWindowMessage(textboxHandle); if (currentText == unescapedText) { break; } if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut) { throw new Exception("Failed to set the text of the " + Description); } Thread.Sleep(15); } GUI.Log("Press Enter to set the value", LogItemType.Action); base.SendKeysInternal("{Enter}"); // Wait for the input to be idle after entering the value GUI.WaitForInputIdle(this); if (Identity.TypeNameSpace == "LzGenericWalker") { WaitForTimer("tmrDelayedEvent"); } } } finally { Input.Unblock(); } }
/// <summary> /// Sets the text of the generic walker control /// </summary> /// <param name="text">The text to set the control to</param> public void SetText(string text) { Stopwatch timer; string currentText; Input.Block(); try { GUITextBox textbox; if (Identity.TypeNameSpace == "LzGenericWalker" || Identity.TypeName == "AxGenericWalker") { if (Identity.TechnologyType == "Windows Forms (WinForms)" && Identity.TypeName != "AxGenericWalker") { GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "txtText", MemberTypes.Field); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call IntPtr textboxHandle = GUI.m_APE.GetValueFromMessage(); textbox = new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Handle, textboxHandle)); } else { textbox = new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Name, "txtText"), new Identifier(Identifiers.ChildOf, this)); } } else { GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "WalkerTextBox", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call IntPtr textboxHandle = GUI.m_APE.GetValueFromMessage(); textbox = new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Handle, textboxHandle)); } currentText = textbox.Text; string unescapedText = Unescape(text); if (unescapedText == currentText) { GUI.Log("Ensure " + Identity.Description + " is set to " + unescapedText, LogItemType.Action); } else { if (currentText != "") { textbox.SingleClick(MouseButton.Left); //Select everything in the textbox base.SendKeys("{HOME}+{END}"); //wait for SelectedText == Text timer = Stopwatch.StartNew(); while (true) { string selectedText = textbox.SelectedText(); if (currentText == selectedText) { break; } if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut) { throw GUI.ApeException("Failed to select all the text of the " + Description); } Thread.Sleep(15); } } // Get an array of each character token for example a or {+} string[] tokens = Tokenise(text); switch (tokens.Length) { case 0: break; default: int token = 0; int searchAfter; while (true) { if (Identity.TypeNameSpace == "LzGenericWalker" || Identity.TypeName == "AxGenericWalker") { searchAfter = GetCurrentDropAfter(); } else { string state = GetCurrentState(); //PrefixState has 4 states: Unknown, Incomplete, Valid, Invalid //The last 2 states cause the drop down to appear if (token == 0 || state == "Unknown" || state == "Incomplete") { searchAfter = token + 1; } else { searchAfter = token; } } if (token < searchAfter) { GUI.Log("Type [" + unescapedText.Substring(token, 1) + "] into the " + Identity.Description, LogItemType.Action); base.SendKeysInternal(tokens[token]); tokens[token] = ""; } else { break; } token++; if (token == tokens.Length) { break; } } if (token == tokens.Length) { break; } //Wait for popup GUI.Log("Wait for the generic walker popup to appear", LogItemType.Action); timer = Stopwatch.StartNew(); bool isDropped = false; while (true) { //Get the state of the popup control if (Identity.TypeNameSpace == "LzGenericWalker" || Identity.TypeName == "AxGenericWalker") { GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "IsDropped", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call isDropped = GUI.m_APE.GetValueFromMessage(); } else { string PopupState; GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "PopupState", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "ToString", MemberTypes.Method); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call PopupState = GUI.m_APE.GetValueFromMessage(); if (PopupState == "Open") { isDropped = true; } } if (isDropped) { break; } if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut) { throw GUI.ApeException("Failed to find the " + Description + " dropdown"); } Thread.Sleep(15); } //Send rest of characters if (tokens.Length > searchAfter) { GUI.Log("Type [" + unescapedText.Substring(searchAfter) + "] into the " + Identity.Description, LogItemType.Action); base.SendKeysInternal(string.Join("", tokens)); } break; } //wait for current text == unescaped text timer = Stopwatch.StartNew(); while (true) { currentText = textbox.Text; if (currentText == unescapedText) { break; } if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut) { throw GUI.ApeException("Failed to set the text of the " + Description); } Thread.Sleep(15); } if (Identity.TypeNameSpace == "LzGenericWalker" && Identity.TechnologyType == "Windows Forms (WinForms)") { // Add event handler GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageAddGenericWalkerSelectedHandler(DataStores.Store0, Identity.ParentHandle); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); } bool ok = false; try { GUI.Log("Press Enter to set the value", LogItemType.Action); base.SendKeysInternal("{Enter}"); ok = true; } finally { if (Identity.TypeNameSpace == "LzGenericWalker" && Identity.TechnologyType == "Windows Forms (WinForms)") { if (ok) { //Wait for the event handler then remove it GUI.m_APE.AddFirstMessageWaitForAndRemoveGenericWalkerSelectedHandler(); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); } else { //Remove the event handler GUI.m_APE.AddFirstMessageRemoveGenericWalkerSelectedHandler(); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); } } } } } catch when(Input.ResetInputFilter()) { // Will never be reached as ResetInputFilter always returns false } finally { Input.Unblock(); } }