Getting Started

Introduction

In this series, we will setup an automation framework from scratch to test against REST APIs.

The completed repository can be found at https://gitlab.com/testifyqa/CSharp-RestSharp-Api-Testing

We will use the following in our framework:

  • RestSharp
    • RestSharp is a comprehensive, open-source HTTP client library that works with all kinds of DotNet technologies. It can be used to build robust applications by making it easy to interface with public APIs and quickly access data without the complexity of dealing with raw HTTP requests. We will use the RestSharp library in our RESTful API testing
  • 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.
  • SpecFlow.NUnit
    • A combined package to get SpecFlow setup and working with NUnit

NOTE: If you have followed and completed the blog series on C# Web Automation, then all you need to do is add the NuGet package for the latest version of RestSharp and the rest of this blog post can be skipped…

Setup / Installation

Setting up Visual Studio

  1. Download Visual Studio from https://www.visualstudio.com/downloads/
  2. Complete installation of Visual Studio on your Windows machine

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 File → New → Project
  3. Select Visual C# → Console Application (.NET Framework) – we can use the console app to leave messages about our tests and help us debug
  4. Name the Console App project something suitable (e.g. ProductAutomation) and also name the Solution itself something appropriate
  5. Set the ‘.NET Framework’ version to something which is supported by RestSharp, e.g. v4.5.2

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. Next, search for ‘NUnit’ and download ‘NUnit 3 Test Adapter’
  5. Next search for ‘Productivity Power Tools’ and download ‘Productivity Power Tools 2017’
  6. Click Close and then close down Visual Studio to get the installer window to appear
  7. Click on ‘Modify’ to agree to the terms and then click ‘End Tasks’ (if necessary) to install the extensions
  8. Open Visual Studio and reload the Automation project

Installing NuGet Packages

  1. In the Solution Explorer, right-click on ‘References’ and click on ‘Manage NuGet Packages…’
  2. In the window that opens, select the ‘Browse’ tab…

NUnit Packages

NUnit Test Adapter

  1. Search for ‘NUnit’
  2. Select ‘NUnit3TestAdapter’ and install the latest version of the package

SpecFlow Packages

SpecFlow

  1. Search for ‘SpecFlow’
  2. Select ‘SpecFlow’ and install the latest version of the package

SpecFlow Assist Dynamic

  1. Search for ‘SpecFlow Assist Dynamic’
  2. Select ‘SpecFlow.Assist.Dynamic’ and install the latest version of the package

SpecFlow.NUnit

  1. Search for ‘SpecFlow.NUnit’
  2. Select ‘SpecFlow.NUnit’ and install the latest version of the package

RestSharp Packages

  1. Search for ‘RestSharp’
  2. Select ‘RestSharp’ and install the latest version of the package
Digiprove sealCopyright secured by Digiprove © 2018
Liked it? Take a second to support Thomas on Patreon!

Next Article

One Reply to “Part 1. Getting Started”

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.