How to set up Selenium on Visual Studio

August 2024 · 6 minute read

What is Visual Studio?

Visual Studio is an IDE developed by Microsoft. Its popularity comes from offering unique features such as cloud connectivity, supported extensions, easy debugging, collaboration, deployment, and version control integration, among others. Visual Studio is available for both Windows and Mac. It can be used for mobile, web, cloud, desktop applications, and gaming application development.

Visual Studio is available in both Free and Paid versions. The free version comes with basic features, whereas the paid version comes with enterprise features.

Note: Do not confuse Visual Studio with Visual Studio Code. Visual Studio is a complete IDE, and Visual Studio Code is an editor.

Table of Contents

Benefits of Visual Studio

Note: To integrate the BDD framework into Selenium tests, integrate with SpecFlow.

Setting up Selenium and Visual Studio

Selenium is the most popular end-to-end automation testing tool in existence. It supports the most popular programming languages – C#, Java, Python, JavaScript, and many more.

To set up Selenium C# with Visual Studio, just follow the steps below:

  • Install Visual Studio
  • Create NUnit Project
  • Add Selenium libraries
  • Install Visual Studio

    Step 1: Navigate to Visual Studio Download Webpage and download the installer.

    Note: The community edition is free. If someone has already paid for the license, they can install Visual Studio Professional or Enterprise Edition.

    Step 2: Start the installer and choose the desired option. For Selenium users, C# Test, the Asp.Net, and web development should be good enough.

    Install Visual Studio

    Step 3: Wait for the installation to finish. The program may ask the user to restart the system. 

    Step 4: After restart, choose the desired theme. After this, Visual Studio will begin its first time setup.

    Create New Project

    C#, Selenium, and NUnit comprise the most used combination for end-to-end automation tests.

    Step 1: Click on Create new Project.
    Create New Project in Visual Studio

    Note: On the Start Screen of Visual Studio, create a new project by navigating menu File > New > Project.

    Step 2: Click on Create NUnit Project, which emerges from the Create New Project pop-up.  Look for NUnit Project with .Net Core. Click on Next.

    Create NUnit Project

    Step 3: Configure your project. Specify project name, location, and solution name. Click Next to Continue.

    Configure your project on Visual Studio

    Step 4:  Choose the latest version of Target Framework. In this case, it’s .Net Core 5.0. Select that and click on Create.

    Select Target Framework

    The project setup is complete.

    Add Selenium Libraries and Drivers

    Having created the C# and NUnit Project, users need to add Selenium libraries and browser-specific drivers for End to End testing automation. 

    Step 1: Add Selenium Webdriver NuGget package.

    From the Visual Studio Tools menu, navigate to NuGet package manager and then click on Manage NuGet Packages for Solution.

    The NuGet Solution Window opens up.

    Step 2: Install Selenium Webdriver for the Project.

    In the Nuget Solution window, search for and choose Selenium Webdriver package. Click on Install

    Note: This NuGet Package may ask for license Acceptance. Read and Accept the License Agreement to proceed.

    Manage Selenium package in visual studio

    Step 3: Install Selenium Support Package.

    Like Step 2, search for Selenium Support and Install Selenium. Support Package for the project.

    Step 4: Create a new folder from inside the project. Name folder as “drivers.”

    Install Selenium Package in Visual Studio

     Step 5: Download the Selenium Browser-specific drivers. To execute Selenium end-to-end tests on the browser, download browser-specific drivers.

    Step 6: Copy the downloaded driver .exe file into the newly created drivers folder.

    Selenium C# Automation Best Practices

    Bear in mind that  Selenium WebDriver tests must be executed on real devices and browsers. Remember that device fragmentation is a significant concern for every developer and tester. Every website has to work seamlessly on multiple device-browser-OS combinations. With 9000+ distinct devices being used to access the internet globally, all software has to be optimized for different configurations, viewports, and screen resolutions.

    Run Selenium Tests for Free

    In this state, no emulator or simulator can replicate real user conditions. Software needs to be tested on real devices to work in real-world circumstances such as a low battery, incoming calls, weak network strength, and so on. If an in-house lab is not accessible, opt for a cloud-based testing option that offers real devices.

    BrowserStack’s cloud Selenium grid offers 3000+ real devices and browsers for automated testing. That means users can run tests on multiple real devices and browsers by simply signing up, logging in, and selecting the required combinations. Testers can also conduct Cypress testing on 30+ real browser versions across Windows and macOS. Detects bugs before users do by testing software in real user conditions with BrowserStack.

    ncG1vNJzZmivp6x7o77OsKqeqqOprqS3jZympmeXqralsY6snK2toGLAprjEp6CupV2ku27CyKysmqRdqMG2sMio