0
votes

Im trying to build a test case where i retrieve a list of data objects and populate it in a datagrid.

I want to verify (assert) that the 1st row has a field/column that StartsWith "ABC".

I can see that the generated code produces an element that basically has the field's exact display value (in this case it is "ABCDEFG").

Of course, when i run this test, it validates just fine because the generated element ("ABCDEFG") definitely startswith "ABC".

The problem is that the datagrid could be populated with dynamic data, so the field display could be something like "ABC-FOO" or even "XYZ" for instance.

In short the automated code that is generated seems to not behaving as i expect.

I am expecting to do a StartsWith assertion against the real-time field display, not a generated (hard-coded) string which i used to build the test with.

Am i doing something wrong here? Am i missing something critical? Or should i be abandoning Coded UI altogether?

Here is the generated element:

public HtmlLabel generatedLabel
{
    get
    {
        if ((this.mUIgeneratedLabelLabel == null))
        {
            this.mUIgeneratedLabelLabel = new HtmlLabel(this);
            #region Search Criteria
            this.mUIgeneratedLabelLabel.SearchProperties[HtmlLabel.PropertyNames.Id] = "Control_42";
            this.mUIgeneratedLabelLabel.SearchProperties[HtmlLabel.PropertyNames.Name] = null;
            this.mUIgeneratedLabelLabel.SearchProperties[HtmlLabel.PropertyNames.LabelFor] = null;
            this.mUIgeneratedLabelLabel.SearchProperties[HtmlLabel.PropertyNames.InnerText] = "ABCDEF-FOO";
            this.mUIgeneratedLabelLabel.FilterProperties[HtmlLabel.PropertyNames.Class] = "field-control";
            this.mUIgeneratedLabelLabel.FilterProperties[HtmlLabel.PropertyNames.ControlDefinition] = "class=\"field-control\" id=\"ControlB";
            this.mUIgeneratedLabelLabel.FilterProperties[HtmlLabel.PropertyNames.TagInstance] = "24";
            this.mUIgeneratedLabelLabel.WindowTitles.Add("MyTest");
            #endregion
        }
        return this.mUgeneratedLabelLabel;
    }
}

---- Updated ----

To explain what my confusion is: I've setup my StartsWith() assertion on some text ("ABCD") that has been retrieved dynamically. I created the asserttion to check if the text StartsWith "ABC". Now, when i look at the generated assertion code, i see that the assertion will always pass because the code is comparing the text's string literal ("ABCD") with the assertion check string literal ("ABC"). What I am looking for is to do the assertion check with whatever dynamic text is retrieved during the test run-time. Hope this makes it clear where im getting stuck.

1
I do not understand the question. Are you asking why the code you show contains the ... InnerText] = "ABCDEF-FOO"; line and what to do about it? If yes then why not delete that entry from the search properties. See also stackoverflow.com/a/19703241/546871 - AdrianHHH
Appended a detailed description to hopefully clarify where my confusion and issue is. - AlvinfromDiaspar
Please edit the question to show the assertion code. - AdrianHHH
Is your problem that you need to find the variable for comparison at run time, or that the comparison is not working right? - Rescis
The problem is that the generated code is essentially hard-coding the strings to be compared (not one of the strings is dynamic). If i look at the generated code i can literally see the hard-coded strings ("ABC" vs "ABCD"). What i need is to be able to check a string "ABC" against a string value that is determined at run-time. - AlvinfromDiaspar

1 Answers

0
votes

To figure out where the problem is, you could first try doing if (control.Text.Contains("ABC")), then try if(control.Text.StartsWith("ABS")), and see where the problem emerges.