none
CodedUI Test Builder cannot find object with dynamic TagInstance.

    Question

  • I'm currently using Visual Studio Ultimate 2013 to create UI maps for my automated test suite.  Typically, I can edit the PageMap.uitest file to "generi-size" the objects so they can be found when testing different URLs.  In this case, I mapped a Pane containing a header label, and edit field, and a search button.  If I change to a different URL and go to the same page, though, the Pane cannot be found.  I tried mapping the "new" Pane, but the only difference between the two is the TagInstance value.  I tried removing that parameter (so that all of the search and filter parameters match, but it didn't work.  It would be totally unworkable to have to create separate page maps and separate test scripts for each test environment.  Isn't there some way to make the various test environments see the same page objects?

    Here is what I mean.  This is the .uitest node for the object in ABC.stage.com:

    <UIObject ControlType="Pane" Id="UserManagementSearchPane" FriendlyName="User Management Employee ID Find You Ar" SpecialControlType="None">
      <TechnologyName>Web</TechnologyName>
      <WindowTitles>
        <WindowTitle>Page Hub</WindowTitle>
      </WindowTitles>
      <AndCondition Id="SearchCondition">
        <AndCondition Id="Primary">
          <PropertyCondition Name="ControlType">Pane</PropertyCondition>
          <PropertyCondition Name="TagName">DIV</PropertyCondition>
          <PropertyCondition Name="Id" />
          <PropertyCondition Name="Name" />
          <PropertyCondition Name="InnerText" Operator="Contains">User Management Employee ID  </PropertyCondition>
        </AndCondition>
        <FilterCondition Id="Secondary">
          <PropertyCondition Name="Title" />
          <PropertyCondition Name="Class">row</PropertyCondition>
          <PropertyCondition Name="ControlDefinition">class=row</PropertyCondition>
          <PropertyCondition Name="TagInstance" />
        </FilterCondition>
      </AndCondition>
      <SupportLevel>0</SupportLevel>
    

    When this object was initially mapped, the TagInstance value was 143.  I removed the value while attempting to make it more generic, but the CodedUI Test Builder can still find the object when looking at the ABC url.  It won't find it, however, in the XYZ url.

    This is the .uitest node for the same object in XYZ.stage.com:

    <UIObject ControlType="Pane" Id="UserManagementSearchPane2" FriendlyName="User Management Employee ID Find You Ar" SpecialControlType="None">
     <TechnologyName>Web</TechnologyName>
      <WindowTitles>
        <WindowTitle>Page Hub</WindowTitle>
      </WindowTitles>
      <AndCondition Id="SearchCondition">
        <AndCondition Id="Primary">
          <PropertyCondition Name="ControlType">Pane</PropertyCondition>
          <PropertyCondition Name="TagName">DIV</PropertyCondition>
          <PropertyCondition Name="Id" />
          <PropertyCondition Name="Name" />
          <PropertyCondition Name="InnerText" Operator="Contains">User Management Employee ID  </PropertyCondition>
        </AndCondition>
        <FilterCondition Id="Secondary">
          <PropertyCondition Name="Title" />
          <PropertyCondition Name="Class">row</PropertyCondition>
          <PropertyCondition Name="ControlDefinition">class=row</PropertyCondition>
          <PropertyCondition Name="TagInstance">336</PropertyCondition>
        </FilterCondition>
      </AndCondition>
      <SupportLevel>0</SupportLevel>
    

    As you can see, other than the TagInstance value (and the Id, of course), the search parameters are identical.  My question is... Why can't the object be found in either environment, or how can I make this object generic enough to find in both environments?



    Kevin

    Wednesday, August 10, 2016 3:56 PM

Answers

  • Hi KWD_AA,

    According to your description, only the control Pane you posted above doesn’t work with various URLs. And based on the Item #1 I posted, we could get an object which is generic enough to find by any test URL. You could refer to the following scenarios:

    1). Just as your reply, you removed the TagInstance properties and failed to recognized the Pane in XYZ.stage.comn. I think you should remove ID property too, which could ensure the code is generic enough.  Then you could use the generic code to capture the Pane control with DrawHighlight() function in different URLs, whether this general code woks for different URLs.

    2). According to the return message, you should ensure the Pane control is visible in your web. As far as I know, coded UI could not capture a control which is invisible. You could add WaitForControl functions to ensure the control is displayed. If you have the permission to re-code the Panel control, I suggest you could add a background to the Panel control that could help us to easily find whether it is loaded successfully.

    One bolg about wait for event please refer to the following link:

    https://blogs.msdn.microsoft.com/gautamg/2010/02/12/how-to-make-playback-wait-for-certain-event/

    Sincerely,

    Oscar


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, August 15, 2016 8:55 AM
    Moderator

All replies

  • Hi KWD_AA,

    Could you please share your detailed steps to recognize a similar pane control in a same page (with different UIL) with Test Build Record?  If you want to find a similar object that with dynamic TagInstance with the code generated by Coded UI Test Builder, I think you should recode the code to exclude uncertainty factor (include not only the properties of control). In your code, when you use Test Builder to find control in XYZ.stage.com with ABC.stage.com’s properties, firstly TagInstance property should be considered and we will consider other factors. Because Test Builder find two similar control you specified in different URL will not exactly the same.

    Here are two ways to help us troubleshoot this issue:

    1)You could create two coded UI projects, and capture the similar two controls with Test Builder separately. Comparing with the two generated codes and comment out the different codes, then you could capture the similar controls with the common codes.

    2)We could implement this scenario with hand-code. In my side, I have created two Panel object in different web page, the difference between them are ID and TagInstance. In my code UI project, I could find them correct with DrawHighlight() function. Please refer to the following code:

      BrowserWindow browser = new BrowserWindow();
    
                browser = BrowserWindow.Launch(new Uri("http://10.168.197.19:801/Default.aspx"));
    
                HtmlDiv htmlDiv = new HtmlDiv(browser);
    
                htmlDiv.SearchProperties[HtmlDiv.PropertyNames.Id] = "UserManagementSearchPane";
    
                htmlDiv.DrawHighlight();
    
                browser.NavigateToUrl(new Uri("http://10.168.197.19:801/Blue.aspx"));
    
                htmlDiv.SearchProperties[HtmlDiv.PropertyNames.Id] = "UserManagementSearchPane2";
    
                htmlDiv.DrawHighlight();

    Sincerely,

    Oscar


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.



    Friday, August 12, 2016 9:32 AM
    Moderator
  • Hi Oscar.   Thanks for the response.  I understand what you're saying, but here's the problem...  I have 4 separate projects, all mapped the same way, having an average of 102 individual .uitest page map files, and the one I posted above seems to be the only one that doesn't work with various URLs.  Here's one example of a node that can be used across URLs:

    <UIObject ControlType="Hyperlink" Id="Home" FriendlyName="Home" SpecialControlType="None">
      <TechnologyName>Web</TechnologyName>
      <WindowTitles>
        <WindowTitle>WebSceptre : Home</WindowTitle>
      </WindowTitles>
      <AndCondition Id="SearchCondition">
        <AndCondition Id="Primary">
          <PropertyCondition Name="ControlType">Hyperlink</PropertyCondition>
          <PropertyCondition Name="Id" />
          <PropertyCondition Name="Name" />
          <PropertyCondition Name="TagName">A</PropertyCondition>
          <PropertyCondition Name="Target" />
          <PropertyCondition Name="InnerText">Home</PropertyCondition>
        </AndCondition>
        <FilterCondition Id="Secondary">
          <PropertyCondition Name="AbsolutePath" Operator="Contains">/Default.aspx</PropertyCondition>
          <PropertyCondition Name="Title" />
          <PropertyCondition Name="Href" Operator="Contains">/Default.aspx</PropertyCondition>
          <PropertyCondition Name="Class">level1 selected static</PropertyCondition>
          <PropertyCondition Name="ControlDefinition">class="level1 selected static" tabIndex=</PropertyCondition>
          <PropertyCondition Name="TagInstance">1</PropertyCondition>
        </FilterCondition>
      </AndCondition>
      <SupportLevel>0</SupportLevel>
      <Descendants />
    </UIObject>
     

    Notice that this node also has a distinct TagInstance value, even though this one, too, is dynamic based on the other objects that are displayed on the screen when the page is displayed. 

    The point you're making with Item #1 is typically the method I use to make sure the objects are generic enough to find by any test URL.  This particular example is a link pointing to the AUT Home page, which is on every application page.  By using the Operator="Contains" clause, it doesn't matter which URL I'm testing, because even though they may have a different http:// address, they all contain /Default.aspx as part of the Home page URL.

    I also sometimes use the DrawHighlight() function during development to make sure the correct object is being accessed when the test script is under development.  This is the first time, though, that the Coded UI Test Builder (when searching for a page object) finds the object using one URL but returns a The selected control cannot be highlighted because it is hidden message using a different URL.


    Kevin


    • Edited by KWD_AA Friday, August 12, 2016 3:39 PM corrected error msg
    Friday, August 12, 2016 3:29 PM
  • Hi KWD_AA,

    According to your description, only the control Pane you posted above doesn’t work with various URLs. And based on the Item #1 I posted, we could get an object which is generic enough to find by any test URL. You could refer to the following scenarios:

    1). Just as your reply, you removed the TagInstance properties and failed to recognized the Pane in XYZ.stage.comn. I think you should remove ID property too, which could ensure the code is generic enough.  Then you could use the generic code to capture the Pane control with DrawHighlight() function in different URLs, whether this general code woks for different URLs.

    2). According to the return message, you should ensure the Pane control is visible in your web. As far as I know, coded UI could not capture a control which is invisible. You could add WaitForControl functions to ensure the control is displayed. If you have the permission to re-code the Panel control, I suggest you could add a background to the Panel control that could help us to easily find whether it is loaded successfully.

    One bolg about wait for event please refer to the following link:

    https://blogs.msdn.microsoft.com/gautamg/2010/02/12/how-to-make-playback-wait-for-certain-event/

    Sincerely,

    Oscar


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, August 15, 2016 8:55 AM
    Moderator