Wednesday, 6 April 2016

Selenium Webdriver with C# - Cheat Sheet

Hey All,

I've been on a client site where we're using Visual Studio, Selenium WebDriver and C# for not only web front end but more system level automation testing.

As part of getting tooled up and informed as to how our favourite tools work with C# the team and I put together a Cheat Sheet to get us all started quickly. I thought I'd share that with you in a brief post.

Be warned, completing the below takes maybe an hour to get set up and then about 2 to 3 days full on to go through the material. If you’re working, with family, etc. expect a week with great focus.

One of the biggest challenges with adopting a new technology set is simply getting started. How often do we wish for a guiding hand to get us through the first baby steps and off building tests? Well, if you're a Test Architect like me, pretty much all the time! I hope the below helps.

1. Install Selenium IDE on Firefox
No really. As I've said before the IDE is great for doing web page node discovery and grabbing those names, IDs, CSS classes, etc. quickly and easily. This allows you to do a rough Proof of Concept script to prove the automation flow and then export the Selenease commands as C# in this case.

You'll then strip out of the code the elements you want and discard the rest. The alternative is you can right-click, Inspect element and read the code. Just use the IDE.

Get it from the Chrome store or here:

2. Get Visual Studio
In order to structure and build out your C# code you'll want to grab a copy of Visual Studio. There are many flavours and if your company is a Microsoft house go get IT or whomever to provide you a copy. Failing that or if you're suffering budget restrictions you can grab a free version.

The best I've found is Visual Studio Community Edition. Once installed you'll need to sign-in with a Microsoft email, part of the universal account / ID approach they now use.

Get Community Edition from here:

3. Learn C# Basics
If you're new to C# then you'll need to learn a little. There's a great resource over on the Microsoft Virtual Academy which you can take for free:

I've been told the link can sometimes say the course has expired. If you see that, just hit YouTube: 

4. Practice Selenium C#
If you want to jump straight in and not start mastering C# to get building out a framework at this point, then the site you want is this one:

Or possibly better still watch Learning Selenium Testing channel on YouTube:

5. Practice, Practice, Practice
Once you’re set-up and running with your first basic tests, be sure to practice practice and practice some more. Here’s some great sites to practice against:

If you need a book then get the only book out there that has pretty much all the answers you need in one place: Selenium Recipes by Zhimin Zhan

 Get the book

Good luck!