NumericUpDown contol Automation

Sep 2, 2010 at 11:18 AM
Edited Sep 2, 2010 at 11:19 AM

I am trying to get NumericUpDown Control in white ...

do any body have some idea how to do that

 

thanks in advance

Sep 2, 2010 at 12:11 PM
Edited Sep 2, 2010 at 12:11 PM

Hi

using System.Windows.Automation;
using White.Core.UIItems;
using White.Core.UIItems.Actions;
using White.Core.UIItems.Custom;
using White.Core.UIItems.Finders;
using White.Core.UIItems.WPFUIItems;

namespace ETS4TestHelper.CustomUIItems
{
  /// <summary>
  /// handle Numeric Up and Down Controls  /// </summary>
  [ControlTypeMapping(CustomUIItemType.Custom)]
  public sealed class MyNumericUpAndDown : CustomUIItem
  {

    private const string _buttonUpAuId = "PART_ButtonUp"; 
    private const string _buttonDownAuId = "PART_ButtonDown";
    //private const string _valueAuId = "_TextBox";

    private readonly Button _buttonUp;
    private readonly Button _buttonDown;
    private readonly TextBox _valueTextBox;

    /// <summary>
    /// Initializes a new instance of the <see cref="ETS4NumericUpAndDown"/> class.
    /// </summary>
    /// <param name="element">The element.</param>
    /// <param name="actionListener">The action listener.</param>
    public MyNumericUpAndDown(AutomationElement element, ActionListener actionListener)
      :base(element, actionListener)
    {
      _buttonUp = this.Get<Button>( SearchCriteria.ByAutomationId( _buttonUpAuId ) );
      _buttonDown = this.Get<Button>(SearchCriteria.ByAutomationId(_buttonDownAuId));
      AutomationElement textBoxElement = GetElement( SearchCriteria.ByControlType( ControlType.Edit ) );
      if(textBoxElement!=null)
      {
        _valueTextBox = new TextBox( textBoxElement, ActionListener );
      }
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="ETS4NumericUpAndDown"/> class.
    /// </summary>
    private MyNumericUpAndDown(){}

    /// <summary>
    /// Gets the button up.
    /// </summary>
    /// <value>The button up.</value>
    public Button ButtonUp
    {
      get
      {
        return _buttonUp;
      }
    }

    /// <summary>
    /// Gets the button down.
    /// </summary>
    /// <value>The button down.</value>
    public Button ButtonDown
    {
      get
      {
        return _buttonDown;
      }
    }

    /// <summary>
    /// Gets the value.
    /// </summary>
    /// <value>The value.</value>
    public TextBox ValueTextBox
    {
      get
      {
        return _valueTextBox;
      }
    }
  }
}

 

call:

AutomationElement element = window.GetElement(SearchCriteria.ByAutomationID("id"));

MyNumericUpAndDown myNUD = new MyNumericUpAndDown(element, window.ActionListener);

 

 

On this way the constructor is called and my elements are initialized (if you want to get the element using get, you should write an init operation)

 

Throndorin

 

 

Sep 2, 2010 at 12:40 PM
Edited Sep 21, 2010 at 12:10 PM

Thanks Throndorin,

 

Sep 21, 2010 at 12:24 PM

i am using VS2010

still not able to find the reference System.Windows.Automation;

 

am i missing something?

 

 

Sep 22, 2010 at 4:50 AM
AutomationElement element = window.GetElement(SearchCriteria.ByAutomationID("id"));

MyNumericUpAndDown myNUD = new MyNumericUpAndDown(element, window.ActionListener);
after i call this function i am getting myNud values null  :(
Sep 24, 2010 at 8:19 AM

Hi

is "id" the correct automationID of the numericupand down control?, this is only a placeholder in my example

 

what does UISpy say?

 

is element != null?

 

Throndorin

Sep 24, 2010 at 9:51 AM

bandwidthNumericUpDown  is my id i have added it like this AutomationElement element = window.GetElement(SearchCriteria.ByAutomationID("bandwidthNumericUpDown "));

 

the control shown in UISPy is like this

"spinner","Bandwidth","bandwidthNumericUpDown" 
"button" ,"Backward" , "SmallDecrement"
"button", "Forward","SmallIncrement"

i am able to do click event for both button's :(

but not able to read values :(

 

 

 

Sep 24, 2010 at 10:11 AM

 

Hi

 

I'm so sorry, our developer has added AutomationPeer, so I had a customControl which contains the elements,

"customcontrol", "", "numericUpAndDown"

  "spinner","Bandwidth","bandwidthNumericUpDown" 
  "button" ,"Backward" , "SmallDecrement"
  "button", "Forward","SmallIncrement"

  and a Textbox

 

this custom control is not visible for utomation by default.

 

Throndorin