Getting Started

Introduction

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

The completed repository can be found at https://gitlab.com/testifyqa/CSharp-Selenium-Web

We will use the following in our test framework:

  • Selenium WebDriver
    • Selenium is a portable software-testing framework for web applications. Selenium provides a playback (formerly also recording) tool for authoring tests without the need to learn a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including C#, Groovy, Java, Perl, PHP, Python, Ruby and Scala. The tests can then run against most modern web browsers. Selenium deploys on Windows, Linux, and macOS platforms. It is open-source software, released under the Apache 2.0 license: web developers can download and use it without charge.
      • We will set up WebDrivers for automation in Google Chrome and Mozilla Firefox
  • 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.
  • NUnit
    • NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit, the current production release, version 3, has been completely rewritten with many new features and support for a wide range of .NET platforms.

Setup / Installation

Setting up Visual Studio Code

  1. Download Visual Studio Code for your Operating System from https://code.visualstudio.com/download
  2. Complete installation of Visual Studio Code on your machine

Add the C# Extension to Visual Studio Code

  1. Launch Visual Studio Code on your machine
  2. Click the Extensions icon (the 4 squares with one square being slightly separated)
  3. Search for ‘C#’ and click the green ‘Install’ button

Enable ability to launch Visual Studio Code from the command line

  1. Make sure Visual Studio Code is launched
  2. Open the command palette (CMD/Ctrl + SHIFT + P)
    1. Type in ‘shell’
    2. Select the option “Shell command: Install ‘code’ command in PATH”

You can now launch Visual Studio Code from the directory you are in from Terminal / CMD by entering the following command…

Installing .NET Core SDK

.NET Core SDK is a set of libraries and tools that allow developers to create . NET Core applications and libraries. We require it to create our test automation framework in C#

  1. Download the .NET Core SDK Installer for your Operating System from https://dotnet.microsoft.com/download/dotnet-core/3.1
  2. Launch the installer once downloaded and follow any instructions to install it
  3. Verify DotNet installed successfully by opening a CMD / Terminal window and entering the following command…

Creating an Automation Test Project in Visual Studio Code

  1. Open up a Terminal window
  2. change directory in to a suitable folder (e.g. Documents)…
  3. Make a new directory for your project and then change directory in to it…

  4. Launch Visual Studio Code from the command line in the current project directory…
  5. Click ‘Terminal’ -> ‘New Terminal’ to display the Terminal window integrated within Visual Studio Code
  6. Enter the following command to add a new NUnit project…
  7. Next, let’s add our Solution file (again, name it something suitable) by entering the following command in the integrated terminal again…
  8. Finally, let’s add our NUnit project to our solution…

Installing Visual Studio Code Extensions

  1. With Visual Studio Code open, click the Extensions icon
  2. Search for ‘SpecFlow’ and click ‘Install’ on “Specflow Tools”
  3. Next, search for ‘Power Tools’ and click the green ‘Install’ button
  4. Next, search for ‘Cucumber’ and install ‘Cucumber (Gherkin) Full Support’
  5. Next, search for ‘.NET Core test Explorer’ and click the green ‘Install’ button

Installing NuGet Packages

  1. In the Terminal window integrated within Visual Studio Code, enter the following commands for each package to install it successfully…

NUnit Packages

NUnit Test Adapter

Selenium Packages

Chrome WebDriver

Firefox WebDriver

Selenium Support

Selenium WebDriver

SpecFlow Packages

SpecFlow

SpecFlow Assist Dynamic

SpecFlow.NUnit

SpecFlow.Tools.MsBuild.Generation

Building the Framework

  1. In the Terminal window integrated within Visual Studio Code, enter the following command to build the project and all of its dependencies…
  2. Once the build has run successfully, go in to one of the generated .cs files (e.g. Program.cs) and click in to a line of code
    1. You should get a prompt to add required assets that are missing for C#…
    2. Click ‘Yes’ and it will add some necessary asset files and folders (e.g. ‘.vscode’ folder)
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.