private static bool UiaWaitForInputIdle(ProdWindow baseControl, int delay) { bool retVal = WindowPatternHelper.WaitForInputIdle(baseControl.UIAElement, delay); LogController.ReceiveLogMessage(new LogMessage(retVal.ToString())); return(retVal); }
private static WindowVisualState UiaGetWindowVisualState(ProdWindow control) { WindowVisualState retVal = WindowPatternHelper.GetVisualState(control.UIAElement); LogController.ReceiveLogMessage(new LogMessage(retVal.ToString())); return(retVal); }
/// <summary> /// Sets the constructor parameters for the ProdSession and ProdWindow. /// </summary> /// <param name="originalName">Name of the original control.</param> /// <returns> /// An array of the necessary constructors needed for instance methods /// </returns> /// <remarks> /// This is just an empty, "Dummy" session /// </remarks> private object[] SetConstructorParameters(string originalName) { ProdWindow fake = new ProdWindow(_parentWindowHandle); object[] o = new object[] { fake, originalName }; return(o); }
/// <summary> /// Demonstrates creating a simple Prod using preconfigured loggers from a configuration file /// </summary> public static void LoadConfigFile() { try { /* Loading a set of loggers from a configuration file (located in the /bin directory */ LoggingConfiguration lc = new LoggingConfiguration(); /* Adding them to the controller */ LogController.AddActiveLogger(lc.LoadFromConfiguration(@"loggers.ses")); /* start the application and wait until it exists */ Process.Start("MasterWinformTest.exe"); Prod.WinWaitExists(WIN_TITLE); /* Get the parent window and add loggers */ ProdWindow window = new ProdWindow(WIN_TITLE); /* here's the control we want to Prod */ ProdCheckBox chk1 = new ProdCheckBox(window, "checkBox1"); /* We'll monkey with the slider control */ ProdSlider slider = new ProdSlider(window, "trackBarTest"); slider.SetValue(3); chk1.SetCheckState(ToggleState.On); } catch (ProdUI.Exceptions.ProdOperationException e) { /* Show any errors */ Debug.WriteLine(">>>>>>>" + e.InnerException.Message + "<<<<<<<<"); } }
private static string UiaGetTitle(ProdWindow baseControl) { string retVal = baseControl.WindowTitle; LogController.ReceiveLogMessage(new LogMessage(retVal)); return(retVal); }
private static WindowInteractionState UiaGetWindowState(ProdWindow baseControl) { WindowInteractionState state = WindowPatternHelper.GetInteractionState(baseControl.UIAElement); LogController.ReceiveLogMessage(new LogMessage(state.ToString())); return(state); }
internal static AutomationElement Prologue(ProdWindow prodwindow, AutomationPattern pattern, string automationId) { AutomationElement control = GetControl(prodwindow, automationId); /* control found...proceed */ control.SetFocus(); /* Nothing. bail */ if (control == null) { throw new ProdOperationException("Cannot find control"); } try { CheckPatternSupport(pattern, control); } catch (InvalidOperationException) { return(null); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err.Message, err); } return(control); }
private static bool UiaGetIsModal(ProdWindow control) { bool retVal = WindowPatternHelper.GetIsModal(control.UIAElement); LogController.ReceiveLogMessage(new LogMessage(retVal.ToString())); return(retVal); }
public static ToggleState GetCheckState(ProdWindow prodwindow, string automationId) { try { AutomationElement control = InternalUtilities.GetHandlelessElement(prodwindow, automationId); StaticEvents.RegisterEvent(TogglePattern.ToggleStateProperty, control); ToggleState ret = TogglePatternHelper.GetToggleState(control); LogController.ReceiveLogMessage(new LogMessage(control.Current.Name)); return(ret); } catch (InvalidOperationException err) { throw new ProdOperationException(err.Message, err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err.Message, err); } catch (ArgumentException err) { throw new ProdOperationException(err.Message, err); } }
/// <summary> /// Initializes a new instance of the <see cref="ProdMenuItem"/> class. /// </summary> /// <param name="prodWindow">The prod window.</param> /// <param name="automationId">The automation id. Pass an empty string for the top level menu</param> public ProdMenuBar(ProdWindow prodWindow, string automationId) : base(prodWindow, automationId) { if (automationId.Length == 0) { automationId = "Application"; } }
/// <summary> /// Initializes a new instance of the ProdTreeView class. /// </summary> /// <param name = "prodWindow">The ProdWindow that contains this control.</param> /// <param name = "automationId">The UI Automation element</param> /// <remarks> /// Will attempt to match AutomationId, then ReadOnly /// </remarks> public ProdTreeView(ProdWindow prodWindow, string automationId) : base(prodWindow, automationId) { AllNodes = new Collection <AutomationElement>(); AutomationElement aeNode = TreeWalker.ControlViewWalker.GetFirstChild(UIAElement); EnumControlElements(aeNode); }
private static void UiaRotateWindow(ProdWindow baseControl, double degrees) { Collection <object> verboseInformation = new Collection <object> { "degrees = " + degrees }; LogController.ReceiveLogMessage(new LogMessage("Rotated", verboseInformation)); TransformPatternHelper.Rotate(baseControl.UIAElement, degrees); }
private static void UiaMoveWindow(ProdWindow baseControl, double x, double y) { Collection <object> verboseInformation = new Collection <object> { "Y = " + y, "X = " + x }; LogController.ReceiveLogMessage(new LogMessage("move", verboseInformation)); TransformPatternHelper.Move(baseControl.UIAElement, x, y); }
private static void UiaResizeWindow(ProdWindow baseControl, double width, double height) { Collection <object> verboseInformation = new Collection <object> { "Width = " + width, "Height = " + height }; LogController.ReceiveLogMessage(new LogMessage("resize", verboseInformation)); TransformPatternHelper.Resize(baseControl.UIAElement, width, height); }
/// <summary> /// Gets the controls with matching automationId inside a ProdWindow /// </summary> /// <param name="prodwindow">The ProdWindow.</param> /// <param name="automationId">The automation id.</param> /// <returns> /// A list of matching elements /// </returns> private static AutomationElement GetControl(ProdWindow prodwindow, string automationId) { /* first, try using the Automation ID */ Condition condId = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId); AutomationElement control = prodwindow.UIAElement.FindFirst(TreeScope.Descendants, condId); /* then we'll try the name...who knows? */ if (control == null) { /* try the name */ Condition condName = new PropertyCondition(AutomationElement.NameProperty, automationId); control = prodwindow.UIAElement.FindFirst(TreeScope.Descendants, condName); } return(control); }
/// <summary> /// Gets an AutomationElement based on its container window. /// </summary> /// <param name="prodWindow">The containing ProdWindow.</param> /// <param name="automationId">The automation id.</param> /// <returns> /// Corresponding element if successful, null if not /// </returns> internal static AutomationElement GetHandlelessElement(ProdWindow prodWindow, string automationId) { Condition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId); AutomationElement control = prodWindow.UIAElement.FindFirst(TreeScope.Descendants, cond); /* then we'll try the name...who knows? */ if (control == null) { /* try the name */ Condition condName = new PropertyCondition(AutomationElement.NameProperty, automationId, PropertyConditionFlags.IgnoreCase); control = prodWindow.UIAElement.FindFirst(TreeScope.Descendants, condName); } return(control); }
/// <summary> /// Gets a value whether a window is set to be topmost in the z-order /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The ProdWindow.</param> /// <returns> /// <c>true</c> if topmost; otherwise, <c>false</c>. /// </returns> internal static bool GetIsTopmostBridge(this WindowAdapter extension, ProdWindow baseControl) { try { return(UiaGetIsTopmost(baseControl)); } catch (ArgumentNullException err) { throw new ProdOperationException(err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err); } //catch (InvalidOperationException) //{ // return NativeGetIsTopmost(baseControl); //} }
//private static WindowVisualState NativeGetWindowVisualState(ProdWindow control) //{ // return ProdWindowNative.GetVisualStateNative(control.NativeHandle); //} /// <summary> /// Gets whether the current window is modal or not /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The ProdWindow.</param> /// <returns> /// <c>true</c> if this instance is modal; otherwise, <c>false</c>. /// </returns> internal static bool GetIsModalBridge(this WindowAdapter extension, ProdWindow baseControl) { try { return(UiaGetIsModal(baseControl)); } catch (ArgumentNullException err) { throw new ProdOperationException(err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err); } catch (InvalidOperationException err) { throw new ProdOperationException(err); } }
/// <summary> /// Rotates the window /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The base control.</param> /// <param name="degrees">The number of degrees to rotate the element. A positive number rotates clockwise; /// a negative number rotates counterclockwise</param> internal static void RotateWindowBridge(this WindowAdapter extension, ProdWindow baseControl, double degrees) { try { UiaRotateWindow(baseControl, degrees); } catch (ArgumentNullException err) { throw new ProdOperationException(err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err); } catch (InvalidOperationException err) { throw new ProdOperationException(err); } }
/// <summary> /// Resize the window /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The base control.</param> /// <param name="width">The new width of the window, in pixels</param> /// <param name="height">The new height of the window, in pixels</param> internal static void ResizeWindowBridge(this WindowAdapter extension, ProdWindow baseControl, double width, double height) { try { UiaResizeWindow(baseControl, width, height); } catch (ArgumentNullException err) { throw new ProdOperationException(err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err); } catch (InvalidOperationException) { NativeResizeWindow(baseControl, width, height); } }
/// <summary> /// Moves the window to the specified location /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The base control.</param> /// <param name="x">Absolute screen coordinates of the left side of the window</param> /// <param name="y">Absolute screen coordinates of the top of the window</param> internal static void MoveWindowBridge(this WindowAdapter extension, ProdWindow baseControl, double x, double y) { try { UiaMoveWindow(baseControl, x, y); } catch (ArgumentNullException err) { throw new ProdOperationException(err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err); } catch (InvalidOperationException) { NativeMoveWindow(baseControl, x, y); } }
//private static string NativeGetTitle(ProdWindow baseControl) //{ // return ProdWindowNative.GetWindowTitleNative(baseControl.NativeHandle); //} /// <summary> /// Sets the specified windows title /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The base control.</param> /// <param name="title">The title.</param> internal static void SetTitleBridge(this WindowAdapter extension, ProdWindow baseControl, string title) { //try //{ // NativeSetTitle(baseControl, title); //} //catch (ArgumentNullException err) //{ // throw new ProdOperationException(err); //} //catch (ElementNotAvailableException err) //{ // throw new ProdOperationException(err); //} //catch (InvalidOperationException err) //{ // throw new ProdOperationException(err); //} }
internal static void CloseWindowBridge(this WindowAdapter extension, ProdWindow baseControl) { try { UiaCloseWindow(baseControl); } catch (ArgumentNullException err) { throw new ProdOperationException(err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err); } //catch (InvalidOperationException) //{ // NativeCloseWindow(baseControl); //} }
/// <summary> /// Causes the calling code to block for the specified time or until the associated process enters an idle state, whichever completes first /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The base control.</param> /// <param name="delay">Time, in milliseconds to wait for an idle state</param> /// <returns> /// <c>true</c> if the window has entered the idle state. <c>false</c> if the timeout occurred /// </returns> internal static bool WaitForInputIdleBridge(this WindowAdapter extension, ProdWindow baseControl, int delay) { try { return(UiaWaitForInputIdle(baseControl, delay)); } catch (ArgumentNullException err) { throw new ProdOperationException(err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err); } catch (InvalidOperationException err) { throw new ProdOperationException(err); } }
/// <summary> /// Demonstrates creating a simple Prod and how to create and add an external ProdLogger as well as how a /// static Prod can be used to set a checkbox's value. /// </summary> public static void SimpleProdExample() { try { /* Create a logger. Note: You don't need to have a logger at all if you don't want one... */ ProdLogger def = new ProdLogger(new DebugLogger(), LoggingLevels.Prod, "LogTime,Message Level,Calling Function,Message Text", "T"); /* Add the new logger to the active loggers */ LogController.AddActiveLogger(def); /* start the application and wait until it exists */ Process.Start("MasterWinformTest.exe"); Prod.WinWaitExists(WIN_TITLE); /* Get the parent window and add loggers */ ProdWindow window = new ProdWindow(WIN_TITLE); /* here's the control we want to Prod */ ProdCheckBox chk1 = new ProdCheckBox(window, "checkBox1"); /* We'll monkey with the slider control */ ProdSlider slider = new ProdSlider(window, "trackBarTest"); slider.SetValue(3); /* here, we use a static Prod to directly set the ToggleState */ Prod.SetCheckState(window, "checkBox2", ToggleState.On); /* and switch tabs */ ProdTab tabB = new ProdTab(window, "tabControl1"); tabB.SelectTab(1); /* We're still able to set the checkbox on the other tab because we got its control before we changed */ chk1.SetCheckState(ToggleState.On); /* This will break, because the static checkbox can't be referenced, since its not onscreen */ //Prod.SetCheckState(window, "checkBox3", ToggleState.Off); } catch (ProdUI.Exceptions.ProdOperationException e) { /* Show any errors */ Debug.WriteLine(">>>>>>>" + e.InnerException.Message + "<<<<<<<<"); } }
/// <summary> /// Gets the ReadOnly status of the Textbox /// </summary> /// <param name="prodwindow">The containing ProdWindow.</param> /// <param name="automationId">The automation id (or caption).</param> /// <returns> /// <c>true</c> if control is ReadOnly, <c>false</c> otherwise /// </returns> /// <exception cref="ProdOperationException">Examine inner exception</exception> public static bool GetReadOnly(ProdWindow prodwindow, string automationId) { try { AutomationElement control = InternalUtilities.GetHandlelessElement(prodwindow, automationId); return((bool)control.GetCurrentPropertyValue(ValuePattern.IsReadOnlyProperty)); } catch (InvalidOperationException err) { throw new ProdOperationException(err.Message, err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err.Message, err); } catch (ArgumentException err) { throw new ProdOperationException(err.Message, err); } }
public static bool CanSelectMultiple(ProdWindow prodwindow, string automationId) { try { AutomationElement control = InternalUtilities.GetHandlelessElement(prodwindow, automationId); return(SelectionPatternHelper.CanSelectMultiple(control)); } catch (InvalidOperationException err) { throw new ProdOperationException(err.Message, err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err.Message, err); } catch (ArgumentException err) { throw new ProdOperationException(err.Message, err); } }
/// <summary> /// Clicks this ProdButton. /// </summary> /// <param name="prodwindow">The ProdWindow that contains this control..</param> /// <param name="automationId">The UI Automation element</param> /// <exception cref="ProdOperationException">Examine inner exception</exception> /// <remarks> /// The program will also attempt to identify using the name property if the AutomationId fails /// </remarks> public static void ButtonClick(ProdWindow prodwindow, string automationId) { try { BaseProdControl control = new BaseProdControl(prodwindow, automationId); InvokeBridge.ClickBridge(null, control); } catch (InvalidOperationException err) { throw new ProdOperationException(err.Message, err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err.Message, err); } catch (ArgumentException err) { throw new ProdOperationException(err.Message, err); } }
/// <summary> /// Register to make a window the active window. /// </summary> /// <param name="extension">The extended interface.</param> /// <param name="baseControl">The base control.</param> internal static void ActivateWindowBridge(this WindowAdapter extension, ProdWindow baseControl) { //try //{ // NativeMethods.ShowWindowAsync(baseControl.NativeHandle, (int)ShowWindowCommand.SW_SHOWDEFAULT); // NativeMethods.ShowWindowAsync(baseControl.NativeHandle, (int)ShowWindowCommand.SW_SHOW); // NativeMethods.SetForegroundWindow(baseControl.NativeHandle); //} //catch (ArgumentNullException err) //{ // throw new ProdOperationException(err); //} //catch (ElementNotAvailableException err) //{ // throw new ProdOperationException(err); //} //catch (InvalidOperationException err) //{ // throw new ProdOperationException(err); //} }
/// <summary> /// Set value of control /// </summary> /// <param name="prodwindow">The containing ProdWindow.</param> /// <param name="automationId">The automation id (or caption)</param> /// <param name="value">The value to set the slider to.</param> /// <exception cref="ProdOperationException">Examine inner exception</exception> /// <remarks> /// This is the WPF version /// </remarks> public static void SliderSetValue(ProdWindow prodwindow, string automationId, double value) { BaseProdControl control = new BaseProdControl(prodwindow, automationId); RangeValueBridge.SetValueBridge(null, control, value); }