Header Ads

Getting Started with Selenium using C# .Net and Visual Studio 2019

Visual Studio 2019

Introduction

Automating a web application is on your mind and you are looking for open source test automation library, selenium can be your top contender. Being easy to adapt to multiple programming languages like C#, Java, Python to name a few and supports multiple browsers. Today we will look at steps to follow getting started with Selenium using C# .Net.

Installing Visual Studio 2019:

  1. Visit here and download and install Visual Studio.
  2. Select the option '.Net Desktop Development' and 'Universal Windows Platform Development' while installation.
  3. Complete the installation

Installing Selenium WebDriver:


In Visual Studio, Create a New Project (NUnit Test Project)

VS 2019

VS 2019

NUnit project will be created

VS 2019

Using NuGet package manager one can easily install selenium packages



Download the latest NuGet package for selenium from here



That's it !! Installation is done !!




Configuring WebDriver:

Download and Install the Chrome browser if not already installed.Check the version of installed browser and download ChromeDriver of same version from here.


Copy chromedriver.exe to bin folder.

Instead of copying chromedriver.exe to bin folder one can update the system PATH environmental variable with path of chromedriver.exe.

.


First Selenium with C# example


Rename the default class UnitTest1 to UITests and include the code given below:



Executing the Tests


In visual studio, open the test explorer and execute the tests directly from visual studio.


The example demonstrated here is using NUnit test framework. There are other test frameworks like MSTest and BDD (Behavior Driven Development) frameworks like SpecFlow that can also be configured to execute selenium tests.

Advantages of using Selenium with C#:
  • Using C# for automation will increase productivity of tests development and maintenance with state of the art tool Visual Studio 2019, having features such as AI assisted IntelliCode, better search capabilities and good debugger.
  • C# is object oriented programming language is strongly typed and provides the feature Reflection with which we can play with type information at run time, supports LINQ and programmers does not have to lower level details like memory management and garbage collection.
  • Using selenium with C# greatly beneficial when your application under test is developed using .Net framework and where the whole ecosystem is of Microsoft Technologies which will have effect on quality and productivity of tests development and thereby improving quality of application under test.

 

No comments

automationglance.com. Powered by Blogger.