Getting Started

Introduction

In this series, we will set up an automation framework from scratch to test against the UI of a Windows software application.

The completed repository can be found at https://gitlab.com/testifyqa/CSharp-Windows-Coded-UI

We will use the following in our test framework:

  • SpecFlow
    • Use SpecFlow to define, manage and automatically execute human-readable acceptance tests in .NET projects. Writing easily understandable tests (in Gherkin language) is a cornerstone of the BDD paradigm and also helps build up a living documentation of your system.
  • CodedUI
    • Automated tests that drive your application through its user interface (UI) are known as coded UI tests (CUITs). These tests include functional testing of the UI controls. They let you verify that the whole application, including its user interface, is functioning correctly.
      • We will also create a custom plugin for SpecFlow to get it working with CodedUI

Setup / Installation

Setting up Visual Studio

  1. Download Visual Studio Enterprise from https://www.visualstudio.com/downloads/
    1. Enterprise edition is needed due to using the CodedUI feature, which is unfortunately not available in community / free editions
  2. Complete installation of Visual Studio Enterprise 2017 with the following components/packages installed…
    • MS Test Manager
    • CodedUI Tests
    • Unit Testing framework
    • Windows Form Development
    • .NET development
    • Windows 10 SDK
    • WindowsStore (if available)

Setting up ReSharper (optional)

ReSharper is a popular developer productivity extension for Microsoft Visual Studio. It automates most of what can be automated in your coding routines. It finds compiler errors, runtime errors, redundancies, and code smells right as you type, suggesting intelligent corrections for them.

  1. Download ReSharper from https://www.jetbrains.com/resharper/download/
    1. Sign up to a trial account if necessary
  2. Install ReSharper and customise your settings based on being used to Java and Automation (C# and Java are similar when using Selenium WebDriver API)
  3. Close down and restart Visual Studio

Creating an Automation Test Project in Visual Studio

  1. Launch Visual Studio
  2. Click ‘Create New Project’
  3. Select Visual C# → Test → CodedUI Test Project
    1. We will use this as our main test project, to create tests which execute against our UI Maps
  4. Name the CodedUI Test Project something suitable (e.g. ProductAutomation) and also name the Solution itself something appropriate
  5. Select ‘.NET Framework 4.5’ as the Framework
  6. Click ‘OK’
  7. Select ‘Cancel’ in the ‘Generate Code for Coded UI Test’ window that pops up
  8. Right-click on the root solution in the Solution Explorer and select ‘Add’ –> ‘New Project’ to add another 2nd project in the solution
  9. Select ‘Visual C#’ –> ‘Class Library (.NET Framework)’
    1. The ‘Class Library’ project is where we create our custom test generator, which is what will be used to get SpecFlow to work with our ‘CodedUI’ tests
  10. Name the ‘Class Library’ project “TechTalk.SpecFlow.CodedUI.MsTest” (without quotes) and again set the Framework to ‘.NET Framework 4.5’ and click OK.

Installing Visual Studio Extensions

  1. Click Tools –> Extensions and Updates
  2. In the Extensions and Updates window, click the ‘Online’ section
  3. Search for ‘SpecFlow’ and download ‘SpecFlow for Visual Studio 2017’
  4. Click Close and then close down Visual Studio to get the installer window to appear
  5. Click on ‘Modify’ to agree to the terms and then click ‘End Tasks’ (if necessary) to install the extensions
  6. Open Visual Studio and reload the Automation project

Installing NuGet Packages

  1. Go to ‘Tools’ –> ‘NuGet Package Manager’ –> ‘Manage NuGet Packages for Solution’
  2. In the window that opens, select the ‘Browse’ tab and make sure ‘All’ is selected in the ‘Package Source’ dropdown

SpecFlow Packages

SpecFlow.CustomPlugin

  1. Search for ‘SpecFlow.CustomPlugin’
  2. Select ‘SpecFlow.CustomPlugin’
  3. Check the checkbox for the project we want to install in, which should be only TechTalk.SpecFlow.CodedUi.MsTest (your ‘Class Library’ project) and install the latest version of ‘SpecFlow.CustomPlugin’ (this will automatically grab the dependency package of SpecFlow as well)
    • Accept any licenses and install the package

SpecFlow

  1. Search for ‘SpecFlow’
  2. Select ‘SpecFlow’
  3. Check the checkbox for the project we want to install it in, which should be only the CodedUI test project (e.g. ProductAutomation) and install the latest version of ‘SpecFlow’
    • Accept any licenses and install the package

 

 

Digiprove sealCopyright secured by Digiprove © 2018
Liked it? Take a second to support Thomas on Patreon!

Next Article

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.