1

Update: I used some hit and trial method for this issue and found that this issue of slowness occurs only when Coded UI (or my code) encounters any Date-Type text field. If there is no Date-Field over the page which is used by test cases, then execution is fast enough. Further digging into issue make me understand that almost all the date-fields have Client Side validation scripts and each date field use masking. So, I tried the same with Coded UI recording and found that if during record and playback, I enter a value in date field using Keyboard, then playback is too slow, but if uses Calendar control to select a date then playback is fast enough. This is the root cause of the issue.

Solution: Didn't get any solution, because I can't use Calendar control for selecting a past date which is like multiple clicks on the calendar. Tried using 'SendKeys' instead of 'text' for setting the value of the text field but still no improvement.

I hope this updated information will provide some hint in providing an answer to this question.

Update ends.


I am creating some test cases in Coded UI using handwritten code. For the same, I have created a generic function for finding a Text Box and then setting its value. Code for that function is provided below. I call this function every time I need to provide value for a text box over any page.

public static void FindTextBox_SetText(BrowserWindow brw, string str_uiElementPrimaryLocator, string str_uiElementSecondaryLocator, string str_uiElementInputValue)
        {
            Boolean bol_textBoxFound;
            HtmlEdit html_textBox = new HtmlEdit(brw);
            if (!string.IsNullOrEmpty(str_uiElementInputValue))
            {
                if (brw.Exists)
                {
                    html_textBox.SearchProperties[HtmlEdit.PropertyNames.Id] = str_uiElementPrimaryLocator;
                    html_textBox.SearchProperties[HtmlEdit.PropertyNames.Name] = str_uiElementSecondaryLocator;
                    bol_textBoxFound = html_textBox.Exists;
                    if (bol_textBoxFound)
                    {
                        html_textBox.Text = "";
                        html_textBox.Text = str_uiElementInputValue;
                    }
                    else
                    {
                        Assert.IsTrue(bol_textBoxFound, "TextBox not found");
                    }
                }
                else
                {
                    Assert.IsTrue(brw.Exists, "Browser window for finding the TextBox does not exists.");
                }
            }
            else
            {
                //Do nothing
            }
        }

Implementation Example: In my application I have a page which has 8-10 text fields (some page have more than that and some have less), 2-3 dropdowns etc. For each page I have created a separate method for filling all the fields of that page 9as that page is being used in many test cases, so to avoid code repetition, I created a separate method for page fields) and for each Text box field, I call this above function. So, in short, this function is being called 10 times in a test case.

Issue: First 3-4 calls to this function are completed in seconds (very short duration), while next 2-3 calls take minutes to complete. To better describe issue, when Coded UI runs my test, it finds text box (T1) and then insert its value in 1 sec (let's say), then it finds T2 and insert its value in the same time, then it finds T3 and insert its value in the same time but; when it goes to 4th or 5th field, it takes 1-2 minutes to Empty and Fill that field and then again next 3-4 fields are filled in seconds. no matter what is the order of fields (i.e. T1, T2, T3 --> Fast processing; T4, T5 --> Slow processing OR T3, T4, T1 --> Fast Processing; T2, T5 --> Slow Processing). I tried to Debug the test case and found that most of the time is being consumed at these two lines of code for the 3rd and 4th field

html_textBox.Text = "";
html_textBox.Text = str_uiElementInputValue;

Why is this happening (as I am calling the same function) and What is the solution or better approach for this.

HTML for Text Box and Date Fields are:-

<input name="FindVariables.RecordNumber" class="form-control valid" id="FindVariables_RecordNumber" aria-invalid="false" aria-describedby="FindVariables_RecordNumber-error FindVariables_RecordNumber-error" type="text" value="" data-val-atleastonerequired-properties="FileNumber,ID,RecordNumber,SellerNumber,StartDate,SaleDateStart" data-val-atleastonerequired="At least one marked field is required to search." data-val="true" autocomplete="off">

<input name="FindVariables.StartDate" class="form-control type-date hasDatepicker" id="FindVariables_StartDate" type="text" value="" data-val-regex-pattern="(99|0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01]|99)/(99|[1-3]\d\d\d)" data-val-regex="Valid date is required (MM/DD/YYYY)" data-val-atleastonerequired-properties="FileNumber,ID,RecordNumber,SellerNumber,StartDate,SaleDateStart" data-val-atleastonerequired="At least one marked field is required to search." data-val="true" autocomplete="off">
11
  • Because I can't comment: Here are some thoughts, I can probably provide more if you give the HTML as well. What is similar about the fields that are processing slow? Or fast? Carefully look at the UIspy to review the ControlType and Properties. Remember, the more specific you make your SearchProperties the faster they will locate. Conversely, the more properties you have that are inaccurate will increase the search time. Here is a blog on how CodedUI uses its Find() method. You may find that the control that eventually gets Commented Jan 26, 2016 at 16:33
  • I have added the HTML of Textbox (working fast) and Date Field (working slow).
    – Dhiman
    Commented Jan 26, 2016 at 18:40
  • What is the ControlType of each when you use the test builder to look at them? Commented Jan 26, 2016 at 18:44
  • Also have you tried setting the value of the second? dateField.SetProperty("Value", "valuethatissethowitlikesit"); Commented Jan 26, 2016 at 18:46
  • Control Type for both fields is 'Edit'. I tried using '.SetProperty' method but unfortunately it is more slower than 'SendKeys' :(.
    – Dhiman
    Commented Jan 26, 2016 at 19:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.