Here we
are, Day 6 and pretty much a continuation of yesterday. I suppose I should say
refinement or refactoring. Compared to the approach taken in yesterday’s
session I scaled this right back to something simpler. Why? Here comes today’s
(and yesterday’s) real learning.
I was
breaking the golden rule of taking it one step at a time. Instead I was trying
to work out what the overall solution looked like then code it up. That was doomed
to failure so I went back to baby steps and simplified things.
First off, recall the (cut down) testing problem from yesterday:
You have a website with 2 navigation links. The expectation is more
links will be added in the future. The test must check the known set of text
links are present and if any new ones have been added.
That’s the
first part so let’s work out some code for that.
Here’s the
list of expected links:
public enum links
{
News,
Sport
}
We need to a) locate the links section and b) count how many links there are on the page:
var locateTheLinkSection
=
Driver.Instance.FindElement(By.XPath("//ul[@class='nav-tabs']"));
var actuaLinkSetCount
= locateTheLinkSection.FindElements(By.TagName("a")).Count();
Good,
we have a count of what is on the page, but is that what was expected?
var expectedLinkSetCount
= links.Count();
Console.WriteLine($"Expected
link Set Count is {expectedLinkSetCount}.");
Console.WriteLine($"Actual
link count is: {actuaLinkSetCount}");
We could
wrap this in an if-else or a try-catch to actually DO something given the outcome,
but that’s a way to get our check done.
I’d still like
to report what was new, what actual links got found, etc. not just a count - but that’s something to
look at later.
Good, onto
day 7!
Mark
(Be sure to have a look at the book - Deep Work)
-------------------------------------------------------------------------------------------------------------
Day 5: http://cyreath.blogspot.co.uk/2017/03/100-day-deep-work-day-5-iterating-over.html
-------------------------------------------------------------------------------------------------------------
Day 5: http://cyreath.blogspot.co.uk/2017/03/100-day-deep-work-day-5-iterating-over.html
Day 3: http://cyreath.blogspot.co.uk/2017/03/100-day-deep-work-c-enumerations.html
Day 2: http://cyreath.blogspot.co.uk/2017/03/100-day-deep-work-day-2-comparing.html
Day 1: http://cyreath.blogspot.co.uk/2017/02/100-day-deep-work-day-1-c-namespaces.html
Day 0: http://cyreath.blogspot.co.uk/2017/02/100-day-deep-work-day-0-learning-plan.html
Day 2: http://cyreath.blogspot.co.uk/2017/03/100-day-deep-work-day-2-comparing.html
Day 1: http://cyreath.blogspot.co.uk/2017/02/100-day-deep-work-day-1-c-namespaces.html
Day 0: http://cyreath.blogspot.co.uk/2017/02/100-day-deep-work-day-0-learning-plan.html