UI Automation With C# and Selenium: Adding Packages

The Takeaway: Installing the right packages from the start makes everything else a lost easier.

So far, we’ve created a blank solution with a few projects and added that solution to a repository. Now we need to install the right packages so that when we start coding some tests, everything will be in place and we won’t need to go back and figure out what we’re missing. For our automation, we’ll start out with the following packages:

  • Selenium
  • NUnit
  1. In your automation solution (which you can find the previous post for here), Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution

    Visual Studio - Manage NuGet Packages
    Visual Studio – Manage NuGet Packages
  2. Select the Browse option and search for Selenium 

    Visual Studio - Selenium NuGet Packages
    Visual Studio – Selenium NuGet Packages
  3. For each package Selenium. WebDriver and Selenium.Support, select the package. Notice that the project where our tests live is the only option available installing this package. Remember, since the framework is a Shared Project, there’s no DLL file created for that project, but the files required for the tests will be automatically included when the test project is built 

    Visual Studio - Packages Install in the Test Project
    Visual Studio – Packages Install in the Test Project
  4. Select the Test project (UI Tests in the example above) and select the Install Button 

    Visual Studio - Installing Packages
    Visual Studio – Installing Packages
  5. You’ll probably need to confirm the install of each package as well 

    Visual Studio - Review Package Install
    Visual Studio – Review Package Install
  6. After both the Selenium.WebDriver and Selenium.Support packages are installed, search for and install the NUnit and NUnit .Console packages as well 
    Visual Studio - Installing Nunit Packages
    Visual Studio – Installing NUnit Packages

    Once the NUnit packages are installed, you can select the Installed link and see that several NUnitpackagaes were installed. These packages will be the basis for our framework and tests, but we’ll add more as we progress.

UI Automation With C# and Selenium: Visual Studio Project Types

The Takeaway: Using shared projects with class libraries is a good way to start your Visual Studio automation project.

Setting Up Your Visual Studio Project

One of the initial things you need to decide when you start an automation project is what the structure of your Visual Studio Solution will be. I have worked with several different scenarios, involving various types of projects:

Class Library:

Default project type

Results in the compilation of a DLL (Dynamic Linked Library) that can be ran by Nunit

NUnit Unit Test Project:

Available through the NUnit VS Templates Extension in Visual Studio

Provides code snippets that make getting up and running with NUnit a bit quicker

NUnit VS Templates
NUnit VS Templates

Unit Test Project:

Similar to the NUint VS Templates project template, the Unit Test project template creates a class file with a basic frame of a unit test already built in (including a using statement for the Microsoft.VisualStudio.TestTools.UnitTesting package and properties for a class and method to mark them as a test class and test method). 

I’m sure there are others that are and have been used as well. BUT, one of my favorite project types for testing has become the Shared Project.

Shared Projects:

What I love about Shared Projects is that any code in that project, referenced by other projects, is automatically added to and complies with the other project. So, you can have multiple types of test projects in your solution (one for UI testing, one for API testing, one for database testing, one for security testing), and one single repository for your framework. When you compile the code for that project, the shared code that applies to that project.

How Shared Projects Share Code
Shared Projects

Starting Your Automation Solution

  1. Open up Visual Studio. I will use Visual Studio 2015, but these examples should all work in Visual Studio 2017 just as easily
  2. Navigate to File > New > Project
  3. In the New Project window, select the Templates TreeView > Other Project Types
  4. There should be a Blank Solution template available to you. Select that in the Window, give your solution a name (I’m calling mine Automation), ensure that the Create directory for solution checkbox is checked, and click the OK Button:

    Visual Studio Automation Project - Blank Solution
    Visual Studio Automation Project – Blank Solution
  5. Now, you should have a blank solution with nothing in itNow, we need to add at least two projects to this solution: one Shared Project, and one 
  6. Navigate to File > New > Project
  7. Select the Templates TreeView > Visual C#
  8. Select Shared Project, name it Framework, select Add to solution, make sure you’re in the same location as your blank solution, make sure the Create Directory for solution checkbox is selected, and select the OK Button

    Visual Studio Automation Project - Shared Project

      Visual Studio Automation Project – Shared Project

    Now, you should have a solution with an empty shared project. Time to add the test library:

  9. Navigate to File > New > Project
  10. Select the Templates TreeView > Visual C#
  11. Select Class Library, name it Framework, select Add to solution, make sure you’re in the same location as your blank solution, make sure the Create Directory for solution checkbox is selected, and select the OK Button
Visual Studio Automation Project - Class Library
Visual Studio Automation Project – Class Library

So, you should wind up with a solution with two project templates: a Shared Project for your framework, and a Class Library for your tests. This is the base off of which we will build our automation and framework. Using a Shared Project, we can add whatever we need into the framework portion of our solution, then simply use the necessary components when we build and deploy our tests.

Visual Studio Automation Project - Complete
Visual Studio Automation Project – Complete

A Zip file of this project is available here

Software Automation and the Modern Web: The Web As a Platform

The Takeaway: The modern Web is a platform for user connections, and automation can play an important role in ensuring platform integrity.

The advent of Web 2.0 has altered the way users interact with enterprise-level software and the way enterprises incorporate software into their business.

Tim O’Reilly’s definitional article (2005) describes the shift that started around that time and points to a number of factors that have led to the proliferation of Web applications for business use.

The Web as a Platform

The World Wide Web has become its own platform, upon which developers are developing next-generation Web applications and rich Internet applications. The evolution of the Web as a platform allows developers to think about applications as browser-based services, independent of user operating systems. Some even argue that the Internet browser is becoming the next operating system, capable of delivering applications and extending architectural capabilities in much the same way traditional, desktop operating systems have worked for many years (Wayner, 2013; Garaizar, P., Vadillo, M. A., López-de-Ipiña, D., & Matute, H., 2012).

The success of Google’s Chrome OS points to the
successes companies are seeing with implementing
Internet-as-Platform concepts.

Using the Web as a platform, instead of a specific operating system or specific browser, frees developers from the constraints imposed by utilizing operating systems and browsers, allowing the large amounts of interoperability organizations require from their Web applications. Thinking of the Web as a platform also highlights the network effects possible with Web applications, where the value that the Web application provides the organization using it increases as the number of individuals using the application increases.

What This Means for Automation

Automation plays a valuable role in the Web as a Platform in several ways:

  • The World Wide Web allows us to start abstracting applications from traditional operating systems, but the implementation of the same browser in various operating systems still means there is a need to test those implementations in order to minimize risk. That’s where Sauce Labs, BrowserStack, and the Selenium Grid come into play.

We, as automation engineers, need to understand that, for the web applications we automate, a core strength is an application’s flexibility and “lack of control”.  Once a vendor attempts to control both ends of communication, you lose the primary value of the Web. There are ways to mitigate risk, whether it’s by only supporting particular browsers and not using resources to troubleshoot user issues on other browsers, or by testing your application on multiple browsers/versions/operating systems to make sure your application performs as well as it can on a wide variety of end-user machines. Thankfully, we are also able to mitigate risk with responsive websites that can display information in different ways depending on the browser and the end-user device. Decisions made

Decisions made at the beginning of any software project about browser/device compatibility impact automation effort scope and automation engineers should be in on these conversations from the start.

  • A key tenant of Web 2.0 is that the service improves as the number of users increase. The WWW’s focus is on connections, clients, hosts, and, most importantly, the information that flows between through these connections and between these end-points. Automation’s ability to precisely execute a set of inputs, and then compare the actual outputs with expected outputs helps ensure that all possible execution paths of an information system meet user expectations.

Automation’s Place in the Value Chain

The Takeaway: Automation adds value to your DevOps/SDLC process and can be a large part of your project’s success in the marketplace.

I feel that management theory is not only necessary for understanding a individual’s place on a team, a team’s place in an organization, and an organization’s place in the market. Not only that, but I like reading and talking management theory.

While I do recommend Michael Porter’s Competitive Strategy and Competitive Advantage to anyone wanting to know how to better understand how businesses compete in the market or how their business affects and is affected by internal and external forces, I also understand these books are a bit hard to read through with understanding.

Value Chain

“…strategically relevant activities [disaggregated] in order to understand the behavior of costs and the existing and potential sources of differentiation.”  (Porter, Competitive Advantage, p. 33). 

The way you stay in business is by doing things either cheaper and/or better than its competition. Once you separate and examine each individual activity in your collection of activities performed to design, produce, market, deliver, and support the thing you make, you start to gain an understanding of where the resources go. Where do we spend time that we can cut out? Where do we spending money that makes our product better than our competitors’? This is the (basic) idea behind the aglie manifesto, right? Cut out the things that cost time and money unnecessarily

  • processes and tools
  • comprehensive documentation
  • over contract negotiation
  • following a plan,

and focus on the valuable things

  • individuals and interactions
  • working software
  • customer collaboration
  • responding to change.

Focus resources on the things that matter, and you’re a step ahead of competitors that don’t.

Michael Porter's Value Chain
Michael Porter’s Value Chain

Value Activities + Margin = Value Chain

The total Value Chain is comprised of Value Activities and Margin:

Value Activities

“…physically and technologically distinct activities a firm performs… building blocks by which a firm creates a product valuable to its buyers…” (Porter, Competitive Advantage, p. 38).

There are Primary and Secondary (Support) activities. We’ll focus on support just to keep things simple.

The typical primary value activities do not apply across all industries equally. Manufacturing, for example, relies much more heavily on inbound and outbound logistics than software development, for example. For our purposes, I’ll rely on a classical approach to software value chains provided by Boehm and Papaccio (1987, NTRS), and state that the majority of software development falls under the Operations and Service value activities. 

Operations: Transforming inputs into the final product form (requirements into an application)

Service: Providing service to enhance and maintain the product’s value


“…the difference between total value and collective cost of performing the value activities…”(Porter, Competitive Advantage, p. 38). 

Margin depends upon the efforts placed in the value chain that add value to a product over and above the costs incurred in the value activities. 

What Automation has to Do With The Value Chain

The good news for automation engineers, is that automation can be a crucial part of the value chain. For any task that can be automated effectively, the cost of that activity decreases significantly. For testing, as an example, instead of using three resources for a week to regression test your application, you can do it overnight, and view the results the next morning. Certainly, there are resources required to develop and maintain the regression testing suite, where the value obtained form those efforts starts small, but will increase over time. However, proper planning and execution can help ensure that value is delivered as quick as possible.

Additionally, automation is helpful in the detection, reporting, and verification of defects. A system defect drives down the “worthwhile-ness” of any product. Good automation efforts discover defects before your customers do, and can, if executed correctly, discover them before manual testing efforts. 

The important thing is to start thinking of any repeated task as something that can be automated. Not every repeatable task should be automated, so discernment is required in order to ensure that the right things are automated. But, progression of automation efforts has been shown to increase the value of the activities you perform in your software development life cycle.

As we continue this series, we’ll delve further into aspects of automation that help deliver value over its costs, how you can implement automation to achieve these goals, and what to look for in order to be successful with software automation.

UI Automation With C# and Selenium, Part I

For the past few years, I’ve struggled with a desire to publish a “how-to” series
on automation. On one hand, there are already LOTS of resources out there, frankly, written by people much better at development and programming than


I am. Dave Haeffner, for example, does a great job of explaining how to get started in his Selenium Guidebook. And now that it’s available in multiple languages (Java, Ruby, C#, Python, JavaScript), that’s an awesome resource for anyone looking to get started in UI and browser automation.

However, as I’ve grown as an automation engineer, especially in the past year, I still find it hard to find resources that do a great job of explaining how to expand your automation palette, moving beyond the


basic ideas of UI automation, and including:

  • Data-Driven Automation and Testing
  • Keyword-Driven Automation and Testing
  • API Automation and Testing
  • Security Testing

Furthermore, finding resources that speak to the implementation of these ideas in a C#/.NET environment is even more difficult. 

So, the idea is to show some real-life examples of how to implement an automation solution for testing websites and browser-based applications.

Check out my webiste to get an idea of the tools I use in my own automation.


Some of the ideas I share are ones that I implement in my own work, some may not be. Some may be ones that I figure out while I’m writing these articles and implement because of them.

If you have ANY questions or want to discuss anything, please feel free to comment or e-mail me.