title: Coded UI Tests: How can I set the search properties for recording?
body: <p>I wanted to inform myself about Coded UI Tests. So I created some coded ui tests and played a bit around.</p>
  <p>But now I'm at a point I can't help myself. I have the following problem. When I do record some actions from a dotNet 4.5 program, the recorder locates the forms, buttons, textfields and so on via <strong>SearchProperties[WinText.PropertyNames.Name]</strong> That's definitely uncool.</p>
  <p>Imagine you want to do an assertation on a text-control. The WinText.PropertyNames.Name would be the calculated value. So if you change some input values in the form which affect the calculation, the WinText.PropertyNames.Name will be changed to the new value and the coded ui test wont find the text-control with the changed value because it searched for the WinText.PropertyNames.Name of the control instead of the <strong>WinText.PropertyNames.ControlName</strong>.</p>
  <p><strong>My Question is, is there a way to change the configuration of the standard search property the coded ui test builder uses to locate the needed objects?</strong></p>
  <p>Because its a big effort to change this for every recorded object, afterwards.</p>
  <p>PS: I'm not talking about the <strong>C:\Program Files (x86)\Common Files\microsoft shared\VSTT\11.0\IEPropertyConfiguration.xml</strong> which takes only effect on ie sites =)</p>
  <h1>Additional:</h1>
  <p><strong>Lets make things clear:</strong></p>
  <p>Here's my code:</p>
  <pre><code>public class UIItem100180Window : WinWindow
      {
          
          public UIItem100180Window(UITestControl searchLimitContainer) : 
                  base(searchLimitContainer)
          {
              #region Search Criteria
              this.SearchProperties[WinWindow.PropertyNames.ControlName] = &quot;wert2Praemie12&quot;;
              this.WindowTitles.Add(&quot;Any Title&quot;);
              #endregion
          }
          
          #region Properties
          public WinText UIItem100180Text
          {
              get
              {
                  if ((this.mUIItem100180Text == null))
                  {
                      this.mUIItem100180Text = new WinText(this);
                      #region Search Criteria
                      this.mUIItem100180Text.SearchProperties[WinText.PropertyNames.Name] = &quot;1.001,80&quot;;
                      this.mUIItem100180Text.WindowTitles.Add(&quot;Any Title&quot;);
                      #endregion
                  }
                  return this.mUIItem100180Text;
              }
          }
          #endregion
          
          #region Fields
          private WinText mUIItem100180Text;
          #endregion
      }
  </code></pre>
  <p>I got a <strong>parent control(UIItem100180Window: WinWindow)</strong> which creates my <strong>Text-Control(UIITem100180Text: WinText)</strong> on UI, that represents the value of my calculation. The problem is both have the same <strong>.PropertyNames.ControlName</strong> =).</p>
  <p>That means if I'm going to add:</p>
  <pre><code>this.mUIItem100180Text.SearchProperties[WinText.PropertyNames.ControlName] = &quot;wert2Praemie12&quot;;
  </code></pre>
  <p>it will find alltime my parent-control: WinWindow. If I'm not adding it and if the value of the calculation changes (maybe calculation method was edited,..), and its not equal to <strong>this.mUIItem100180Text.SearchProperties[WinText.PropertyNames.Name] = &quot;1.001,80&quot;;</strong> the control wont be found and an errorMessage &quot;..control not found&quot; will be thrown.</p>
  <p><strong>Later I will get problems at this line,</strong> checking the Value of my text-control(WinText):</p>
  <pre><code>public void VerifyTextControl()
      {
          #region Variable Declarations
          WinText uIItem100180Text = this.xxx.UIItem100180Window.UIItem100180Text;
          #endregion
  
          // Verify that the 'DisplayText' property of '1.001,80' label equals '1.001,80'
          Assert.AreEqual(&quot;1.001,80&quot;, uIItem100180Text.DisplayText, &quot;järhlich muss 1.001,80 € betragen!&quot;);
      }
  </code></pre>
  <p>my <strong>uIItem100180Text:WinText</strong> is handled as <strong>WinWindow</strong> because it finds only my parent-control when I'm searching for the PropertyNames.ControlName, like I said both got the same name. So I <strong>can't use the .DisplayText-method</strong>, and it ends in an error Message.</p>
  <p>The best solution is, do your assertation on parent control, because it also keeps the value of the text-control and you wont have such problems like I had have.</p>
  <p>Maybe this post is helpful for people who struggle at the same point.</p>
  <p><strong>Note:</strong><br />
  UITestControl-&gt;WinControl-&gt;WinText<br />
  UITestControl-&gt;WinControl-&gt;WinWindow</p>