public virtual UIItemCollection ItemsWithin(Rect bounds, ActionListener actionListener) { var collection = new UIItemCollection(); List<AutomationElement> descendants = Finder.Descendants(AutomationSearchCondition.All); foreach (AutomationElement automationElement in descendants) { if (!bounds.Contains(automationElement.Current.BoundingRectangle)) continue; var factory = new DictionaryMappedItemFactory(); collection.Add(factory.Create(automationElement, actionListener)); } return collection; }
public virtual UIItemCollection UIItems(ActionListener actionListener) { if (uiItemCollection != null) { return(uiItemCollection); } uiItemCollection = new UIItemCollection(); foreach (AutomationElement automationElement in list) { uiItemCollection.Add(dictionaryMappedItemFactory.Create(automationElement, actionListener)); } return(uiItemCollection); }
public void ReviewIUItems(UIItemCollection items) { foreach (IUIItem x in items) { Console.WriteLine($""); Console.WriteLine($"name {x.Name}"); Console.WriteLine($"id {x.Id}"); Console.WriteLine($"prime {x.PrimaryIdentification}"); Console.WriteLine($"location {x.Location}"); Console.WriteLine($"bounds {x.Bounds}"); Console.WriteLine($"type {x.GetType()}"); } }
public void TestMethod1() { Application app = base.Application; Window window = app.GetWindow(SearchCriteria.ByAutomationId("StartScreen"), InitializeOption.WithCache); Add_Level_Data(); window.WaitWhileBusy(); //click the cont button Button contBtn = window.Get <Button>(SearchCriteria.ByAutomationId("button2")); contBtn.Click(); // get cont window Window cont = app.GetWindow(SearchCriteria.ByAutomationId("ContinueGame"), InitializeOption.WithCache); cont.WaitWhileBusy(); IUIItem[] children1 = cont.GetMultiple(SearchCriteria.All); //get lvl 3 button Button lvl3Btn = (Button)children1[3]; lvl3Btn.Click(); // get game window Window game = app.GetWindow(SearchCriteria.ByAutomationId("Form3"), InitializeOption.WithCache); UIItemCollection items = game.Items; // put stuff here to win Window win = app.GetWindow(SearchCriteria.ByAutomationId("LevelComplete3"), InitializeOption.WithCache); win.WaitWhileBusy(); children1 = win.GetMultiple(SearchCriteria.All); //4-save 5-quit Button saveBtn = (Button)children1[4]; saveBtn.Click(); win.WaitWhileBusy(); Button quitBtn = (Button)children1[5]; quitBtn.Click(); app.Close(); app.Dispose(); }
public virtual UIItemCollection ItemsWithin(Rect bounds, ActionListener actionListener) { var collection = new UIItemCollection(); List <AutomationElement> descendants = finder.Descendants(AutomationSearchCondition.All); foreach (AutomationElement automationElement in descendants) { if (!bounds.Contains(automationElement.Current.BoundingRectangle)) { continue; } var factory = new DictionaryMappedItemFactory(); collection.Add(factory.Create(automationElement, actionListener)); } return(collection); }
private static int FindPromptIndex(UIItemCollection controls, int startingIndex) { int promptIndex = startingIndex; while (promptIndex >= 0) { WPFLabel textBlock = controls[promptIndex] as WPFLabel; if (textBlock != null && (textBlock.Text == DefaultPrompt || textBlock.Text == DbgPrompt || textBlock.Text == ExecutingPrompt)) { break; } promptIndex--; } return(promptIndex); }
//If it's allready open -> returns true. If it's closed it tries opens it. public static void openPianoRollContextMenu(IntPtr windowHandle, TestStack.White.UIItems.WindowItems.Window window) { TestStack.White.UIItems.Panel itemToClick = null; //TODO: use isPianoRollContextMenuOpen? //if (!isPianoRollContextMenuOpen(windowHandle, window)) //{ UIItemCollection coll = window.Items; foreach (UIItem item in coll) { if (item.Name.Contains("Piano roll")) { if (((TestStack.White.UIItems.Panel)item).Items.Count == 0) { itemToClick = (TestStack.White.UIItems.Panel)item; break; } } } //TODO: Focus alway returns false bool focus = SetForegroundWindow(windowHandle); if (focus) { var mouse = window.Mouse; Point p = itemToClick.Location; p.Offset(11, 12); mouse.Click(p); } else { //Do it as well, but log it Debug.Print("Failed to focus window"); var mouse = window.Mouse; Point p = itemToClick.Location; p.Offset(11, 12); mouse.Click(p); } //} }
//************************************************************************************************************************************************************** public static void HighLightAndShowProperties(UIItemCollection item, String elementType) { String spy = null; try { foreach (var element in item) { if (element.GetType().Name.Contains(elementType) || element.GetType().Name.Equals(elementType)) { element.RightClick(); var name = element.Name; var id = element.Id; var pid = element.PrimaryIdentification; MessageBox.Show(" Name= " + name + " ID= " + id + " PrimaryID= " + pid + " / "); AutomationProperty[] properties = element.AutomationElement.GetSupportedProperties(); foreach (var p in properties) { try { var value = element.AutomationElement.GetCurrentPropertyValue(p); var property = p.ProgrammaticName; spy = spy + " -- " + value + " / " + property; } catch (Exception e) { var err = e.Message; } } MessageBox.Show(spy.ToString()); spy = null; } } } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static void HighLightWindowElements(UIItemCollection collection) { try { foreach (IUIItem item in collection) { try { item.RightClick(); Thread.Sleep(int.Parse(Execution_Speed)); } catch (Exception) { } } } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static List<IUIItem> GetAllListItems(UIItemCollection collection) { List<IUIItem> listItems = new List<IUIItem>(); try { foreach (IUIItem element in collection) { if (element.GetType().Name.Contains("List") || element.GetType().Equals("List")) { listItems.Add(element); } } return listItems; } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static List<IUIItem> GetAllTextBoxes(UIItemCollection collection) { List<IUIItem> textBoxes = new List<IUIItem>(); try { foreach (IUIItem element in collection) { if (element.GetType().Name.Contains("Text") || element.GetType().Equals("Text")) { TestStack.White.UIItems.TextBox x = (TestStack.White.UIItems.TextBox) element; textBoxes.Add(x); } } return textBoxes; } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static void FileOutAutomationIDs(UIItemCollection collection, String fileName) { try { FileInfo test = new FileInfo(@fileName); string temp = string.Empty; using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fileName)) { foreach (IUIItem item in collection) { try { AutomationProperty p = AutomationElementIdentifiers.NameProperty; var element = item.AutomationElement.ToString(); var value = item.AutomationElement.GetCurrentPropertyValue(p).ToString(); temp = element + " / " + item.GetType().ToString() + " = " + value; file.WriteLine(temp); test.AppendText().WriteLine(temp); test.AppendText().Flush(); } catch (Exception) { } } } System.IO.File.WriteAllText(@fileName, temp); } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static List<IUIItem> GetAllCustomControls(UIItemCollection collection) { List<IUIItem> customControls = new List<IUIItem>(); try { foreach (IUIItem element in collection) { if (element.GetType().Name.Contains("Custom") || element.GetType().Equals("Custom")) { var x = (TestStack.White.UIItems.Custom.CustomUIItem)element; customControls.Add(x); } } return customControls; } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
public void PostToDatePicker(UIItemCollection items, Dictionary <string, string> valueDictionary, Window window) { UpdateDatePickersFromDictionary(valueDictionary, CreateDatePickerDictionary(items), window); }
//************************************************************************************************************************************************************** public static TestStack.White.UIItems.Panel GetPanelElementByName(UIItemCollection collection, string elementName) { Logger.logMessage("Function call @ :" + DateTime.Now); TestStack.White.UIItems.Panel p = null; try { foreach (IUIItem element in collection) { if (element.GetType().Name.Contains("Pane") && element.Name.Equals(elementName)) { p = (TestStack.White.UIItems.Panel)element; break; } } Logger.logMessage("GetPanelElementByName " + collection + "->" + elementName + " - Successful"); Logger.logMessage("------------------------------------------------------------------------------"); return p; } catch (Exception e) { Logger.logMessage("GetPanelElementByName " + collection + "->" + elementName + " - Failed"); Logger.logMessage(e.Message); Logger.logMessage("------------------------------------------------------------------------------"); String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
public void ItemsReturnsCustomUIItemToo() { UIItemCollection uiItemCollection = window.Items; Assert.AreEqual(true, uiItemCollection.Any(item => item is MyDateUIItem)); }
public void PostToComboBoxes(UIItemCollection items, Dictionary <string, string> valueDictionary) { UpdateComboBoxesFromDictionary(valueDictionary, CreateComboBoxDictionary(items)); }
//************************************************************************************************************************************************************** public static List<IUIItem> GetAllButtons(UIItemCollection collection) { Logger.logMessage("Function call @ :" + DateTime.Now); List<IUIItem> buttons = new List<IUIItem>(); try { foreach (IUIItem element in collection) { if (element.GetType().Name.Contains("Button") || element.GetType().Equals("Button")) { TestStack.White.UIItems.Button x = (TestStack.White.UIItems.Button)element; buttons.Add(x); } } Logger.logMessage("GetAllButtons " + collection + " - Successful"); Logger.logMessage("------------------------------------------------------------------------------"); return buttons; } catch (Exception e) { Logger.logMessage("GetAllButtons " + collection + " - Failed"); Logger.logMessage(e.Message); Logger.logMessage("------------------------------------------------------------------------------"); String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static void ClickWPFButton(Window win, UIItemCollection collection, String text) { Logger.logMessage("Function call @ :" + DateTime.Now); try { foreach (var item in collection) { if (item.GetType().Name.Equals("WPFButton")) { AutomationProperty[] properties = item.AutomationElement.GetSupportedProperties(); foreach (AutomationProperty p in properties) { if (item.AutomationElement.GetCurrentPropertyValue(p).Equals(text)) { item.Click(); Thread.Sleep(int.Parse(Execution_Speed)); break; } } } Logger.logMessage("ClickWPFButton " + win + "->" + collection + "->" + text + " - Successful"); Logger.logMessage("------------------------------------------------------------------------------"); Thread.Sleep(int.Parse(Execution_Speed)); } } catch (Exception e) { Logger.logMessage("ClickWPFButton " + collection + "->" + text + " - Failed"); Logger.logMessage(e.Message); Logger.logMessage("------------------------------------------------------------------------------"); String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static void HighLightWindowElements(UIItemCollection collection) { Logger.logMessage("Function call @ :" + DateTime.Now); try { foreach (IUIItem item in collection) { try { item.RightClick(); Thread.Sleep(int.Parse(Execution_Speed)); } catch (Exception) { } } Logger.logMessage("HighLightWindowElements " + collection + " - Successful"); Logger.logMessage("------------------------------------------------------------------------------"); } catch (Exception e) { Logger.logMessage("HighLightWindowElements " + collection + " - Failed"); Logger.logMessage(e.Message); Logger.logMessage("------------------------------------------------------------------------------"); String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
public virtual IUIItem Filter(UIItemCollection collection) { var list = new List<IUIItem>(collection); list.Sort(new UIItemPositionComparer()); return list.Count < (index + 1) ? null : list[index]; }
//************************************************************************************************************************************************************** public static void ClickWPFButton(Window win, UIItemCollection collection, String text) { try { foreach (var item in collection) { if (item.GetType().Name.Equals("WPFButton")) { AutomationProperty[] properties = item.AutomationElement.GetSupportedProperties(); foreach (AutomationProperty p in properties) { if (item.AutomationElement.GetCurrentPropertyValue(p).Equals(text)) { item.Click(); Thread.Sleep(int.Parse(Execution_Speed)); break; } } } Thread.Sleep(500); } } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static List<IUIItem> GetAllCustomControls(UIItemCollection collection) { Logger.logMessage("Function call @ :" + DateTime.Now); List<IUIItem> customControls = new List<IUIItem>(); try { foreach (IUIItem element in collection) { if (element.GetType().Name.Contains("Custom") || element.GetType().Equals("Custom")) { var x = (TestStack.White.UIItems.Custom.CustomUIItem)element; customControls.Add(x); } } Logger.logMessage("GetAllCustomControls " + collection + " - Successful"); Logger.logMessage("------------------------------------------------------------------------------"); return customControls; } catch (Exception e) { Logger.logMessage("GetAllCustomControls " + collection + " - Successful"); Logger.logMessage(e.Message); Logger.logMessage("------------------------------------------------------------------------------"); String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static List<IUIItem> GetAllListItems(UIItemCollection collection) { Logger.logMessage("Function call @ :" + DateTime.Now); List<IUIItem> listItems = new List<IUIItem>(); try { foreach (IUIItem element in collection) { if (element.GetType().Name.Contains("List") || element.GetType().Equals("List")) { listItems.Add(element); } } Logger.logMessage("GetAllListItems " + collection + " - Successful"); Logger.logMessage("------------------------------------------------------------------------------"); return listItems; } catch (Exception e) { Logger.logMessage("GetAllListItems " + collection + " - Failed"); Logger.logMessage(e.Message); Logger.logMessage("------------------------------------------------------------------------------"); String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
public void TestMethod1() { TestStack.White.Application app = base.Application; Window window = app.GetWindow(SearchCriteria.ByAutomationId("StartScreen"), InitializeOption.WithCache); Delete_LevelData(); window.WaitWhileBusy(); //click the cont button Button contBtn = window.Get <Button>(SearchCriteria.ByAutomationId("button2")); contBtn.Click(); // get cont window Window cont = app.GetWindow(SearchCriteria.ByAutomationId("ContinueGame"), InitializeOption.WithCache); cont.WaitWhileBusy(); IUIItem[] children1 = cont.GetMultiple(SearchCriteria.All); //get lvl 1 button Button lvl1Btn = (Button)children1[1]; lvl1Btn.Click(); // get game window Window game = app.GetWindow(SearchCriteria.ByAutomationId("Form1"), InitializeOption.NoCache); game.Focus(); UIItemCollection items = game.Items; items[24].Focus(); SendKeys.Send("{SPACE}"); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RIGHT);//winElem14.SendKeys(Keys.Right); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);//winElem14.SendKeys(Keys.Space); //input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.LEFT);//winElem14.SendKeys(Keys.Left); Window win = app.GetWindow(SearchCriteria.ByAutomationId("LevelComplete"), InitializeOption.WithCache); win.WaitWhileBusy(); children1 = win.GetMultiple(SearchCriteria.All); //35 Button saveBtn = (Button)children1[4]; saveBtn.Click(); win.WaitWhileBusy(); Button quitBtn = (Button)children1[5]; quitBtn.Click(); app.Close(); app.Dispose(); }
public virtual IUIItem IndexedItem(UIItemCollection collection) { return indexCondition.Filter(collection); }
public virtual IUIItem IndexedItem(UIItemCollection collection) { return(indexCondition.Filter(collection)); }
//************************************************************************************************************************************************************** public static bool ClickButtonByOrientation(UIItemCollection item, String identifier) { AutomationProperty p = AutomationElementIdentifiers.OrientationProperty; try { foreach (IUIItem element in item) { if (element.GetType().Name.Contains("Button") || element.GetType().Name.Equals("Button")) { if (element.Name.Equals(identifier) || element.Id.Equals(identifier) || element.PrimaryIdentification.Equals(identifier)) { element.Click(); Thread.Sleep(int.Parse(Execution_Speed)); return true; } } } return false; } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }