简体   繁体   中英

Visual Studio coded ui click on the first record returned from a search

I have a recording in Visual Studio 2012 for an application I'm testing. I record adding a person with a case (a child record). The case number is auto generated, so every time I run this test it's different.

When I playback my recording, it fails while trying to click on the link to the case record. This is because the link is different each execution.

The code that specifies this is in the designer (even after I "move" it to the UIMap file). Plus, I can't change it each time to predict what the number will be anyway.

How do I get the recording to select based on first link in the list (it's a gridview) rather than the specific link test and url?

A clever co-worker helped me out. Here is the solution he found:

replaced  Mouse.Click(uIHHP2013000005Hyperlink, new Point(49, 2));

where had been defined in my UIMap designer with hard-coded values.

with:

HtmlControl control = new HtmlControl(this.UIPersonsCCDWindowsIntWindow.UIDetailsCCDDocument);
        control.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "HtmlHyperlink");
        UITestControlCollection controlcollection = control.FindMatchingControls();
        List<string> names = new List<string>();
        foreach (UITestControl x in controlcollection)
        {
            if (x is HtmlHyperlink)
            {
                HtmlHyperlink programCaseLink = (HtmlHyperlink)x;
                if (programCaseLink.Href.StartsWith("http://mywebsite.com/ProgramCase/Details/"))
                {
                    Mouse.Click(programCaseLink);
                }
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM