Coypu 0.16.1

82 views
Skip to first unread message

Adrian Longley

unread,
Apr 29, 2013, 3:23:58 AM4/29/13
to co...@googlegroups.com
Hi,

I've been back on a .Net project recently so been using Coypu again. After seeing what people came up with over the last couple of months I've added a couple of small features which should be a big help:

## FindCss now takes expected text as a string or Regex

Often there's an element you want to click, or assert the presence of which will not be cound by FindLink or FindButton, perhaps its a <span> or a <li> that has a javascript click event handler attached to it but is not using <a> or <button> or the like.

I found in this particular case people were using FindAllCss and then filtering the results by their text, which is not great for a number of reasons, so now you can do:

    browserSession.FindCss("ul.models li", text: "Citroen");
    browserSession.FindCss("ul.models li", text: new Regex("Citroen C\d"));

    bool foundCitroen = browserSession.HasCss("ul.models li", text: "Citroen");
    bool foundCitroenCx = browserSession.FindCss("ul.models li", text: new Regex("Citroen C\d"));

And there are NUnit matchers for this:

    Assert.That(browserSession, Shows.Css("ul.models li", text: "Citroen");
    Assert.That(browserSession, Shows.No.Css("ul.models li", text: new Regex("Citroen C\d"));

By the way, there are also Shows.Content matchers for HasContent and HasNoContent that I added a while back which give much better feedback than Assert.That(browserSession.HasContent("10 results found")) for example.

## FindAllCss takes a predicate so Coypu can wait for the expected state

Sometimes you want to assert against a list of elements but wait for the full list to be loaded. For this case I've added a predicate argument to FindAllCss so you can make it wait until that predicate is satisfied before return a list of all matching elements:

var elements = browserSession.FindAllCss("ul.search-results li", elements => elements.Count() == 5);
Assert.That(elements[0].Text, Is.EqualTo("First search result title"));

Alternatively you could put assertions in the predicate if you like, it would give better feedback when it fails:

var elements = browserSession.FindAllCss("ul.search-results li", elements => {
Assert.That(elements.Count(), Is.EqualTo(5));
Assert.That(elements[0].Text, Is.EqualTo("First search result title"));
return true;
});

-----

That's it for now
Adrian


Reply all
Reply to author
Forward
0 new messages