I have a fairly simple list page that I generated using the MVC scaffolding. I am trying to write a CodedUI page that checks to see if there is a 'Create New' link at the top of the page.
I autogenerated the test using the Test Builder, but the test is only able to find my 'create new' link control if I delete the paragraph that my link is encased inside:
@model IEnumerable<MyItem>
@{
ViewBag.Title = "My items";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>My items</h2>
<!--<p id="createNewParaId">-->
@Html.ActionLink("Create New", "Create", new { controller = "Items" }, new { @id = "createNewLinkId" })
<!--</p>-->
<table class="table"> [...]
If I keep the paragraph in, the test doesn't find my link, and the inbuilt control locator functionality can't find it either. I can even record the control during a session and then immediately try to find it during the same session, and it still won't find it.
I tried writing my own test to force a search just based on ID, but this still doesn't work (UITestControlNotFoundException). I don't understand why it won't find it by ID just because it's inside a paragraph? If I comment out the paragraph as above, this test suddenly works:
public bool HasCreateLink()
{
HtmlHyperlink createNewLink = new HtmlHyperlink(UIInterWindow.UIItemsDocument);
createNewLink.SearchProperties[HtmlHyperlink.PropertyNames.Id] = "createNewLinkId";
string expectedLink = "/MySite/Admin/Items/Create";
string actualLink = createNewLink.AbsolutePath;
return expectedLink.Equals(actualLink);
}
The shared layout is as follows:
<body Id="outerBodyId">
<header class="clearfix container-fluid" id ="mainHeaderId">
@Html.Partial("_TopNav")
</header>
<div class="container body-content" id="mainBodyId">
@RenderBody() [...]
As you can see, I've tried to add Id properties to everything in case that would help CodedUI out, but it doesn't seem to have worked.
I also tried explicitly naming the entire hierarchy inside the test but then it just fails to find the mainBodyId div. Surely you shouldn't have to explicitly name the whole hierarchy anyway as this would be really fragile?
HtmlDiv divMainBody = new HtmlDiv(UIInterWindow.UIItemsDocument);
divMainBody.SearchProperties[HtmlDiv.PropertyNames.Id] = "mainBodyId";
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException occurred HResult=-268111872 Message=The playback failed to find the control with the given search properties. Additional Details: TechnologyName: 'Web' ControlType: 'Pane' TagName: 'DIV' Id: 'mainBodyId'
Aucun commentaire:
Enregistrer un commentaire