public static AutomationElement GetTaskbar() { PropertyCondition cond = new PropertyCondition(AutomationElement.ClassNameProperty, "Shell_TrayWnd"); return(AutomationElement.RootElement.FindFirst(TreeScope.TreeScope_Subtree, cond)); }
public static AutomationElementCollection FindElementByControlType(this AutomationElement ae, string controlType) { Condition c = null; AutomationElement elementList = null; if (ae == null || String.IsNullOrEmpty(controlType)) { throw new InvalidOperationException("invalid operation"); } // Set up the CacheRequest. CacheRequest cacheRequest = new CacheRequest(); cacheRequest.Add(AutomationElement.ControlTypeProperty); cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children; using (cacheRequest.Activate()) { switch (controlType) { case "List": // Set a property condition that will be used to find the control. c = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.List); elementList = ae.FindFirst(TreeScope.Descendants, c); break; case "Tree": // Set a property condition that will be used to find the control. c = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Tree); elementList = ae.FindFirst(TreeScope.Descendants, c); break; case "Grid": // Set a property condition that will be used to find the control. c = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.DataGrid); elementList = ae.FindFirst(TreeScope.Descendants, c); break; case "Tab": // Set a property condition that will be used to find the control. c = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Tab); elementList = ae.FindFirst(TreeScope.Descendants, c); break; case "Combo": // Set a property condition that will be used to find the control. c = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ComboBox); elementList = ae.FindFirst(TreeScope.Descendants, c); break; default: break; } // Find the element. return(elementList.CachedChildren); } }
public ScrollableBase() : base() { base.Layout = new ScrollableBaseCustomLayout(); mPanGestureDetector = new PanGestureDetector(); mPanGestureDetector.Attach(this); mPanGestureDetector.AddDirection(PanGestureDetector.DirectionVertical); mPanGestureDetector.Detected += OnPanGestureDetected; mTapGestureDetector = new TapGestureDetector(); mTapGestureDetector.Attach(this); mTapGestureDetector.Detected += OnTapGestureDetected; ClippingMode = ClippingModeType.ClipChildren; //Default Scrolling child ContentContainer = new View() { WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent, HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent, Layout = new AbsoluteLayout() { SetPositionByLayout = false }, }; ContentContainer.Relayout += OnScrollingChildRelayout; propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(1.0f)); propertyNotification.Notified += OnPropertyChanged; base.Add(ContentContainer); //Interrupt touching when panning is started mInterruptTouchingChild = new View() { Size = new Size(Window.Instance.WindowSize), BackgroundColor = Color.Transparent, }; mInterruptTouchingChild.TouchEvent += OnIterruptTouchingChildTouched; Scrollbar = new Scrollbar(); }
/// <summary> /// /// </summary> /// <param name="controlName"></param> /// <returns></returns> public static PropertyCondition GetNameProperty(object controlName) { propertyCondition = new PropertyCondition(AutomationElement.NameProperty, controlName); return(propertyCondition); }
static void Main(string[] args) { string XenCenterInstallStatusFile = "C:\\XenCenterInstalled.txt"; String TestStatus = "Pass"; Logger NewLogObj = new Logger(); NewLogObj.CreateLogFolder(); string LogFilePath = NewLogObj.CreateLogFile(); NewLogObj.WriteLogFile(LogFilePath, "Test : Installer", "info"); NewLogObj.WriteLogFile(LogFilePath, "======================", "info"); if (File.Exists(XenCenterInstallStatusFile)) { File.Delete(XenCenterInstallStatusFile); } FileOperations FileObj = new FileOperations(); string InputFilePath = FileObj.GetInputFilePath(LogFilePath, "Inputs.txt"); string InstallerLocation = FileObj.GetInputPattern(InputFilePath, "InstallerLocation"); string InstallerProcessName = FileObj.GetInputPattern(InputFilePath, "InstallerProcessName"); string LocationToInstallXenCenter = FileObj.GetInputPattern(InputFilePath, "LocationToInstallXenCenter"); string XenCenterVersion = FileObj.GetInputPattern(InputFilePath, "XenCenterVersion"); string SetUpWindowTitle = "Citrix XenCenter Setup"; string InterruptedDialog = "Citrix XenCenter Setup Wizard was interrupted"; string HelpMenu = "&Help"; string AboutXenCenterMenu = "&About XenCenter"; string LocalizedFilePath = FileObj.GetLocalizedFilePath(); //if (LocalizedFilePath != null) //{ SetUpWindowTitle = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, SetUpWindowTitle); InterruptedDialog = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, InterruptedDialog); HelpMenu = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, HelpMenu); AboutXenCenterMenu = FileObj.GetLocalizedMappedPattern(LocalizedFilePath, AboutXenCenterMenu); //} //else //{ // //Substitue the & // HelpMenu = FileObj.RemovePatternFromString(HelpMenu, "&"); // AboutXenCenterMenu = FileObj.RemovePatternFromString(AboutXenCenterMenu, "&"); //} //string InputFilePath1 = FileObj.GetInputFilePath(LogFilePath, "Mapped_CH.txt"); //string SetupWindowTitle = FileObj.SearchFileForPattern(InputFilePath1, "Citrix XenCenter Setup", 1, LogFilePath); //int IndexEqual2 = SetupWindowTitle.IndexOf("="); //SetupWindowTitle = SetupWindowTitle.Substring(IndexEqual2 + 1); Console.WriteLine("InstallerLocation " + InstallerLocation); Console.WriteLine("InstallerProcessName " + InstallerProcessName); Generic GenricObj = new Generic(); GenricObj.StartProcess(InstallerLocation, InstallerProcessName, LogFilePath, 1); Thread.Sleep(5000); //Console.WriteLine("handling UAC"); ////Assuming that UAC prompt is on the screen //System.Windows.Forms.SendKeys.SendWait("{LEFT}"); //Thread.Sleep(1000); //System.Windows.Forms.SendKeys.SendWait("{ENTER}"); //Thread.Sleep(3000); // Console.WriteLine("Click send to UAC"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); PropertyCondition WindowReturnCondition = GuiObj.SetPropertyCondition("NameProperty", SetUpWindowTitle, 1, LogFilePath); AutomationElement SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); Console.WriteLine("Checking for SetupDialog "); NewLogObj.WriteLogFile(LogFilePath, "Checking for SetupDialog", "info"); int WaitTimeOut = 240000;//3 mins int timer = 0; while (SetupDialogObj == null && timer < WaitTimeOut) { SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); Thread.Sleep(3000); timer = timer + 3000; NewLogObj.WriteLogFile(LogFilePath, "Waiting for SetupDialog", "info"); Console.WriteLine("Waiting for SetupDialog "); } if (SetupDialogObj == null && timer < WaitTimeOut) { Console.WriteLine("Timeout waiting for setup dialog obj.Exiting.. "); Console.WriteLine("Timeout waiting for SetupDialog obj.Exiting.. "); FileObj.ExitTestEnvironment(); } NewLogObj.WriteLogFile(LogFilePath, "SetupDialog obj found", "info"); Console.WriteLine("SetupDialog obj found "); //Click cancel btn & verify actions Program PgmObj = new Program(); PgmObj.ClickCancel(SetupDialogObj, SetUpWindowTitle, "yes"); PgmObj.CheckInterruptedDialog(WindowReturnCondition, InterruptedDialog); PgmObj.ClickFinishBtn(WindowReturnCondition);; //Start installer again GenricObj.StartProcess(InstallerLocation, InstallerProcessName, LogFilePath, 1); Thread.Sleep(3000); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); timer = 0; while (SetupDialogObj == null && timer < WaitTimeOut) { SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); Thread.Sleep(3000); timer = timer + 3000; NewLogObj.WriteLogFile(LogFilePath, "Waiting for SetupDialog", "info"); Console.WriteLine("Waiting for SetupDialog "); } if (SetupDialogObj == null && timer < WaitTimeOut) { Console.WriteLine("Timeout waiting for setup dialog obj.Exiting.. "); Console.WriteLine("Timeout waiting for SetupDialog obj.Exiting.. "); FileObj.ExitTestEnvironment(); } //Click cancel & no PgmObj.ClickCancel(SetupDialogObj, SetUpWindowTitle, "no"); //Verify SetupDialogObj is still there SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); if (SetupDialogObj != null) { NewLogObj.WriteLogFile(LogFilePath, "SetupDialogObj is there after pressing on no btn", "info"); } PropertyCondition NextBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "613", 1, LogFilePath); AutomationElement NextBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, NextBtnReturnCondition, TreeScope.Descendants, "Next Btn", 1, LogFilePath); GuiObj.ClickButton(NextBtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); ////Destination text //PropertyCondition DestinationTextReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "679", 1, LogFilePath); //AutomationElement DestinationTextObj = GuiObj.FindAutomationElement(SetupDialogObj, DestinationTextReturnCondition, TreeScope.Descendants, "Xencenter install DestinationTextObj", 1, LogFilePath); //Click on browse btn PropertyCondition BrowseBtnReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "683", 1, LogFilePath); AutomationElement BrowseBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, BrowseBtnReturnCondition, TreeScope.Descendants, "Next Btn", 1, LogFilePath); GuiObj.ClickButton(BrowseBtnObj, 1, "Browse Button", 1, LogFilePath); //Verify if child winodw with xencenter location has apperaed AutomationElement LocationChildWndObj = GuiObj.FindAutomationElement(SetupDialogObj, WindowReturnCondition, TreeScope.Descendants, "Xencenter install location browse", 1, LogFilePath); //LOcate the textbox having location PropertyCondition LocationEditCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "547", 1, LogFilePath); AutomationElement LocationObj = GuiObj.FindAutomationElement(LocationChildWndObj, LocationEditCondition, TreeScope.Descendants, "Xencenter install location edit box", 1, LogFilePath); GuiObj.SetTextBoxText(LocationObj, LocationToInstallXenCenter, "Xencenter Install location textbox", 1, LogFilePath); PropertyCondition OKBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "549", 1, LogFilePath); AutomationElement OKbtnObj = GuiObj.FindAutomationElement(LocationChildWndObj, OKBtnCondition, TreeScope.Descendants, "Xencenter install location edit box", 1, LogFilePath); GuiObj.ClickButton(OKbtnObj, 1, "OK Button", 1, LogFilePath); Thread.Sleep(2000); //find the radio btns PropertyCondition ForAllRadioBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "507", 1, LogFilePath); AutomationElement ForAllradioBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, ForAllRadioBtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.SetRadioButton(ForAllradioBtnObj, "Install for all radioBytn", 1, LogFilePath); Thread.Sleep(1000); PropertyCondition ForMeRadioBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "781", 1, LogFilePath); AutomationElement ForMeradioBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, ForMeRadioBtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.SetRadioButton(ForMeradioBtnObj, "Install for me radioBytn", 1, LogFilePath); Thread.Sleep(1000); //Click next btn PropertyCondition Next1BtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "613", 1, LogFilePath); AutomationElement Next1BtnObj = GuiObj.FindAutomationElement(SetupDialogObj, Next1BtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.ClickButton(Next1BtnObj, 1, "Next Button", 1, LogFilePath); SetupDialogObj = GuiObj.FindAutomationElement(AutomationElement.RootElement, WindowReturnCondition, TreeScope.Children, "Xencenter Setup window", 1, LogFilePath); //Click install btn PropertyCondition InstallBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "648", 1, LogFilePath); AutomationElement InstallBtnObj = GuiObj.FindAutomationElement(SetupDialogObj, InstallBtnCondition, TreeScope.Descendants, "Xencenter install for all radiobtn", 1, LogFilePath); GuiObj.ClickButton(InstallBtnObj, 1, "Install Button", 1, LogFilePath); AutomationElement FinishBtnObj = PgmObj.WaitTillFinishButtonIsActive(WindowReturnCondition); if (FinishBtnObj == null) { NewLogObj.WriteLogFile(LogFilePath, "Xencenter installation timeout", "fail"); NewLogObj.WriteLogFile(LogFilePath, "Exiting ...", "fail"); FileObj.ExitTestEnvironment(); } GuiObj.ClickButton(FinishBtnObj, 0, "Finish Button", 1, LogFilePath); File.Create(XenCenterInstallStatusFile); PgmObj.CheckXenCenterInstalledVersion(HelpMenu, AboutXenCenterMenu, XenCenterVersion); FileObj.FinishCurrentTest("Installer"); }
public static AutomationElement GetApplicationRoot(int processId) { var processIdCondition = new PropertyCondition(AutomationElement.ProcessIdProperty, processId); return(AutomationElement.RootElement.FindFirst(TreeScope.Children, processIdCondition)); }
/// <summary> /// Creats the condition to search an AutomationElemente depending on <see cref="GeneralProperties"/> object /// </summary> /// <param name="properties">the properties to search</param> /// <returns>a Condition object</returns> private Condition setPropertiesCondition(GeneralProperties properties) { Condition resultCondition; #region Readable from all resultCondition = new PropertyCondition(AutomationElement.ClassNameProperty, properties.classNameFiltered); // ... ? #endregion if (properties.localizedControlTypeFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, properties.localizedControlTypeFiltered), resultCondition); } if (properties.acceleratorKeyFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.AcceleratorKeyProperty, properties.acceleratorKeyFiltered), resultCondition); } if (properties.accessKeyFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.AccessKeyProperty, properties.accessKeyFiltered), resultCondition); } if (properties.runtimeIDFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.RuntimeIdProperty, properties.runtimeIDFiltered), resultCondition); } if (properties.frameWorkIdFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.FrameworkIdProperty, properties.frameWorkIdFiltered), resultCondition); } if (properties.isContentElementFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.IsContentElementProperty, properties.isContentElementFiltered), resultCondition); } if (properties.labeledByFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.LabeledByProperty, properties.labeledByFiltered), resultCondition); } if (properties.isControlElementFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.IsControlElementProperty, properties.isControlElementFiltered), resultCondition); } if (properties.isPasswordFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.IsPasswordProperty, properties.isPasswordFiltered), resultCondition); } if (properties.itemTypeFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.ItemTypeProperty, properties.itemTypeFiltered), resultCondition); } if (properties.itemStatusFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.ItemStatusProperty, properties.itemStatusFiltered), resultCondition); } if (properties.isRequiredForFormFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.IsRequiredForFormProperty, properties.isRequiredForFormFiltered), resultCondition); } if (properties.autoamtionIdFiltered != null) { resultCondition = new AndCondition(new PropertyCondition(AutomationElement.AutomationIdProperty, properties.autoamtionIdFiltered), resultCondition); } //.. return(resultCondition); }
public void PropertyConditionTest() { AssertRaises <ArgumentNullException> ( () => new PropertyCondition(null, null), "passing null to both params of PropertyCondition constructor"); //Load for everything in AEIds VerifyPropertyConditionBasics(AEIds.AcceleratorKeyProperty, new object [] { string.Empty, null }, new object [] { 5 }); VerifyPropertyConditionBasics(AEIds.AccessKeyProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.AutomationIdProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.BoundingRectangleProperty, new object [] { Rect.Empty }, new object [] { null, true }, new object [] { new double [] { double.PositiveInfinity, double.PositiveInfinity, double.NegativeInfinity, double.NegativeInfinity } }); VerifyPropertyConditionBasics(AEIds.ClassNameProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.ClickablePointProperty, new object [] { new Point(0, 0) }, new object [] { null, true }, new object [] { new double [] { 0, 0 } }); VerifyPropertyConditionBasics(AEIds.ControlTypeProperty, new object [] { ControlType.Button, null }, new object [] { ControlType.Button.Id, string.Empty }, new object [] { ControlType.Button.Id, null }); VerifyPropertyConditionBasics(AEIds.CultureProperty, new object [] { new CultureInfo("en-US"), new CultureInfo("fr-FR"), null }, new object [] { new CultureInfo("en-US").LCID, "en-US", string.Empty, 5 }, new object [] { new CultureInfo("en-US").LCID, new CultureInfo("fr-FR").LCID, null }); VerifyPropertyConditionBasics(AEIds.FrameworkIdProperty, new object [] { "WinForm", string.Empty, "hiya", null }, new object [] { 5 }); VerifyPropertyConditionBasics(AEIds.HasKeyboardFocusProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.HelpTextProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.IsContentElementProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsControlElementProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsDockPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsEnabledProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsExpandCollapsePatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsGridItemPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsGridPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsInvokePatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsKeyboardFocusableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsMultipleViewPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsOffscreenProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsPasswordProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsRangeValuePatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsRequiredForFormProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsScrollItemPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsScrollPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsSelectionItemPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsSelectionPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsTableItemPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsTablePatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsTextPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsTogglePatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsTransformPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsValuePatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.IsWindowPatternAvailableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(AEIds.ItemStatusProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.ItemTypeProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.LabeledByProperty, new object [] { button1Element, null }, new object [] { string.Empty, true }, new object [] { button1Element.GetRuntimeId(), null }); VerifyPropertyConditionBasics(AEIds.LocalizedControlTypeProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.NameProperty, new object [] { string.Empty, null }, new object [] { true }); VerifyPropertyConditionBasics(AEIds.NativeWindowHandleProperty, new object [] { 5 }, new object [] { null, string.Empty, true }); VerifyPropertyConditionBasics(AEIds.OrientationProperty, new object [] { OrientationType.Horizontal }, new object [] { null, true }); VerifyPropertyConditionBasics(AEIds.ProcessIdProperty, new object [] { 5 }, new object [] { null, true }); VerifyPropertyConditionBasics(AEIds.RuntimeIdProperty, new object [] { new int [] { 5, 6, 7 }, null }, new object [] { true }); // Load everything for *PatternIdentifiers VerifyPropertyConditionBasics(DockPatternIdentifiers.DockPositionProperty, new object [] { DockPosition.Bottom }, new object [] { null, true }); VerifyPropertyConditionBasics(ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, new object [] { ExpandCollapseState.Collapsed }, new object [] { null, true }); VerifyPropertyConditionBasics(GridItemPatternIdentifiers.ColumnProperty, new object [] { 5, -5 }, new object [] { null, true }); VerifyPropertyConditionBasics(GridItemPatternIdentifiers.ColumnSpanProperty, new object [] { 5, -5 }, new object [] { null, true }); VerifyPropertyConditionBasics(GridItemPatternIdentifiers.ContainingGridProperty, new object [] { button1Element, null }, new object [] { true }, new object [] { button1Element.GetRuntimeId(), null }); VerifyPropertyConditionBasics(GridItemPatternIdentifiers.RowProperty, new object [] { 5, -5 }, new object [] { null, true }); VerifyPropertyConditionBasics(GridItemPatternIdentifiers.RowSpanProperty, new object [] { 5, -5 }, new object [] { null, true }); VerifyPropertyConditionBasics(GridPatternIdentifiers.ColumnCountProperty, new object [] { 5, -5 }, new object [] { null, true }); VerifyPropertyConditionBasics(GridPatternIdentifiers.RowCountProperty, new object [] { 5, -5 }, new object [] { null, true }); VerifyPropertyConditionBasics(MultipleViewPatternIdentifiers.CurrentViewProperty, new object [] { 5, -5 }, new object [] { null, true }); VerifyPropertyConditionBasics(MultipleViewPatternIdentifiers.SupportedViewsProperty, new object [] { new int [] { 5, -5 }, new int [] { }, null }, new object [] { true }); VerifyPropertyConditionBasics(RangeValuePatternIdentifiers.IsReadOnlyProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(RangeValuePatternIdentifiers.LargeChangeProperty, new object [] { 5.0, -5.0, 1.2 }, new object [] { null, 5, -5, true }); VerifyPropertyConditionBasics(RangeValuePatternIdentifiers.MaximumProperty, new object [] { 5.0, -5.0, 1.2, 5, -5, true, string.Empty, null }, new object [] { }); VerifyPropertyConditionBasics(RangeValuePatternIdentifiers.MinimumProperty, new object [] { 5.0, -5.0, 1.2, 5, -5, true, string.Empty, null }, new object [] { }); VerifyPropertyConditionBasics(RangeValuePatternIdentifiers.SmallChangeProperty, new object [] { 5.0, -5.0, 1.2 }, new object [] { null, 5, -5, true }); VerifyPropertyConditionBasics(RangeValuePatternIdentifiers.ValueProperty, new object [] { 5.0, -5.0, 1.2 }, new object [] { null, 5, -5, true }); VerifyPropertyConditionBasics(ScrollPatternIdentifiers.HorizontallyScrollableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(ScrollPatternIdentifiers.HorizontalScrollPercentProperty, new object [] { 5.0, -5.0, 1.2 }, new object [] { null, 5, -5, true }); VerifyPropertyConditionBasics(ScrollPatternIdentifiers.HorizontalViewSizeProperty, new object [] { 5.0, -5.0, 1.2 }, new object [] { null, 5, -5, true }); VerifyPropertyConditionBasics(ScrollPatternIdentifiers.VerticallyScrollableProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(ScrollPatternIdentifiers.VerticalScrollPercentProperty, new object [] { 5.0, -5.0, 1.2 }, new object [] { null, 5, -5, true }); VerifyPropertyConditionBasics(ScrollPatternIdentifiers.VerticalViewSizeProperty, new object [] { 5.0, -5.0, 1.2 }, new object [] { null, 5, -5, true }); VerifyPropertyConditionBasics(SelectionItemPatternIdentifiers.IsSelectedProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(SelectionItemPatternIdentifiers.SelectionContainerProperty, new object [] { button1Element, null }, new object [] { true }, new object [] { button1Element.GetRuntimeId(), null }); VerifyPropertyConditionBasics(SelectionPatternIdentifiers.CanSelectMultipleProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(SelectionPatternIdentifiers.IsSelectionRequiredProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(SelectionPatternIdentifiers.SelectionProperty, new object [] { new AutomationElement [] { button1Element }, null }, new object [] { button1Element, true }); VerifyPropertyConditionBasics(TableItemPatternIdentifiers.ColumnHeaderItemsProperty, new object [] { new AutomationElement [] { button1Element }, null }, new object [] { button1Element, true }); VerifyPropertyConditionBasics(TableItemPatternIdentifiers.RowHeaderItemsProperty, new object [] { new AutomationElement [] { button1Element }, null }, new object [] { button1Element, true }); VerifyPropertyConditionBasics(TablePatternIdentifiers.ColumnHeadersProperty, new object [] { new AutomationElement [] { button1Element }, null }, new object [] { button1Element, true }); VerifyPropertyConditionBasics(TablePatternIdentifiers.RowHeadersProperty, new object [] { new AutomationElement [] { button1Element }, null }, new object [] { button1Element, true }); VerifyPropertyConditionBasics(TablePatternIdentifiers.RowOrColumnMajorProperty, new object [] { RowOrColumnMajor.ColumnMajor, AutomationElement.NotSupported }, new object [] { null, true }); VerifyPropertyConditionBasics(TogglePatternIdentifiers.ToggleStateProperty, new object [] { ToggleState.Indeterminate }, new object [] { null, true }); VerifyPropertyConditionBasics(TransformPatternIdentifiers.CanMoveProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(TransformPatternIdentifiers.CanResizeProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(TransformPatternIdentifiers.CanRotateProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(ValuePatternIdentifiers.IsReadOnlyProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(ValuePatternIdentifiers.ValueProperty, new object [] { string.Empty, null }, new object [] { 5, true }); VerifyPropertyConditionBasics(WindowPatternIdentifiers.CanMaximizeProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(WindowPatternIdentifiers.CanMinimizeProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(WindowPatternIdentifiers.IsModalProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(WindowPatternIdentifiers.IsTopmostProperty, new object [] { true }, new object [] { null, string.Empty }); VerifyPropertyConditionBasics(WindowPatternIdentifiers.WindowInteractionStateProperty, new object [] { WindowInteractionState.BlockedByModalWindow }, new object [] { null, true }); VerifyPropertyConditionBasics(WindowPatternIdentifiers.WindowVisualStateProperty, new object [] { WindowVisualState.Maximized }, new object [] { null, true }); Assert.IsNotNull(button1Element.FindFirst(TreeScope.Element, new PropertyCondition(AEIds.NameProperty, "button1"))); Assert.IsNull(button1Element.FindFirst(TreeScope.Element, new PropertyCondition(AEIds.NameProperty, "Button1"))); Assert.IsNull(button1Element.FindFirst(TreeScope.Element, new PropertyCondition(AEIds.NameProperty, "Button1", PropertyConditionFlags.None))); Assert.IsNotNull(button1Element.FindFirst(TreeScope.Element, new PropertyCondition(AEIds.NameProperty, "Button1", PropertyConditionFlags.IgnoreCase))); PropertyCondition cond1 = new PropertyCondition(AEIds.NameProperty, string.Empty); PropertyCondition cond2 = new PropertyCondition(AEIds.NameProperty, string.Empty); Assert.AreNotEqual(cond1, cond2); }
public void Initialize() { GetTestCatgoryInformation(); EndStartedOutLook(); Thread.Sleep(10000); MessageParser.ClearSessions(); string outLookPath = ConfigurationManager.AppSettings["OutLookPath"].ToString(); waittime_window = Int32.Parse(ConfigurationManager.AppSettings["WaitTimeWindow"].ToString()); waittime_item = Int32.Parse(ConfigurationManager.AppSettings["WaitTimeItem"].ToString()); Process p = Process.Start(outLookPath); AutomationElement outlookWindow = null; var desktop = AutomationElement.RootElement; string userName = ConfigurationManager.AppSettings["Office365Account"].ToString(); var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook"); int count = 0; while (outlookWindow == null) { outlookWindow = desktop.FindFirst(TreeScope.Children, condition_Outlook); Thread.Sleep(waittime_item / 10); count += (waittime_item / 10); if (count >= waittime_window) { break; } } Process[] pp = Process.GetProcesses(); if (pp.Count() > 0) { foreach (Process pp1 in pp) { if (pp1.ProcessName != "OUTLOOK" && pp1.ProcessName != "explorer" && pp1.MainWindowHandle != IntPtr.Zero) { AutomationElement element = AutomationElement.FromHandle(pp1.MainWindowHandle); if (element != null) { try { element.SetFocus(); } catch { continue; } } break; } } } Thread.Sleep(waittime_item); try { oApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application; } catch { throw new Exception("Get active outlook application failed, please check if outlook is running"); } inboxFolders = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); sentMailFolder = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail); deletedItemsFolders = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems); draftsFolders = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts); }
/// <summary> /// タイムラインウィンドウのキャラ選択コンボボックスからキャラを選択する。 /// </summary> /// <param name="name">選択するキャラ名。</param> /// <returns> /// 成功したならば true 。 /// キャラ名が存在しないならば null 。 /// どちらでもなければ false 。 /// </returns> public async Task <bool?> SelectTimelineCharaComboBoxItem(string name) { if (!this.IsTimelineElementFound) { return(false); } // すべてのアイテムを有効化させるためにコンボボックスを開閉する var expand = GetPattern <ExpandCollapsePattern>( this.CharaComboElement, ExpandCollapsePattern.Pattern); if (expand == null) { ThreadDebug.WriteLine( @"YMM3 : CharaComboElement から ExpandCollapsePattern を取得できない。"); return(false); } try { await this.WhenForInputIdle(); expand.Expand(); expand.Collapse(); } catch (Exception ex) { ThreadDebug.WriteException(ex); return(false); } // Name がキャラ名の子を持つコンボボックスアイテムUIを探す var nameCond = new PropertyCondition(AutomationElement.NameProperty, name); var itemElem = await FindAllChildren( this.CharaComboElement, AutomationElement.ControlTypeProperty, ControlType.ListItem) .ToObservable() .FirstOrDefaultAsync(i => FindFirstChild(i, nameCond) != null); if (itemElem == null) { // キャラ名存在せず return(null); } // SelectionItemPattern 取得 var item = GetPattern <SelectionItemPattern>(itemElem, SelectionItemPattern.Pattern); if (item == null) { ThreadDebug.WriteLine( @"YMM3 : CharaComboElement から SelectionItemPattern を取得できない。"); return(false); } // アイテム選択 try { await this.WhenForInputIdle(); item.Select(); } catch (Exception ex) { ThreadDebug.WriteException(ex); return(false); } return(true); }
public DialogMonitorResult ExecuteDialogSlapDown(Action <string> ifSlappedAction) { if (ifSlappedAction == null) { throw new ArgumentNullException("ifSlappedAction"); } var noActionTaken = DialogMonitorResult.NoSlapdownAction(); if (!_webBrowserToMonitor.ProcessId.HasValue) { _logger.Debug("MessageBoxMonitor - do not have processId"); return(noActionTaken); } int processId = _webBrowserToMonitor.ProcessId.Value; var processIdCond = new PropertyCondition(AutomationElement.ProcessIdProperty, processId); var appWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, processIdCond); if (appWindow == null) { _logger.Debug("COULD NOT FIND THE AUTOMATION ELEMENT FOR processId {0}".FormatWith(processId)); return(noActionTaken); } var dialogCond = new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "Dialog"); var dialogWindow = appWindow.FindFirst(TreeScope.Children, dialogCond); if (dialogWindow == null) { //_logger.Debug("COULD NOT FIND THE AUTOMATION ELEMENT FOR dialgWindow 'Dialog'"); return(noActionTaken); } if (dialogWindow.Current.Name.Contains("Assertion Failed")) { return(noActionTaken); } var okButtonCond = new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "button"); var okButtonNameCond = new PropertyCondition(AutomationElement.NameProperty, "OK"); var okCond = new AndCondition(okButtonCond, okButtonNameCond); var okButton = dialogWindow.FindFirst(TreeScope.Children, okCond); if (okButton == null) { _logger.Debug("COULD NOT FIND THE okButton"); return(noActionTaken); } var buttonClicInvokePattern = okButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; if (buttonClicInvokePattern == null) { _logger.Debug("COULD NOT FIND THE buttonClicInvokePattern"); return(noActionTaken); } string caption = dialogWindow.GetNamePropertyOf(AutomationTypes.ControlText); string text = dialogWindow.GetNamePropertyOf(AutomationTypes.ControlTitleBar); string msg = @"A Silverlight MessageBox dialog was automatically closed. Caption: {0} Dialog Message: {1}".FormatWith(caption, text); ifSlappedAction(msg); _logger.Debug("Clicking OK on a dialog (MessageBox)"); // Close the dialgo by clicking OK buttonClicInvokePattern.Invoke(); return(new DialogMonitorResult { WasActionTaken = true, Message = msg, }); }
//获取所有交易所的品种、合约 private List <Exchange> getAllExchanges() { List <IntPtr> wndHandles = WindowsApiUtils.findWindowHandlesByClassTitleFuzzy(CLASS_DIALOG, FuturesAnalysisPage.FUTURES_ANALYSIS_PAGE_TITLE); if (wndHandles.Count == 0) { PageUtils.frontMessageBox(this, "打开“挑选要分析的股票,合约或品种”界面失败,未找到该界面"); return(null); } else if (wndHandles.Count > 1) { PageUtils.frontMessageBox(this, "找到多个“挑选要分析的股票,合约或品种”界面,请关闭多余界面"); return(null); } IntPtr handle = wndHandles[0]; AutomationElement targetWindow = AutomationElement.FromHandle(handle); if (targetWindow != null) { WindowsApiUtils.clearOtherWindows(mainHandle, new List <IntPtr> { handle }); PropertyCondition condition0 = new PropertyCondition(AutomationElement.AutomationIdProperty, FuturesAnalysisPage.AUTOMATION_ID_TREEVIEW_EXCHANGE); PropertyCondition condition1 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tree); AutomationElement treeviewExchange = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition0, condition1)); if (treeviewExchange != null) { List <Exchange> exchanges = new List <Exchange>(); Condition condition2 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem); AutomationElementCollection exchangeElementCollection = treeviewExchange.FindAll(TreeScope.Children, condition2); if (exchangeElementCollection != null && exchangeElementCollection.Count > 0) { foreach (AutomationElement exchangeAE in exchangeElementCollection) { string exchangeName = exchangeAE.Current.Name; if (FuturesAnalysisPage.isDomesticFutures(exchangeName)) { if (SimulateOperating.expandTreeItem(exchangeAE)) { Exchange exchange = new Exchange(); exchange.exchangeName = exchangeName; List <Variety> varieties = new List <Variety>(); exchange.varieties = varieties; exchanges.Add(exchange); Condition condition3 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem); AutomationElementCollection varietyElementCollection = exchangeAE.FindAll(TreeScope.Children, condition3); if (varietyElementCollection != null && varietyElementCollection.Count > 0) { foreach (AutomationElement varietyAE in varietyElementCollection) { Variety variety = new Variety(); variety.varietyName = varietyAE.Current.Name; varieties.Add(variety); } } } else { PageUtils.frontMessageBox(this, "展开“挑选要分析的股票,合约或品种”界面中的“" + exchangeAE.Current.Name + "”子项失败"); WindowsApiUtils.closeWindow(handle); return(null); } } } WindowsApiUtils.closeWindow(handle); return(exchanges); } else { PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面中的“品种”树形结构的子项"); WindowsApiUtils.closeWindow(handle); return(null); } } else { PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面中的“品种”树形结构"); WindowsApiUtils.closeWindow(handle); return(null); } } else { PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面"); WindowsApiUtils.closeWindow(handle); return(null); } }
// Too complex... private static List <MeasurementResult> FindCandidates(DirectionFunction function, Rect focusedBounds, AutomationElement root, Unit unit) { List <MeasurementResult> results = new List <MeasurementResult>(); var children = root.FindAll(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition)?.Cast <AutomationElement>(); if (children == null) { return(results); } AutomationElement candidate = null; List <MeasurementResult> candidates = new List <MeasurementResult>(); List <AutomationElement> focusedAncestors = new List <AutomationElement>(); double nearestFocusableDistance = double.PositiveInfinity; foreach (var element in children) { var info = element.Current; var bounds = info.BoundingRectangle; var controlType = info.ControlType; // for WPF(Tab and TabItem) if (controlType == ControlType.Tab) { focusedAncestors.Add(element); } else if (controlType == ControlType.TabItem) { candidates.Add(new MeasurementResult(element, _weightingValue * 3)); } if (_excludes.Any(x => x == bounds)) { continue; } if (bounds.Contains(focusedBounds) || bounds == _zero) { focusedAncestors.Add(element); continue; } if (!function.IsInDirection(bounds, focusedBounds) || bounds == focusedBounds) { continue; } var distance = function.DistanceCaluculator(bounds, focusedBounds, _weightingValue); if (unit != Unit.Group || !controlType.IsContainer() || controlType == ControlType.Group) { candidates.Add(new MeasurementResult(element, distance)); } if (distance < nearestFocusableDistance) { if (_enumerateTargets.Contains(controlType) && IsFocusable(info, controlType)) { nearestFocusableDistance = distance; candidate = element; } } } focusedAncestors.ForEach(x => results.AddRange(FindCandidates(function, focusedBounds, x, unit))); candidates = candidates.OrderBy(x => x.Distance).ToList(); foreach (var c in candidates) { var condition = new PropertyCondition(AutomationElement.IsEnabledProperty, true); var result = FindCandidatesInGroup(function, focusedBounds, c.Element, condition); if (result.Count > 0) { results.AddRange(result); break; } } if (candidate != null) { results.Add(new MeasurementResult(candidate, nearestFocusableDistance)); } return(results); }
/// <summary> /// Кликает по заданной кнопке диалогового окна. /// </summary> /// <param name="dialogWindow"> /// Диалоговое окно. /// </param> /// <param name="buttonsType"> /// Тип набора кнопок диалогово окна. /// </param> /// <param name="targetButton"> /// Целевая кнопка. /// </param> public static void ClickButton( WindowAppElement dialogWindow, MessageBoxButton buttonsType, MessageBoxResult targetButton) { if (dialogWindow == null) { throw new ArgumentNullException("dialogWindow"); } var condition = new PropertyCondition(WindowPattern.IsModalProperty, true); var modalwindow = AutomationElementHelper.FindFirst(dialogWindow.Instance, TreeScope.Children, condition); if (modalwindow == null) { throw new CruciatusException("NOT CLICK BUTTON"); } string uid; if (targetButton == MessageBoxResult.None) { uid = CruciatusFactory.Settings.MessageBoxButtonUid.CloseButton; } else { switch (buttonsType) { case MessageBoxButton.OK: switch (targetButton) { case MessageBoxResult.OK: uid = CruciatusFactory.Settings.MessageBoxButtonUid.OkType.Ok; break; default: throw new CruciatusException("NOT CLICK BUTTON"); } break; case MessageBoxButton.OKCancel: switch (targetButton) { case MessageBoxResult.OK: uid = CruciatusFactory.Settings.MessageBoxButtonUid.OkCancelType.Ok; break; case MessageBoxResult.Cancel: uid = CruciatusFactory.Settings.MessageBoxButtonUid.OkCancelType.Cancel; break; default: throw new CruciatusException("NOT CLICK BUTTON"); } break; case MessageBoxButton.YesNo: switch (targetButton) { case MessageBoxResult.Yes: uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoType.Yes; break; case MessageBoxResult.No: uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoType.No; break; default: throw new CruciatusException("NOT CLICK BUTTON"); } break; case MessageBoxButton.YesNoCancel: switch (targetButton) { case MessageBoxResult.Yes: uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoCancelType.Yes; break; case MessageBoxResult.No: uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoCancelType.No; break; case MessageBoxResult.Cancel: uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoCancelType.Cancel; break; default: throw new CruciatusException("NOT CLICK BUTTON"); } break; default: throw new CruciatusException("NOT CLICK BUTTON"); } } var buttonElement = new WindowAppElement(dialogWindow, modalwindow, null).FindElement(By.Uid(uid)); buttonElement.Click(); }
public void Activate() { win = NUIApplication.GetDefaultWindow(); win.BackgroundColor = Color.White; View view = new View() { Size = new Size(100, 100), BackgroundColor = Color.Red, Name = "test view", }; PropertyNotification propertyNotification = view.AddPropertyNotification("size", PropertyCondition.Step(1.0f)); propertyNotification.Notified += (object source, PropertyNotification.NotifyEventArgs args) => { View target = args.PropertyNotification.GetTarget() as View; if (target != null) { Tizen.Log.Error("NUI", $"Size changed! ({target.SizeWidth},{target.SizeHeight})"); global::System.Console.WriteLine($"Size changed! ({target.SizeWidth},{target.SizeHeight})"); } Tizen.Log.Error("NUI", "Size changed"); }; Button button = new Button() { Size = new Size(100, 100), Position = new Position(200, 200), Text = "Click me", Name = "test button", }; button.Clicked += (object source, ClickedEventArgs args) => { if (++cnt % 2 == 0) { view.Size += new Size(5, 5); } else { view.Position += new Position(10, 10); } }; win.GetDefaultLayer().Add(view); win.GetDefaultLayer().Add(button); }
////[TestMethod, Priority(0)] //[HostType("VSTestHost"), TestCategory("Installed")] public void ObjectBrowserFindAllReferencesTest(VisualStudioApp app) { var project = app.OpenProject(@"TestData\MultiModule.sln"); System.Threading.Thread.Sleep(1000); app.OpenObjectBrowser(); var objectBrowser = app.ObjectBrowser; System.Threading.Thread.Sleep(1000); int nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(1, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[0].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(3, nodeCount, "Node count: " + nodeCount.ToString()); string str = objectBrowser.TypeBrowserPane.Nodes[1].Value; Assert.AreEqual("MyModule.py", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[2].Value; Assert.AreEqual("Program.py", str, ""); objectBrowser.TypeBrowserPane.Nodes[2].ExpandCollapse(); System.Threading.Thread.Sleep(1000); objectBrowser.TypeBrowserPane.Nodes[1].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(6, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[4].ShowContextMenu(); System.Threading.Thread.Sleep(1000); Condition con = new PropertyCondition( AutomationElement.ClassNameProperty, "ContextMenu" ); AutomationElement el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); Menu menu = new Menu(el); int itemCount = menu.Items.Count; Assert.AreEqual(13, itemCount, "Item count: " + itemCount.ToString()); menu.Items[4].Check(); System.Threading.Thread.Sleep(1000); //this needs to be updated for bug #4840 str = app.Dte.ActiveWindow.Caption; Assert.IsTrue(str.Contains("2 matches found"), str); objectBrowser.TypeBrowserPane.Nodes[2].ShowContextMenu(); System.Threading.Thread.Sleep(1000); el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); menu = new Menu(el); menu.Items[4].Check(); System.Threading.Thread.Sleep(1000); str = app.Dte.ActiveWindow.Caption; Assert.IsTrue(str.Contains("2 matches found"), str); }
internal virtual Condition AutomationConditionWith(PropertyCondition propertyCondition) { Condition condition = conditions.AutomationCondition; return(new AndCondition(condition, propertyCondition)); }
private AutomationElementCollection _items(AutomationElement e) { Condition treeitemcondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem); return(e.FindAll(TreeScope.Children, treeitemcondition)); }
private void Automate() { LogMessage("Getting RootElement..."); AutomationElement rootElement = AutomationElement.RootElement; if (rootElement != null) { LogMessage("OK." + Environment.NewLine); Automation.Condition condition = new PropertyCondition(AutomationElement.NameProperty, _WindowTestsViewModel.FirstOrDefault().WindowTitle); LogMessage("Searching for Test Window..."); AutomationElement appElement = rootElement.FindFirst(TreeScope.Children, condition); if (appElement != null) { LogMessage("OK " + Environment.NewLine); LogMessage("Searching for TextBox A control..."); AutomationElement txtElementA = GetTextElement(appElement, "txtA"); if (txtElementA != null) { LogMessage("OK " + Environment.NewLine); LogMessage("Setting TextBox A value..."); try { ValuePattern valuePatternA = txtElementA.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; valuePatternA.SetValue("10"); LogMessage("OK " + Environment.NewLine); } catch { WriteLogError(); } } else { WriteLogError(); } LogMessage("Searching for TextBox B control..."); AutomationElement txtElementB = GetTextElement(appElement, "txtB"); if (txtElementA != null) { LogMessage("OK " + Environment.NewLine); LogMessage("Setting TextBox B value..."); try { ValuePattern valuePatternB = txtElementB.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; valuePatternB.SetValue("5"); LogMessage("OK " + Environment.NewLine); } catch { WriteLogError(); } } else { WriteLogError(); } } else { WriteLogError(); } } }
public void CheckXenCenterInstalledVersion(string HelpMenu, string AboutXenCenterMenu, string XenCenterVersion) { Logger NewLogObj = new Logger(); string LogFilePath = NewLogObj.GetLogFilePath(); NewLogObj.WriteLogFile(LogFilePath, "CheckXenCenterInstalledVersion", "info"); NewLogObj.WriteLogFile(LogFilePath, "==============================", "info"); AutomationElementIdentity GuiObj = new AutomationElementIdentity(); XenCenter NewOprtorObj = new XenCenter(); FileOperations FileObj = new FileOperations(); NewOprtorObj.OpenXenCenter(LogFilePath); Thread.Sleep(2000); AutomationElement NewAutoObj = NewOprtorObj.SetFocusOnWindow(AutomationElement.RootElement, "NameProperty", "XenCenter", TreeScope.Children, "XenCenter", 1, LogFilePath); int WaitTimeOut = 300000;//5 mins int timer = 0; while (NewAutoObj == null && timer < WaitTimeOut) { NewAutoObj = NewOprtorObj.SetFocusOnWindow(AutomationElement.RootElement, "NameProperty", "XenCenter", TreeScope.Children, "XenCenter", 1, LogFilePath); Thread.Sleep(2000); timer = timer + 2000; NewLogObj.WriteLogFile(LogFilePath, "Waiting for Xencenter to open", "info"); Console.WriteLine("Waiting for Xencenter to open "); } if (NewAutoObj == null && timer >= WaitTimeOut) { Console.WriteLine("Timeout waiting for Xencenter to open after installation.Exiting.. "); NewLogObj.WriteLogFile(LogFilePath, "Timeout waiting for Xencenter to open after installation.Exiting.. ", "fail"); FileObj.ExitTestEnvironment(); } NewLogObj.WriteLogFile(LogFilePath, "Xencenter has opened after installation", "info"); Console.WriteLine("Xencenter has opened after installation "); //Check if periodic update cjheck window has come //Commenting for demo.. Remmber to uncomment ***************************************** //PropertyCondition AllowUpdateWindowCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "AllowUpdatesDialog", 1, LogFilePath); //AutomationElement AllowUpdatesDialog = GuiObj.FindAutomationElement(NewAutoObj, AllowUpdateWindowCondition, TreeScope.Children, "AllowUpdatesDialog", 0, LogFilePath); //WaitTimeOut = 60000;//1 mins //timer = 0; //while (AllowUpdatesDialog == null && timer < WaitTimeOut) //{ // AllowUpdatesDialog = GuiObj.FindAutomationElement(NewAutoObj, AllowUpdateWindowCondition, TreeScope.Children, "AllowUpdatesDialog", 0, LogFilePath); // Thread.Sleep(3000); // timer = timer + 3000; // NewLogObj.WriteLogFile(LogFilePath, "Waiting for AllowUpdatesDialog to open", "info"); // Console.WriteLine("Waiting for AllowUpdatesDialog to open "); //} //if (AllowUpdatesDialog == null && timer >= WaitTimeOut) //{ // Console.WriteLine("Timeout waiting for AllowUpdatesDialog to open after installation. "); // NewLogObj.WriteLogFile(LogFilePath, "Timeout waiting for AllowUpdatesDialog to open after installation. ", "fail"); // //Environment.Exit(1); //} //if (AllowUpdatesDialog != null) //{ // NewLogObj.WriteLogFile(LogFilePath, "AllowUpdatesDialog has opened after installation", "info"); // Console.WriteLine("AllowUpdatesDialog has opened after installation "); // NewLogObj.WriteLogFile(LogFilePath, "AllowUpdatesDialog found after installation", "info"); // PropertyCondition YesBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "YesButton", 1, LogFilePath); // AutomationElement YesBtnObj = GuiObj.FindAutomationElement(AllowUpdatesDialog, YesBtnCondition, TreeScope.Children, "YesBtn", 1, LogFilePath); // GuiObj.ClickButton(YesBtnObj, 1, "YesBtnObj", 1, LogFilePath); // Thread.Sleep(1000); //} //Commenting for demo.. Remmber to uncomment ***************************************** NewOprtorObj.InvokeXenCenterSubMenuItem(NewAutoObj, HelpMenu, AboutXenCenterMenu, LogFilePath, 1); Thread.Sleep(3000); PropertyCondition AboutDialogCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "AboutDialog", 1, LogFilePath); AutomationElement AboutDialogObj = GuiObj.FindAutomationElement(NewAutoObj, AboutDialogCondition, TreeScope.Children, "AboutDialog", 1, LogFilePath); PropertyCondition TblLayoutCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "tableLayoutPanel1", 1, LogFilePath); AutomationElement TblLayoutObj = GuiObj.FindAutomationElement(AboutDialogObj, TblLayoutCondition, TreeScope.Children, "AboutDialog", 1, LogFilePath); //Get the version PropertyCondition VersionLabelCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "VersionLabel", 1, LogFilePath); AutomationElement VersionLabelObj = GuiObj.FindAutomationElement(TblLayoutObj, VersionLabelCondition, TreeScope.Children, "AboutDialog", 1, LogFilePath); string VersionNumber = VersionLabelObj.Current.Name.ToString(); NewLogObj.WriteLogFile(LogFilePath, "VersionNumber found after install *" + VersionNumber + "*", "info"); NewLogObj.WriteLogFile(LogFilePath, "Expected VersionNumber XenCenterVersion *" + XenCenterVersion + "*", "info"); if (string.Compare(XenCenterVersion, VersionNumber) == 0) { NewLogObj.WriteLogFile(LogFilePath, "Right version of Xencenter installed " + VersionNumber, "pass"); } else { NewLogObj.WriteLogFile(LogFilePath, "Wrong version of Xencenter installed. Version found from Xenvcenter " + VersionNumber + "Version from inputs file " + XenCenterVersion, "fail"); } PropertyCondition OKBtnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "OkButton", 1, LogFilePath); AutomationElement OKBtnObj = GuiObj.FindAutomationElement(TblLayoutObj, OKBtnCondition, TreeScope.Children, "OKBtnObj", 1, LogFilePath); GuiObj.ClickButton(OKBtnObj, 1, "OKBtnObj", 1, LogFilePath); }
public override void OnChildAdd(View view) { if (mScrollingChild.Name != "DefaultScrollingChild") { propertyNotification.Notified -= OnPropertyChanged; mScrollingChild.RemovePropertyNotification(propertyNotification); } mScrollingChild = view; propertyNotification = mScrollingChild?.AddPropertyNotification("position", PropertyCondition.Step(1.0f)); propertyNotification.Notified += OnPropertyChanged; { if (Children.Count > 1) { Log.Error("ScrollableBase", $"Only 1 child should be added to ScrollableBase."); } } }
public override UIHandlerAction HandleWindow(IntPtr topLevelhWnd, IntPtr hwnd, Process process, string title, UIHandlerNotification notification) { GlobalLog.LogDebug("Appearance settings window found."); AutomationElement window = AutomationElement.FromHandle(topLevelhWnd); GlobalLog.LogDebug("Finding Color Scheme combo box and selecting correct value."); Condition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "1114"); AutomationElement colorSchemeComboBox = window.FindFirst(TreeScope.Descendants, cond); // This gets us to the vertical scroll bar AutomationElement item = TreeWalker.ControlViewWalker.GetFirstChild(colorSchemeComboBox); // This gets us to the first item in the list item = TreeWalker.ControlViewWalker.GetNextSibling(item); // On systems which support DWM composition, the first item will be either // "Windows Vista Aero" or "Windows Vista Standard" (depending on the SKU). // The second item will be "Windows Vista Basic". // "Windows Vista Aero" features both DWM composition and glass. // "Windows Vista Standard" features DWM composition but no glass. // "Windows Vista Basic" does not feature DWM composition or glass. // No machine will ever support both Aero and Standard. All machines support Basic. // If this machine supports composition, but we want to turn it off, // we need to move to the second item in the list, "Windows Vista Basic". // Otherwise, we select the first item, either because composition is supported // and we want it enabled, or it is not supported. if (IsDwmCompositionSupported && newAppearance == DesktopAppearance.AeroWithoutComposition) { item = TreeWalker.ControlViewWalker.GetNextSibling(item); } object patternObject; item.TryGetCurrentPattern(SelectionItemPattern.Pattern, out patternObject); SelectionItemPattern selectionItemPattern = patternObject as SelectionItemPattern; selectionItemPattern.Select(); // HACK: On recent builds of Vista, UI Automation does not seem to properly // notify the dialog that the selection has changed. This message is normally // sent by the combo box to the dialog. IntPtr wParam = MakeWParam(1114, CBN_SELCHANGE); SendMessage(hwnd, WM_COMMAND, wParam, new IntPtr((int)colorSchemeComboBox.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty))); GlobalLog.LogDebug("Finding and clicking the OK Button"); cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "1"); AutomationElement okBtn = window.FindFirst(TreeScope.Descendants, cond); okBtn.TryGetCurrentPattern(InvokePattern.Pattern, out patternObject); InvokePattern invokePattern = patternObject as InvokePattern; invokePattern.Invoke(); GlobalLog.LogDebug("Waiting for appearance to be applied..."); process.WaitForExit(); return(UIHandlerAction.Abort); }
public void Set(int value) { this.PrepareForReplay(); Condition button = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button); AutomationElement scrollbarobject = this._condition.AutomationElement; AutomationElementCollection scrollcollection = null; if (scrollbarobject != null) { AutomationElement abutton = null; scrollcollection = scrollbarobject.FindAll(TreeScope.Children, button); if (value >= 0) { abutton = scrollcollection[scrollcollection.Count - 1]; } else { abutton = scrollcollection[0]; } int hwnd = abutton.Current.NativeWindowHandle; if (hwnd != 0) { while (value != 0) { KeyInput.Click(KeyInput.MouseClickType.LClick, hwnd, 2, 2); if (value < 0) { value++; } if (value > 0) { value--; } } } else { try { Point p = new Point(); p.X = (int)abutton.Current.BoundingRectangle.Left + (int)((abutton.Current.BoundingRectangle.Right - abutton.Current.BoundingRectangle.Left) / 2); p.Y = (int)abutton.Current.BoundingRectangle.Top + (int)((abutton.Current.BoundingRectangle.Bottom - abutton.Current.BoundingRectangle.Top) / 2); while (value != 0) { KeyInput.Click(KeyInput.MouseClickType.LClick, p); if (value < 0) { value++; } if (value > 0) { value--; } } return; } catch { } try { InvokePattern cinvoke = (InvokePattern)this._condition.AutomationElement.GetCurrentPattern(InvokePattern.Pattern); while (value != 0) { cinvoke.Invoke(); if (value < 0) { value++; } if (value > 0) { value--; } } } catch { } } } else { return; } }
/// <summary> /// Create PropertyCondition by AutomationId /// </summary> /// <param name="automationId">Control AutomationId</param> /// <returns>Return PropertyCondition instance</returns> public static PropertyCondition GetAutomationIdProperty(object automationId) { propertyCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId); return(propertyCondition); }
////[TestMethod, Priority(0)] //[HostType("VSTestHost"), TestCategory("Installed")] public void ObjectBrowserContextMenuBasicTest(VisualStudioApp app) { var project = app.OpenProject(@"TestData\MultiModule.sln"); System.Threading.Thread.Sleep(1000); app.OpenObjectBrowser(); var objectBrowser = app.ObjectBrowser; System.Threading.Thread.Sleep(1000); int nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(1, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[0].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(3, nodeCount, "Node count: " + nodeCount.ToString()); string str = objectBrowser.TypeBrowserPane.Nodes[1].Value; Assert.AreEqual("MyModule.py", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[2].Value; Assert.AreEqual("Program.py", str, ""); objectBrowser.TypeBrowserPane.Nodes[2].ExpandCollapse(); System.Threading.Thread.Sleep(1000); objectBrowser.TypeBrowserPane.Nodes[1].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(6, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[1].ShowContextMenu(); System.Threading.Thread.Sleep(1000); Condition con = new PropertyCondition( AutomationElement.ClassNameProperty, "ContextMenu" ); AutomationElement el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); Menu menu = new Menu(el); int itemCount = menu.Items.Count; Assert.AreEqual(7, itemCount, "Item count: " + itemCount.ToString()); Assert.AreEqual("Copy", menu.Items[0].Value.Trim(), ""); Assert.AreEqual("View Namespaces", menu.Items[1].Value.Trim(), ""); Assert.AreEqual("View Containers", menu.Items[2].Value.Trim(), ""); Assert.AreEqual("Sort Alphabetically", menu.Items[3].Value.Trim(), ""); Assert.AreEqual("Sort By Object Type", menu.Items[4].Value.Trim(), ""); Assert.AreEqual("Sort By Object Access", menu.Items[5].Value.Trim(), ""); Assert.AreEqual("Group By Object Type", menu.Items[6].Value.Trim(), ""); Keyboard.PressAndRelease(System.Windows.Input.Key.Escape); objectBrowser.TypeBrowserPane.Nodes[2].ShowContextMenu(); System.Threading.Thread.Sleep(1000); el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); menu = new Menu(el); itemCount = menu.Items.Count; Assert.AreEqual(13, itemCount, "Item count: " + itemCount.ToString()); Assert.AreEqual("Go To Definition", menu.Items[0].Value.Trim(), ""); Assert.AreEqual("Go To Declaration", menu.Items[1].Value.Trim(), ""); Assert.AreEqual("Go To Reference", menu.Items[2].Value.Trim(), ""); Assert.AreEqual("Browse Definition", menu.Items[3].Value.Trim(), ""); Assert.AreEqual("Find All References", menu.Items[4].Value.Trim(), ""); Assert.AreEqual("Filter To Type", menu.Items[5].Value.Trim(), ""); Assert.AreEqual("Copy", menu.Items[6].Value.Trim(), ""); Assert.AreEqual("View Namespaces", menu.Items[7].Value.Trim(), ""); Assert.AreEqual("View Containers", menu.Items[8].Value.Trim(), ""); Assert.AreEqual("Sort Alphabetically", menu.Items[9].Value.Trim(), ""); Assert.AreEqual("Sort By Object Type", menu.Items[10].Value.Trim(), ""); Assert.AreEqual("Sort By Object Access", menu.Items[11].Value.Trim(), ""); Assert.AreEqual("Group By Object Type", menu.Items[12].Value.Trim(), ""); Keyboard.PressAndRelease(System.Windows.Input.Key.Escape); }
/// <summary> /// Find element by specific PropertyCondition /// </summary> /// <param name="condition">PropertyCondition instance</param> /// <returns>Target automation element</returns> public static AutomationElement FindElement(PropertyCondition condition) { return(AutomationElement.RootElement.FindFirst(TreeScope.Descendants, condition)); }
////[TestMethod, Priority(0)] //[HostType("VSTestHost"), TestCategory("Installed")] public void ObjectBrowserTypeBrowserSortTest(VisualStudioApp app) { var project = app.OpenProject(@"TestData\MultiModule.sln"); System.Threading.Thread.Sleep(1000); app.OpenObjectBrowser(); var objectBrowser = app.ObjectBrowser; System.Threading.Thread.Sleep(1000); int nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(1, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[0].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(3, nodeCount, "Node count: " + nodeCount.ToString()); string str = objectBrowser.TypeBrowserPane.Nodes[1].Value; Assert.AreEqual("MyModule.py", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[2].Value; Assert.AreEqual("Program.py", str, ""); objectBrowser.TypeBrowserPane.Nodes[1].ShowContextMenu(); System.Threading.Thread.Sleep(1000); Condition con = new PropertyCondition( AutomationElement.ClassNameProperty, "ContextMenu" ); AutomationElement el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); Menu menu = new Menu(el); int itemCount = menu.Items.Count; Assert.AreEqual(7, itemCount, "Item count: " + itemCount.ToString()); menu.Items[6].Check(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(4, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[2].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(5, nodeCount, "Node count: " + nodeCount.ToString()); Assert.AreEqual("Namespaces", objectBrowser.TypeBrowserPane.Nodes[3].Value, ""); Assert.AreEqual("Namespaces", objectBrowser.TypeBrowserPane.Nodes[1].Value, ""); objectBrowser.TypeBrowserPane.Nodes[3].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(6, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[3].ExpandCollapse(); System.Threading.Thread.Sleep(1000); objectBrowser.TypeBrowserPane.Nodes[0].ShowContextMenu(); System.Threading.Thread.Sleep(1000); el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); menu = new Menu(el); itemCount = menu.Items.Count; Assert.AreEqual(7, itemCount, "Item count: " + itemCount.ToString()); Assert.IsTrue(menu.Items[6].ToggleStatus); menu.Items[3].Check(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(4, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[3].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(6, nodeCount, "Node count: " + nodeCount.ToString()); str = objectBrowser.TypeBrowserPane.Nodes[1].Value; Assert.AreEqual("MyModule.py", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[2].Value; Assert.AreEqual("class SchoolMember\n", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[3].Value; Assert.AreEqual("Program.py", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[4].Value; Assert.AreEqual("class Student(MyModule.SchoolMember)\n", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[5].Value; Assert.AreEqual("class Teacher(MyModule.SchoolMember)\n", str, ""); }
// this should all be done on a non-UI thread private void btnMisc_Click(object sender, EventArgs e) { Condition cond = new PropertyCondition(AutomationElement.NameProperty, "Tulip"); AutomationElement elementListItem = ListElement.FindFirst(TreeScope.Children, cond); ShowUsage(); // VISTAONLY GetPhysicalCursorPos(ref pt); /* Test for a WPF listbox in the window under the cursor. System.Windows.Point pt = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y); AutomationElement wpfListSample = AutomationElement.FromPoint(pt); Condition cond1 = new PropertyCondition(AutomationElement.ClassNameProperty, "ListBox"); AutomationElement wpfList = wpfListSample.FindFirst(TreeScope.Children, cond1); Stopwatch watch = new Stopwatch(); watch.Start(); AutomationElement childAt = FindChildAt(wpfList, 9); // way faster watch.Stop(); Debug.WriteLine(watch.Elapsed.Ticks.ToString()); watch.Reset(); watch.Start(); AutomationElement childAt1 = FindChildAtB(wpfList, 9); watch.Stop(); Debug.WriteLine(watch.Elapsed.Ticks.ToString()); */ cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "button1"); AutomationElement elementButton = MainWindowElement.FindFirst(TreeScope.Subtree, cond); SubscribeToInvoke(elementButton); //InvokePattern invoker = elementButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; //invoker.Invoke(); // AutomationElement elementList = GetListItemParent(elementListItem); String s = ListElement.Current.Name; //SetupComboElement(MainWindowElement); //MiscellaneousCalls(ListElement); //AddListItemToSelection(elementListItem); //CachePropertiesByActivate(elementList); //CachePropertiesWithScope(MainWindowElement); //CachePropertiesByPush(elementList); ConditionSnips cs = new ConditionSnips(); cs.GetTreeWalkerCondition(); //cs.ConditionExamples(MainWindowElement); //cs.AndConditionExample(MainWindowElement); //cs.NotConditionExample(MainWindowElement); //cs.StaticConditionExamples(MainWindowElement); //MiscPropertyCalls(elementList); PropertySnips ps = new PropertySnips(); ps.GetAllProperties(elementListItem); TreeNode treeNode = treeView1.Nodes.Add("Root node"); //WalkControlElements(MainWindowElement, treeNode); //WalkEnabledElements(MainWindowElement, treeNode); // Property changes //cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "btnDisable"); //elementButton = MainWindowElement.FindFirst(TreeScope.Subtree, cond); // ps.SubscribePropertyChange(elementButton); }
////[TestMethod, Priority(0)] //[HostType("VSTestHost"), TestCategory("Installed")] public void ObjectBrowserNavigateVarContextMenuTest(VisualStudioApp app) { var project = app.OpenProject(@"TestData\MultiModule.sln"); System.Threading.Thread.Sleep(1000); app.OpenObjectBrowser(); var objectBrowser = app.ObjectBrowser; objectBrowser.EnsureLoaded(); int nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(1, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[0].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(3, nodeCount, "Node count: " + nodeCount.ToString()); string str = objectBrowser.TypeBrowserPane.Nodes[1].Value; Assert.AreEqual("MyModule.py", str, ""); str = objectBrowser.TypeBrowserPane.Nodes[2].Value; Assert.AreEqual("Program.py", str, ""); objectBrowser.TypeBrowserPane.Nodes[2].ExpandCollapse(); System.Threading.Thread.Sleep(1000); objectBrowser.TypeBrowserPane.Nodes[1].ExpandCollapse(); System.Threading.Thread.Sleep(1000); nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count; Assert.AreEqual(6, nodeCount, "Node count: " + nodeCount.ToString()); objectBrowser.TypeBrowserPane.Nodes[4].ShowContextMenu(); System.Threading.Thread.Sleep(1000); Condition con = new PropertyCondition( AutomationElement.ClassNameProperty, "ContextMenu" ); AutomationElement el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); Menu menu = new Menu(el); int itemCount = menu.Items.Count; Assert.AreEqual(13, itemCount, "Item count: " + itemCount.ToString()); menu.Items[0].Check(); System.Threading.Thread.Sleep(1000); str = app.Dte.ActiveDocument.Name; Assert.AreEqual("Program.py", str, ""); int lineNo = ((TextSelection)app.Dte.ActiveDocument.Selection).ActivePoint.Line; Assert.AreEqual(14, lineNo, "Line number: " + lineNo.ToString()); app.OpenObjectBrowser(); objectBrowser.TypeBrowserPane.Nodes[5].ShowContextMenu(); System.Threading.Thread.Sleep(1000); el = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, con); Assert.IsNotNull(el); menu = new Menu(el); menu.Items[0].Check(); System.Threading.Thread.Sleep(1000); lineNo = ((TextSelection)app.Dte.ActiveDocument.Selection).ActivePoint.Line; Assert.AreEqual(3, lineNo, "Line number: " + lineNo.ToString()); }
public void RunQuery() { // ��ȡ��ͼӦ�ó��������̶��� MapApplication mapApi = HostMapApplicationServices.Application; ProjectModel proj = mapApi.ActiveProject; DrawingSet drawingSet = proj.DrawingSet; //������ͼ�μ��߽� proj.DrawingSet.ZoomExtents(); //ʹ��LocationCondition������һ����ѯ���� LocationCondition qryCondition = new LocationCondition (); qryCondition.LocationType = LocationType.LocationInside ; qryCondition.JoinOperator = JoinOperator .OperatorAnd ; // ����Բ�߽� CircleBoundary boundary = null; PromptPointResult pointRes = Utility.AcadEditor.GetPoint("\nѡ��ԭ��: "); if (pointRes.Status == PromptStatus.OK) { Point3d point = pointRes.Value; PromptDistanceOptions distOptions = new PromptDistanceOptions("\nѡ��뾶: "); distOptions.BasePoint = point; distOptions.UseBasePoint = true; distOptions.DefaultValue = 0.0; PromptDoubleResult doubleRes = Utility.AcadEditor.GetDistance(distOptions); if (doubleRes.Status == PromptStatus.OK) { double rad = doubleRes.Value; boundary = new CircleBoundary(new Point3d(point.X, point.Y, 0.0), rad); } } // qryCondition.Boundary = boundary; //����һ��������֧ QueryBranch qryBranch = QueryBranch.Create (); qryBranch.JoinOperator = JoinOperator.OperatorAnd; qryBranch.AppendOperand(qryCondition); ////ʹ��PropertyCondition������һ�����Բ�ѯ����(LWPOLYLINE) PropertyCondition propCondition= new PropertyCondition(); //JoinOperator.OperatorAnd, PropertyType.EntityType, ConditionOperator.ConditionEqual, "LWPOLYLINE"; propCondition.JoinOperator = JoinOperator.OperatorAnd ; propCondition.PropertyType = PropertyType.EntityType ; propCondition.ConditionOperator = ConditionOperator.ConditionEqual ; propCondition.Value = "LWPOLYLINE"; // ͨ��QueryBranch�Ĺ��캯��������һ��������ѯ��֧�� QueryBranch subBranch = new QueryBranch(JoinOperator.OperatorAnd); // ����һ�����в�ѯ�����ͷ�֧�IJ�ѯ���� subBranch.AppendOperand(propCondition); qryBranch.AppendOperand(subBranch); // ����һ����ѯ�� QueryModel qryModel = proj.CreateQuery (true); // ��ɲ�ѯ�Ķ��塣 qryModel.Define (qryBranch); //���û���ģʽ qryModel.Mode = QueryType.QueryDraw; //�����ѯ qryModel.Define(qryBranch); //ִ�в�ѯ�� qryModel.Run(); Utility.AcadEditor.WriteMessage("\n ��ɲ�ѯ ��"); }
private void MouseHook_LeftButtonUp(MouseHook.MSLLHOOKSTRUCT mouseStruct) { mouseHook.Uninstall(); Point mousePoint = new Point(mouseStruct.pt.x, mouseStruct.pt.y); int hwnd = User.WindowFromPoint(mouseStruct.pt.x, mouseStruct.pt.y); if (0 == hwnd) { return; } int root = User.GetAncestor((IntPtr)hwnd, User.GA_ROOT); int pid = 0; User.GetWindowThreadProcessId((IntPtr)root, ref pid); Process[] processlist = Process.GetProcesses(); foreach (Process p in processlist) { if (p.Id == pid) { mainwndText = p.MainWindowTitle; processName = p.ProcessName; //processPath = p.MainModule.FileName; } } Automation.Condition condition = new PropertyCondition(AutomationElement.NameProperty, mainwndText); AutomationElement appElement = rootElement.FindFirst(TreeScope.Children, condition); AutomationElementCollection theCollection = appElement.FindAll(TreeScope.Descendants, Automation.Condition.TrueCondition); if (null == appElement) { return; } AutomationElement focusElement = AutomationElement.FromPoint(mousePoint); switch (focusElement.Current.FrameworkId) { case "WPF": switch (focusElement.Current.ClassName) { case "TextBox": { ValuePattern pattern = focusElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; tb_detail.Text += pattern.Current.Value + "\r\n"; } break; case "TextBlock": case "Text": { tb_detail.Text += focusElement.Current.Name + "\r\n"; } break; case "RichTextBox": { TextPattern pattern = focusElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; string controlText = pattern.DocumentRange.GetText(-1); tb_detail.Text += controlText + "\r\n"; } break; } break; case "Win32": if (focusElement.Current.ControlType == ControlType.Document || focusElement.Current.ControlType == ControlType.Edit) { TextPattern pattern = focusElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; string controlText = pattern.DocumentRange.GetText(-1); tb_detail.Text += controlText + "\r\n"; } else if (focusElement.Current.ControlType == ControlType.Text) { tb_detail.Text += focusElement.Current.Name + "\r\n"; } break; case "WinForm": tb_detail.Text += focusElement.Current.Name + "\r\n"; break; case "Silverlight": break; case "SWT": break; default: break; } TreeWalker tWalker = TreeWalker.ControlViewWalker; AutomationElement parentElement = tWalker.GetParent(focusElement); if (parentElement == AutomationElement.RootElement) { return; } while (true) { AutomationElement element = tWalker.GetParent(parentElement); if (element == AutomationElement.RootElement) { break; } else { parentElement = element; } } }