Wednesday, 8 March 2017

100 Day Deep Work - Day 6: Checking Multiple Links using WebDriver

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

We need to a) locate the links section and b) count how many links there are on the page:

var locateTheLinkSection = 

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!