Selenium MSTest Tutorial: Setup Selenium WebDriver For MSTest Framework In C#
Tags: selenium, beginners, tutorial, opensource
Published: 2023-12-28 06:32:43

In the on-going ‘Selenium MSTest testing tutorial’ series, we earlier had a look at setting up the MSTest framework in Visual Studio. It was a getting started guide with a major focus on the installation of the Selenium MSTest framework and MSTest adapter for the project. In case you are starting up with the MSTest framework, we recommend that you check out the installation guide on [MSTest Tutorial: Environment Setup For Selenium Testing](https://www.lambdatest.com/blog/mstest-tutorial-environment-setup-for-selenium-testing/?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=blog).

In this Selenium MSTest testing tutorial, we take a look at setting up [Selenium WebDriver](https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=blog) with Visual Studio in C#. Before we install the Selenium WebDriver, we create a new project in C#.

Starting your journey with Selenium WebDriver? Check out this step-by-step guide to perform Automation testing using Selenium [WebDriver Tutorial](https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=learning_hub).
>  **Need to convert hex to decimal? Our online [Hex to Decimal](https://www.lambdatest.com/free-online-tools/hex-to-decimal?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=free_online_tools) Converter tool converts hexadecimal to decimal numbers quickly. Get your conversions done in no time. **

## Creating a New Project in C#

Before installing Selenium WebDriver, we create a new project in C# by following the below-mentioned steps:

* 1. Open Visual Studio and create a new project of the type ‘MSTest Test Project (.Net Core).’



![](https://cdn-images-1.medium.com/max/2000/0*3qtVNmZ3n4qBqPLi.png)

* As the created project is of type MSTest Test Project (.Net Core), the default C# class comes along with the attributes [TestMethod] and [TestClass] in it.

![](https://cdn-images-1.medium.com/max/2048/0*c9nJcFLT1ZEsf4Kx.png)

## Steps to Download Selenium WebDriver

Before running your [first script in MSTest](https://www.lambdatest.com/blog/mstest-tutorial-running-first-selenium-automation-script/?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=blog), you need to download and set up Selenium WebDriver.

Selenium WebDriver on Visual Studio can be installed using NuGet, a free and open-source package manager that is specifically designed for the Microsoft Platform.
There are two options for installing Selenium WebDriver — using the Visual Studio IDE and using the NuGet Package Manager (PM) Commands.

## Using Visual Studio IDE

For installing Selenium WebDriver using the VS IDE, please perform the following steps:

* Navigate to Tools -> NuGet Package Manager -> Manager NuGet Packages for Solution and search for ‘Selenium.’

![](https://cdn-images-1.medium.com/max/2048/0*9CqViVRBBu4mAc_s.png)

* Select Selenium.WebDriver from the search list and click on the Install button.

![](https://cdn-images-1.medium.com/max/2048/0*TW1m0Na5tpKsQRLb.png)



![](https://cdn-images-1.medium.com/max/2000/0*cQeF2rukJDBBtEqP.png)

* For [automated browser testing](https://www.lambdatest.com/?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=webpage), we make use of the Chrome web browser. Hence, we install the Selenium Chrome Driver. Select Selenium.WebDriver.ChromeDriver from the search list and click on the Install button.

![](https://cdn-images-1.medium.com/max/2048/0*D_89dO2CQNp1upuY.png)

* Now that the Selenium WebDriver installation is complete, you can use the package in the source code. Including the following statements in the source code to verify whether the Selenium WebDriver is installed or not.

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
     
    namespace MSTest_Test_Project
    {
        [TestClass]
        public class UnitTest1
        {
            [TestMethod]
            public void TestMethod1()
            {
            }
        }
    }
>  **Simplify your work with our [Decimal to BCD](https://www.lambdatest.com/free-online-tools/decimal-to-bcd?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=free_online_tools) Converter. Accurately convert decimal numbers to binary-coded decimal values quickly and easily! Try it now and simplify your work!**

## Using Package Manager (PM) Commands

If you are more comfortable with the command-line terminal, Selenium WebDriver can also be installed by executing the relevant commands on the Package Manager (PM) console.

* In order to execute commands from the PM console, navigate to Tools -> NuGet Package Manager -> Package Manager Console.

![](https://cdn-images-1.medium.com/max/2048/0*r5xbHNu4gOZQJwBm.png)

* The following commands have to be executed on the Package Manager (PM) console:

    Install-Package Selenium.WebDriver

* As the Chrome browser is used for testing, we install the Selenium Chrome Driver as we did in the earlier case.

    Install-Package Selenium.Chrome.WebDriver

Shown below is the snapshot of the Package Manager Console:

![](https://cdn-images-1.medium.com/max/2000/0*Hm3MfUbTK8-3lIR1.png)

![](https://cdn-images-1.medium.com/max/2000/0*ziQPkZwG4MrxgUN4.png)

To verify whether the necessary packages are installed, execute the Get-Package command on the PM console.

    PM> Get-Package
     
    Id                                  Versions
    --                                  --------                                          
    Selenium.WebDriver                  {3.141.0}
    Selenium.Chrome.WebDriver           {79.0.0}
    ...... ......
    ...... ......

This MSTest Tutorial for beginners and professionals will help you learn how to use MSTest framework with Selenium C# for performing Selenium automation testing.
{% youtube 2XUQdN-Bi2o  %}

>  **Need to encode your text into UTF-8 format? Use our [UTF-8 Encode](https://www.lambdatest.com/free-online-tools/utf8-encode?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=free_online_tools) tool to encode your text for seamless communication across all platforms and devices. Try it for free today.**

## Conclusion

![](https://cdn-images-1.medium.com/max/2000/0*YLQoBC80fgIvUyPZ.gif)

With this Selenium MSTest setup example, we had a look at setting up [Selenium WebDriver](https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=blog) for automated testing with MSTest and C#. The steps mentioned in this [Selenium C# tutorial](https://www.lambdatest.com/learning-hub/selenium-c-sharp-tutorial?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=learning_hub) are essential to get started with automation testing with Selenium and C#. With the completion of the Selenium MSTest framework & Selenium installation, you are all set to perform [cross browser testing](https://www.lambdatest.com/?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=webpage) or [automated browser testing with MSTest](https://www.lambdatest.com/selenium-automation-testing-with-MSTest?utm_source=devto&utm_medium=organic&utm_campaign=dec_28&utm_term=bh&utm_content=webpage), Selenium, and C# ☺.

### Frequently Asked Questions

### What is SpecFlow Selenium?

SpecFlow is a BDD tool that helps automate acceptance tests, exploit the full power of .NET, and help improve your development process. It’s an interactive testing framework for .NET and C

### Which is better: NUnit or MSTest?

MsTest is similar to NUnit which is another unit testing framework with a focus on simplicity. The difference between the two lies in how they execute tests. In MSTest, tests are executed in parallel whereas in NUnit the test runner will wait for all tests to finish before moving on to the next test. This causes a delay when executing more than one test. Hence, MSTest offers advantages in speed and robustness when compared to NUnit.