Remove Property in Coded Ui Testing


Normally when we go ahead with recording the scenario of logging into the gmail account, we navigate to the user login page from their to the User specific page with the controls being displayed from the automation testing perspective in some way or the other dependent on the logged in user details, such as the user pane containing the username type of account et al.

When we record the login scenario and validate the logged in user details, we generate a code suppose for the below code its like :

Validate User logged in details :

public void ValidateUesrDetails()
        {
            #region Variable Declarations
            HtmlDiv uIGuserPane = this.UIGmailEmailfromGoogleWindow.UIMainFrame.UIHttpsmailgooglecommaDocument.UIGuserPane;
            #endregion

            // Verify that 'guser' pane's property 'InnerText' contains 'viplav15@gmail.com'
            StringAssert.Contains(uIGuserPane.InnerText, this.ValidateUesrDetailsExpectedValues.UIGuserPaneInnerText);

            // Verify that 'guser' pane's property 'InnerText' contains 'Sign out'
            StringAssert.Contains(uIGuserPane.InnerText, this.ValidateUesrDetailsExpectedValues.UIGuserPaneInnerText1);
        }
       

Now when we go through the properties of the associated set of control in our case being UIGuserPane , we find so many  search properties based on which the QTAgent of VSTS recognizes that very control in the screen. However these set of search properties have some expected values, which was as per the record time data in the AUT[application under test].

SO when we use the concept of Data Driven testing in order to replicate the flow for various types of users having different set of the properties associated with them, in that case the recorded set of script might fail just because the search properties as per expectation has been hardcoded for the Record time environment.

This is wherein comes the Remove property feature by which we can just remove the or rather modify the search criterion for such data bind controls which are bound as per the logged in username.


#region Properties
        public HtmlDiv UIGuserPane
        {
            get
            {
                if ((this.mUIGuserPane == null))
                {
                    this.mUIGuserPane = new HtmlDiv(this);
                    #region Search Criteria
                    this.mUIGuserPane.SearchProperties[HtmlDiv.PropertyNames.Id] = "guser";
                    this.mUIGuserPane.SearchProperties[HtmlDiv.PropertyNames.Name] = null;
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.InnerText] = "viplav15@gmail.com | Settings | Help | S";
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.Title] = null;
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.Class] = "a8";
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.ControlDefinition] = "class=a8 id=guser";
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.TagInstance] = "25";
                    this.mUIGuserPane.WindowTitles.Add("Gmail - Inbox (1294) - viplav15@gmail.com");
                    this.mUIGuserPane.WindowTitles.Add("Gmail - Inbox (1295) - viplav15@gmail.com");
                    #endregion
                }
                return this.mUIGuserPane;
            }
        }
        #endregion


This is how we can go across the above scenario and validate the requirement to suite the cause of Data Driven testing.  The code modification will be always done in the test class file, prior to the relevant method call.
Now modifying the container class properties :
// Declare the container variable as an html control as described in the uImap.designer.cs file

HtmlDiv uIGuserPane = this.UIMap.UIGmailEmailfromGoogleWindow.UIMainFrame.UIHttpsmailgooglecommaDocument.UIGuserPane;


            HtmlDiv uIGuserPane = this.UIMap.UIGmailEmailfromGoogleWindow.UIMainFrame.UIHttpsmailgooglecommaDocument.UIGuserPane;
            uIGuserPane.SearchProperties.Remove(HtmlDiv.PropertyNames.Id);
            uIGuserPane.SearchProperties.Remove(HtmlDiv.PropertyNames.Name);
            uIGuserPane.SearchProperties.Remove(HtmlDiv.PropertyNames.InnerText);
            uIGuserPane.SearchProperties.Remove(HtmlDiv.PropertyNames.Title);
            uIGuserPane.SearchProperties.Remove(HtmlDiv.PropertyNames.Class);
            uIGuserPane.SearchProperties.Remove(HtmlDiv.PropertyNames.ControlDefinition);
            uIGuserPane.SearchProperties.Remove(HtmlDiv.PropertyNames.TagInstance);
            this.UIMap.SignIntoGmailGlobal(TestContext );


By this block of code what we have done above is modified the container classs properties.
When I say container class properties, it is nothing but the container that contains the specific controls, such as in this very case is the User pane which has in it the username attached. In VSTS automation , what we do is that since we have the container class property associated with the content directly, we need to modify the properties of the container as per the degree of data independence that needs to be brought for our usage.

For example suppose Viplav15 user has logged into his gmail account, so from automation perspective the pane or the html control that has the user specific details in it, as well might be dynamically generated with the container properties  as per the user name or things like that, we need to make that independent of the specific user, by using the remove properties of the tags as is described above.




2 comments:

  1. But if we remove these properties, how will the QTAgent recognize that Control during Playback?

    ReplyDelete
  2. When we record we find that each controls are recognized based on two specific properties - One search properties and the pother one is filter properties. As my overall experience suggest, in order to recognize a control one or two properties are sufficient to recognize the control. As has been explained above what I did is just removed all properties. BUt when we come across this practically, we can remove all other properties other than Id and Name , innertext. Other than these we can easily remove all others.

    ReplyDelete