Goodbye Contracting

Hello brave new old world...

Ruby-Selenium Webdriver

In under 10 Minutes

%w or %W? Secrets revealed!

Delimited Input discussed in depth.

Ask questions

If you don't ask, you won't learn. You won't teach either.

Tuesday, 12 June 2018

Contracting - Let's Talk Money

Money.

It's why we do contracting, heck it's why we go to work. I've never understood the shyness we have in the UK about talking about money. Never ask anyone what they earn, how much they have saved, how their pension is going. I get it in the main.

We all struggle day to day just to pay the bills on time every time, pay the mortgage off (a dream for many), have a holiday once in a while and hey maybe even save up towards a pension. Not that anyone is going to retire in the future... It narks me that pulling together even a modest amount is such hard work, even when contracting. The 7-year cycle hits and knocks you down a few pegs. Tough but again, it's part of why we do contracting. To gain an accelerated income and make a better financial life for ourselves and our families.

But how much do YOU make?
To answer the question, £400 to £600 per day on average. That's been my contracting rate for pretty much the entirety of my contracting. I wonder if anyone reading this who knows me is surprised by that. I'd take £400/d  for a sit-in-the-corner doing coding stuff and towards £600 for a management role. There's been higher, but they were outliers.

Now, even though £400/d may seem low for someone with 20+ years of experience, it's still a truck tonne of money. So many contractors lose sight of that. 12 months of 20 days is 240 days, that times £400 is £96,000. That's nothing to complain about. A more typical minimum rate is £450/d, that's £108,000. Even if you don't bill all the days, due to holidays or gaps in contracts, you're still earning a shed load of money (running out of these now...)

Here's a reference to put that in context: (accessed today)

http://www.gq-magazine.co.uk/article/average-uk-salary

Average UK salary: £27,271

Before you start celebrating/consoling yourself, this data was taken by the Office For National Statistics from 21,563,000 people's earnings, with averages broken down for each profession. Topping the charts were brokers, who earned £133,677 on average, followed by chief executives and senior officials (£107,703), aircraft pilotsand flight engineers (£90,146) and marketing and sales directors (£82,962). At the other end of the scale are retail assistants (£10,296), hairdressers and barbers (£10,019), cleaners (£7,919), waitresses (£7,554) and bar staff (£7,404).
Even on the minimum of £450/d you're better paid than just about anyone. OK, no Million ££ bonuses for you but still something to pat yourself on the back for.

But can you manage it?
Gfeat, so you can pull in the revenue, but can you manage it? Let's loop back to the hands-on stuff.

Invoicing
The good stuff! Invoicing is pretty easy. Invoice your client as soon as you can each week or month, whatever has been agreed. Each invoice MUST have a unique ID. I have it as company-month-year-number, so ClientRef-Jan-18-001 for example. Calculate your charge (day rate x days worked) and add VAT @ 20%. Terms of payment are 28 days max, ALWAYS see if you can do weekly or fortnightly invoicing. You have nothing to lose but cash flow by asking!

When you do your monthly accounts, you need to record invoices sent out and paid to you, with the unique invoice number. Guess what? When you send an invoice you become liable for the VAT component even though you don't have the money yet. Yep, HMRC suck. So keep a buffer for covering that month's VAT in your business account.

Managing VAT
As mentioned, if you are on Standard Rate (20%) you can offset paid-out against collected VAT. Put anything that is remotely business like through the business and claim the VAT back.

Expense it!
Above almost anything, managing your expenses and reducing your tax is THE single most important reason you're doing this. It *can* seem like a lot of work, but the cumulative savings are worth it.
Electronics, equipment, computers, stationary, postage, books, subscriptions, training, software, hardware, ink, paper, printing, mobile phone (1 per employee), desks, shelves, pot plants (no, not that type ;p), cables, travel, subsistence - ANYTHING that could be stated as business related.

The above is a fine art, but there's more that can go through the business than you might think. The thing to bear in mind is - who can say what was really a legitimate expense? (caveats below) Do you think Coca Cola Corp don't put through crap like pencils, that odd subscription to the gaming magazine (hey, marketing research, new business idea) or say a training course to increase employee capability? Expense it, but be mindful of WHY.

You'll be able to calculate each month how much of that invoice amount you can take as Dividends/Salary. (Invoice amount, minus the VAT, less corporation tax) Let's say it's 8k. Remember that when you expense the above you're paying for it out of that potential 8k - so it's your money your taking, just that as you take it via expenses a) the company reduces it's overall profit and so the tax it pays, and b) you reduce the amount of Dividends you can take (Dividends can only come from corporation taxable profit that's left after expenses). So, if you expense 1k - the company only has profit that month of 7k so pays less Corp Tax at the end of the year. Of course now you can only take 7k dividends and so pay tax on that reduced amount. Also, if what you spend that 1k on is VAT'able, then you offset that outgoing VAT against the incoming VAT, saving that too.

Replay this - by spending on 'expense' through the business, you just saved the Corporation and Personal tax on that 1k and offset the VAT. Think the other way. You take the full 8k, having paid Corporation tax and personal tax, then buy something you pay VAT on. You just got taxed three times (VAT, Corp tax, personal tax), where you could have avoided it all. That is a powerful way to get a LOT more buying power for your money.

A note on expenses: As mentioned above, you can expense 1 mobile bill per employee (i.e. you.) but oddly also a £150 a year on a Christmas dinner per employee, the dinner is tax free like any other expense. However - note that Corporate Hospitality (lunches for clients, etc.) is classed as spending taxable profit. Get it? You pay £10 on dinner, at the end of the year HMRC say that money is part of the overall profit and you pay Corp tax on it. Odd but true.

Amortisation
Check the current figure but generally any item over £1k has to be amortised over a number of years. For example, buy a £3k computer and you can declare £1k as an expense now (Corp tax free), but the other £2k gets taxed. Next year you write-down the asset by £1k, saving the tax as this is a loss on profit. Same again next year. So you DO save the tax, just not in the same year.

Recapping - Expense it
Let me touch on this again. I'm always shocked how small minded fellow business owners are about what they put through their business. HMRC rule is that whatever goes through the business has to be a legitimate business expense. If you're going to reduce profits and so the tax paid, it has to be on something for the business.

So no, a night out at the cinema isn't a tax deductible, legitimate expense. Nor is that shiny new suit or fancy jacket you've been looking to buy. But it's a fine line. If that suit is a uniform, perhaps with a tailored company logo then it's got a unique use for the business and is a valid expense. If that cinema trip is corporate entertainment it can go through the books, but remember you pay tax on it so HMRC aren't going to panic.

If in doubt, leave it out. Or something like that. You know how I keep going on about not getting on the tax man's radar, this is a good example. Again, I've seen fellow business owners do all sorts of stupid things - just don't. Will a small business like us get queried? Probably not, but if you do then everything is up for investigation. You don't need that in your life.

In closing
Check every year what is and isn't the case with the above. Figures, allowable items, etc. change all the time. However, I hope the above has given you a sense that as you run a business now, you need to shift your mindset to that of a business owner. Be bold!

Until next time,

BTW... see that Mark J Diez, Hannover Game ad at the top right? That's me, I wrote that.
Click it and buy a copy.

Mark




Contracting - Business Set-up Steps, Admin, How and Why


From my previous post on the subject I gave a general overview of getting set-up as a business. Here's some more specific detail. Though this applies to the UK, I think the principles are the same.

Set up the Limited Company
Either do this through Companies House or via a company that does this for you. I recommend doing this with a company who deal with everything. It costs a bit more but is hassle free. Registration and set-up takes about 2 weeks.

You'll need a company address, Director and Secretary (who can be the same people). Be aware the company address is public so you might want a virtual office address. You will get a Registration Certificate with the company name and registration number on it. You'll need these later.
When you set up the business make sure you sign-up for Online Filing (if it's even an option NOT to now, I think it's mandatory) and ID Protection so no fecker can change your company details on the sly.

Example:

Register for VAT
You can ether register for Flat Rate or Standard Rate. You need to do this via the 'Government Gateway' services on the Companies House website. It takes about 1 week to get registered and you'll be issued Gateway ID, Pass, etc. and a VAT Certificate. As with the company registration certificate scan it and keep it safe as you will need this all the time too.

If you use Flat Rate (14%) you can charge your clients 20% and pocket the other 6%. I've never done this and having an overriding moral compass that doesn't let me skim like this I don't approve. That said, I know several contractors that do it. The other benefit is you don't need to calculate VAT paid out because you can't claim it back. That's the trade-off for using Flat rate.

Personally, I have always been Standard Rate, so that I can charge and offset VAT. Through the year any VAT paid is taken away from VAT collected on invoices and the difference paid to HMRC. If you buy anything business related, goods or services then offset the VAT. Never screw your VAT up - more on that later.


Company Bank Account
You MUST have a company account as business money/transactions must not be done through a personal account, ever. I use Santander as there were no fees, but some people don't like them as customer service can be pretty bad.

I've had no problem with them so far. Register online, it takes about 2 weeks to get set up. You'll get online banking, company paying in book and cheque. File them away, I bet you never use them given you have online access.

Take a note of your company account number, sort and IBAN (International Bank Account Number) as you'll need these later for clients to pay you.

Never, ever, ever, .... take out any money that is VAT or business/ corporation tax. You *can* as a director loan, but do it even once and HMRC will have their eye on you. I've also seen this being a deep hole you can get into as you try and pay VAT and Corp tax on time. More on that later.


Get Insurance
You'll need Liability Insurance as a minimum. That's the insurance you lean on when a client says you screwed up and need to pay back fees plus damages.  You might also need Public Liability insurance and Employee Liability Insurance, but not at first.

I use Simply Business brokers, check them out to get an idea: Simply Business

Appoint an Accountant
You'll need to do Book Keeping and Accounts when running your business. My recommendation is don't even think about skimping on an Accountant service. I use SJD Accountants and the advice they give you will save the fee they charge and the same again. What's more they're a source of ongoing advise on tax thresholds, VAT and other HMRC related goodness. Add to that, even if you do your own books and draw up your own accounts you still need them certified by an accountant before passing to HMRC. So don't bother; keep your books and pay for an accountant. As at June 2018 SJD is £140 a month including VAT (which you off-set of course) which is cheap.

All Set Up

At this point you have an incorporated business, that's VAT registered, insured, operating with a bank accountant and an appointed accountant. Yay! Now all you need is clients ;]



Doing your books
Do your books monthly and sweat over the small things. Your accountant will want them quarterly (see below) but do them monthly. You ARE going to want to record accurate details of every transaction no matter how big or small, there is no other correct way of doing this. Every fricken penny. You don't get frustrated with the tedious detail, you will never think 'It'll be ok' or ' I'll just square it off by doing this...'. Get it right 100%. I've seen sloppy accounts from other contractors too many times and it's scary. This will be hard and concerning at first, but after the first year it gets pretty routine.

A month of books will take you an evening. So 3 months of books will take you nearly a week…wait what? It will take longer because you'll have to remember what that odd receipt was, you'll forget an invoice or won’t find it, etc. Do your books monthly. OK, lecture over!


Quarterly Submissions (VAT)
Every 3 months your accountant will want your books (your accounts) sent in for review by a certain date. They will look over VAT figures, dividends and salary paid to date, etc. and send you a VAT Return along with any advice on whether you're paying yourself too much salary and dividends.

Your quarterly VAT Return is a CALL TO ACTION, jump on it! There are two components, the return you must go to the HMRC site to fill in (remember when you registered for VAT?) and the VAT payment. The SAME DAY you get your VAT return details from the accountant, do the return online and pay the goddam VAT.

The return is no more than about 10 fields, already filled in by the accountant, that you fill in online and hit submit. If you miss the return date you WILL be on HMRC radar. So just do it and pay the VAT that day, it's a 10 minute job.

Annual Accounts
At the end of the year, the accountant will pull together the formal accounts for the year. You'll get a Full and Abbreviated set, not much difference at our scale to be honest. However, they will ask you to review and confirm they can do the submission, review and then let them. HMRC trust verified accounts more than you or some mate sending them in. You also need to have your business bank accounts statement for the year sent along with the accounts to HMRC. Yup, glad you have a neat Business account now right, even if it is a legal requirement ;p

The accountant will assess how much Corporation Tax you have to pay. Oddly, end of year accounts are in the April/May timeline, but Corp Tax isn't due until January (usually, your accountant will advise as it depends on if you changed your 'filing date' (hint: don't). I have no idea why the delay, who cares. As with VAT, once you know the figure and can pay it (and you can because the money was always in the bank right?..) - just pay it.

Note on VAT and Corp Tax Payments: You pay both via an online transaction from your business account, to a HMRC account that is given online in the VAT / Corp Tax areas of the Gateway services section of the HMRC website. Your accountant will also know these details. However, you only need to go online and submit a return for VAT. Your accountant submits your end of year accounts and HMRC advise on the Corp Tax owed.

Annual Return
At the end of the year you also need to do an Annual Return. That is an online document where you state Directors, Company Secretary, Paid up Shares, Classification of Business, Confirm Address, etc. If nothing changes in the year you can skip through, make the Return, pay your £15 and you're done. Again, a 10 minute job. Just think of this like a Companies House business listing. Literally just admin for HMRC records.


Annual Directors Tax Return
As a Director you WILL have to do an annual tax return, where as an employee you might be asked some years. There's a bit more detail needed like investments, dividend, account interest. It's tedious as crap but most comes from your bank and business accounts. Your accountant will advise you of the need to fill this in and set you a deadline. I find it takes a couple of evenings to pull the details together (trawling bank accounts to find you made 14p interest in the year is so much fun). Fill it in, send it back to you accountant and authorise them to submit.

Paying your Personal Tax Bill
A few months after sending in your personal tax return, usually January like Corp Tax, you get a personal tax bill. This is your tax bill for taking salary and dividends. As always - get the bill pay the bill - ASAP. Unlike VAT and Corp Tax, personal tax must be paid from a personal bank account, as
it's your bill not the company's. But no sweat - because every time you take dividends, you should set aside the personal tax you'll pay on them. Then at the end of the year just pay it to HMRC. Like VAT and Corp Tax, this was money that was never yours, so no biggy. Hive it off each month and stick it into a separate account. If you have a personal account you never use, then great, use that.

Summary

So now; every month you do your books to keep track. You take your dividends and hive off your personal tax. Each quarter you do a VAT return and pay the VAT balance. Each year you do Annual accounts to calculate Corp Tax and pay it ASAP. You do your Personal Tax Return to calculate your personal tax and pay it ASAP. You then do your Annual Return to give admin details to HMRC.

And that's the business and HMRC formalities. Sounds a lot, but actually it gets pretty routine.

Next, let's talk about actual money management.

Mark


I copied this image off the Companies House Website...


Monday, 11 June 2018

Contracting - Entrepreneurship

Entrepreneurship - what is it?

Setting aside the obvious quip about how ridiculous this word is to spell... welcome to English (French...).

In my view it's as mentioned in the prior post. Looking at your world in an entirely different way. No longer are you being led but you're leading, no longer do you just have a job, you have a profession, no longer do you just work for The Man and nod your head in all the right places, you have to think.

I was heard a sermon by an American pastor, can't remember who sorry; the idea was to ask not for a miracle but a thought, an idea. That you were just one idea away from changing the world, one thought away from being a millionaire. In my opinion, entrepreneurship is just that. It's the generation and then execution of ideas and thoughts.

As an entrepreneur your job is to *think*, to think about what can make you money, that's thinking about who your customers are, what your customer wants and that you can provide, thinking about how you will provide it, for what price, in what way and of course, when. Then bill them for it.

I said before, opening your own business, seemingly just to go IT contracting at first, will open your mind to the possibility that everything you do is now a possibility to turn a profit. Everything you do is 'business'. It may be for a large profit or a small one, but it's business for a profit.

You HAVE to make a profit
The good thing is (at least in the UK), as a Director of your own business you can direct the business to engage in whatever will turn a profit. Did you know you have a legal responsibility to make a profit? That's right Mr, Mrs, Miss, Miz, He, She, Zee, It Director, you have to keep a grip of your business, think of clever ideas and make sure your new company makes a profit.

You may well start your business with the simple idea of increasing your personal income from that of your normal wage. It's true, that for the majority of people, going contracting will help you realise an increase in the amount of cash you take home. Remembering never to get tempted by any scheme that claims you can take home even more than that of a combined dividend and salary payment. However, I'm sure that once you start delivering your IT work under an independent contract, you'll figure out related ways to make a little extra cash contracting, through diversification.

There's never been a better time to make an independent income. Despite how much HMRC are clamping down on IT contractors, to the point I think they'd like to see the whole model disappear, you can still make a good income. The tricks are as stated in the first post and diversification. No one can tell you what your business can or can't engage in, what is a legitimate area of research, trading or down right experimentation.

Your Business is your Business
If you decide your business not only delivers testing services but also coding, writing technical articles, mentoring, developing video games, researching the latest tech or just blogging crazy IT ideas - then good for you. That's Entrepreneurship with a capital E and what the country needs. Expenses and profits related to these are all legitimate. Claim those R&D Tax Credits too. Fill out your accounts and submit with confidence.

I've seen too many people limit themselves in thinking their business is *just* testing or coding. Yet, then work with other companies who provide a range of services. So can you. Do whatever it takes to make a profit. Be a true entrepreneur, be enterprising, creative and thoughtful. It doesn't cost you any more to think than not think.

Mark

PS... see that Mark J Diez, Hannover Game ad at the top right? That's me, I wrote that.
Click it and buy a copy.





Contracting - Thoughts on getting set-up

Independent IT Contracting is a mixed experience. Some of it is good for sure, some of it is just a grind but you can get on with it and other bits are definitely a pain in the ass.

The Good
One great aspect that I never expected from going contracting was the sense of becoming an entrepreneur. Once I set up my own business (Ltd company via Companies House in the UK), it was a fundamental shift in mindset. Like others I'd spoken to, I was struck with the idea that I had full control over my financial destiny. That my time and effort, focus and interests were all now a way to generate revenue and in turn generate a profit. Every £$€ earned and spent was relevant.

No more coasting from pay cheque to pay cheque with the hope of a small percent pay rise each year and possible bonus. No more just paying the bills and tick-tocking along between pay day, bills and whatever saving I could make until retirement. Now it was all to play for. Win or Lose, it was down to me.

The Bad
Along with registering a business of course came some other administrative burdens. Registering for VAT, getting business insurance, hiring an accountant, keeping the books and doing quarterly accounts, annual returns and tax declarations. Sounds like a burden and hey, it's not exactly exciting, but it keeps you in touch with what is really happening in the business. This is absolutely key.

A few things I learned from hard won experience regarding these points:

  • Never miss any filing dates for HMRC, ever
You can be late paying your VAT or Business Tax, but file late and you'll be fined. You'll also be on the taxman's radar - and you definitely want to stay off that! Get your filings done on time every time.

  • Get an accountant to do your end of year accounts
As above, you need to make sure everything you put through the business is a legitimate expense, every invoice to clients, every payment into the business and every aspect of your financial accounts is spot on. Then wrap all of this up in a set of reviewed and approved accounts that get sent onto HMRC. That way there's no concern you made stuff up or made mistakes. Keep HMRC happy and off your back or it's yet more admin for you to do.

  • Never, ever use any umbrella, loan scheme, 90% income scheme or similar
Just avoid these like the plague. Yes, even umbrella companies. The simple reason is you lose control of what your income 'means'. It has to mean income - revenue from invoices, minus expenses for running the business (costs, tax, etc.), which leaves you profit from which to pay yourself director's dividends and salary. That's it no confusion, no sudden discovery HMRC don't like the scheme you're using, no accusation it's a tax avoidance scheme or even worse, outright tax evasion.

  • Do avoid paying as much tax as possible, legally
You have an absolute responsibility as a director of a business to save all costs and maximise all profits for the business, in any legal way possible. This is your new responsibility and you must be focused on it. Stop thinking like a salary slave and start thinking like an entrepreneur. Having your own business affords you so many opportunities in this regard you'll save literally thousands per year that non-business owners cannot save.

The Ugly
If you want to keep earning in IT contracting - you must keep learning. If you don't like the idea of being a lifelong learner, this may not be for you.

If you don't keep learning what's new in the marketplace, what is being asked for in contract job postings and what are the emerging practices or technologies - you're going to be un-hirable sooner than you think.  Almost every single time I got into a contract I watched as the world moved on outside of the domain I was working in, which meant I had to sit courses, watch YouTube videos and do hands on practice just to keep up to speed. Even with my ability and focus on this, I still got behind. You cannot sit on your laurels when contracting.

Until next time.

Mark



Friday, 8 June 2018

Goodbye Contracting, Hello...

In a series of short posts I've decided to 'come clean' about the last 10 years of contracting. Sharing some insights I don't often see are shared by other contractors and opening up about things I've not been able to talk about. I hope you enjoy these warts and all posts. They've been a long time coming.
--------------------------------------------------------------------

A New Direction
Just over 10 years ago I started my own small consultancy and went feet-first into contracting. At the time I was working for BJSS, a great consultancy with an amazing team. Leaving was a hard choice and one that would play on my mind to the present day. More on that later.

My very first contract was as a Test Manager on a Government Gateway project. I still have the fleece they gave us to celebrate the successful launch. I remember being a bit irked by one of the team who would constantly text on their phone during the stand-up. I literally wanted to shout at him to get out of the room, but hey, first contract and all that so I behaved!

Doable, but not Plane Sailing
To anyone that's thinking of becoming a contractor and nervous about whether they will fit in, be able to deliver, be able to handle the pace and focus - I say go for it. You can always decide it's not for you and go back to working for the Man. There is a lot of set-up and things to learn, but it's a great mind-shift. More on that later too.

Along the way I've had some great engagements, with real kick-ass deliveries that have left the client's business and team changed for the good. There's also been a good number of glitches along the way too. Yes, some clients are a nightmare. Either because they pay late, demand the unreasonable or just decide you're making them look bad. While I won't name names, it's time to share those stories too.

Things Change
A lot has changed since those early days, both in terms of the contract market, the way the UK government deal with contractors and how I find and deliver work.

It's no secret the UK government, via HMRC (like the IRS), are absolutely hammering contractors. From the introduction of IR35 legislation, cracking down on Umbrella companies and Loan schemes to reducing allowable expenses and increasing the tax paid on dividends - to name just a few moves against contractors in the last few years. Despite all this, contracting remains viable if you have the skills and contacts to make it work. I'll share how some of these things have hit me personally and how I responded to them.

The Secret Sauce to Contracting
If I had to distil what the keys to success have been, I'd say the following:
  • Always, always respect your customer and over deliver in any way you can
  • Every single day learn something new, keep developing your skills
  • Build your network, it's where 90% of your contracts will come from
  • Never, ever get on the wrong side of or try to fiddle the tax man
I'll see what insights I can share around these.

Until next time,

Mark

PS... see that Mark J Diez, Hannover Game ad at the top right? That's me, I wrote that.
Click it and buy a copy.



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
{
    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!



Tuesday, 7 March 2017

100 Day Deep Work - Day 5: Iterating Over Links



Day 5 of the 100 Day Deep Work challenge!

Today’s session was a bit all over the place. I spent most of the time imagining what I think the solution to my current problem could be, than actually solving the problem in code. Such is the way sometimes I guess but I certainly look forward to having mental models of code patterns in my mind to apply more readily.

Here’s the problem:
You have a website with 4 navigation links, 3 are text and 1 is a link under a company logo. The expectation is more links will be added in the future, they might be text or images. The test must check the known set of text links or linked images are present and if any new ones have been added. If new ones have been added, this should simply be reported and the known set tested anyway. The classes/methods for this must be reusable, to cover other sets of links across the website.

To do this I started splitting out the list of known links into a Dictionary

        public static IDictionary<stringstring> knownTextLinkAndURLList
            = new Dictionary<stringstring>
           {
                { "News","http://www.bbc.co.uk/news/" }
                { "Sport","http://www.bbc.co.uk/sport" }
            };


Then I created a method to loop over the links by looking for the link text

       public static void TopNavigationLinksCheck()
        {
            foreach (var navigationLink in knownTextLinkAndURLList.Key)
            {
                if (IsElementPresent(By.LinkText(navigationLink)))
                {
                    Console.WriteLine($"As expected, I saw: '{navigationLink}' link text");
                }
                else
                {
                    Console.WriteLine($"I could NOT locate the link: {navigationLink}");
                    TakeScreenshot.SaveScreenshot();
                    var pageNavigationElementException = $"I expected {navigationLink} but it was not located";
                    throw new Exception(pageNavigationElementException);
                }
            }
        }


Which used a reusable extension in the If statement I copied down from Stack Overflow:

        public static bool IsElementPresent(By by)
        {
            try
            {
                Driver.Instance.FindElement(by);
                return true;
            }
            catch (NoSuchElementException)
            {
                return false;
            }
        }

This seems fine for checking over text links, but we need to do that then check the actual link is correct. This is assuming we're concerned link text may be written incorrectly / against an agree style and that the link applied might vary, say news.bbc instead of bbc.co.uk/news for example.

Two things to investigate further then; 1) How to check both link text and link, 2) How to confirm there are no new links added (we can already check if any are removed or their links changed)

Day 6 here we come!

Mark.

(Be sure to have a look at the book - Deep Work)
-------------------------------------------------------------------------------------------------------------
Day 4: http://cyreath.blogspot.co.uk/2017/03/100-day-deep-work-day-4-configuration.html

Monday, 6 March 2017

100 Day Deep Work - Day 4: Configuration Files for Usernames and Passwords




Day 4 of the 100 Day Deep Work challenge actually happened on Friday, but as I don’t do IT stuff at the weekends here’s the posting today!

One thing I’ve been doing for simplicity sake is putting the various usernames and passwords used in tests into its own Class file. As I’m always working on test systems it didn’t seem to be an issue. However, the general convention is that these Usernames and Passwords should be protected to align with the security policy of the company you’re testing for.

That makes sense, after all you might have an Admin user who’s details make it into a live deployment. With tester tests integrated into the same place as unit tests and code, the risk is there. 

So, how to move those details out of the Class file and include them in the Configuration file?

Configuration Settings
In Visual Studio’s ‘Solution Explorer’ you’ll see your project has an app.config file, double click and open it. Inside the configuration elements we can add appSettings and include details of our username and password as a key/value pair.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="AdminUsername" value="testuser" />
    <add key="AdminPassword" value="Password1"/>
  </appSettings>
</configuration>

Naturally a lot more can be added here, such as system configuration details, but for now let’s stick with these two items.

Calling the appSettings items
To call the items from the app.Config file we need to add a call to our test like this:
        LoginCommand
            .LoginAs(ConfigurationManager.AppSettings["AdminUsername"])
            .WithPassword(ConfigurationManager.AppSettings["AdminPassword"]);

In practice however, I’m seeing the norm appears to be to call the AppSettings items via a separate file. I’m not 100% sure why at this point, but I’m assuming this is further abstraction. Moving anything that might change even further up to the page object level and out of the test. For example we might create a separate class to hold the user list for this test

    public class UserList
    {
        public const string TheUsername = "AdminUsername";
        public const string ThePassword = "AdminPassword";

    }

In which case we’d change our test to a more generic:

        LoginCommand
            .LoginAs(ConfigurationManager.AppSettings[UserList.TheUsername])
            .WithPassword(ConfigurationManager.AppSettings[UserList.ThePassword]);

Not a complete understanding but a good start - more tomorrow