DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • How To Introduce a New API Quickly Using Quarkus and ChatGPT
  • Vision AI on Apple Silicon: A Practical Guide to MLX-VLM
  • Feature Flag Framework in Salesforce Using LaunchDarkly
  • Why GenAI Apps Could Fail Without Agentic Frameworks

Trending

  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  • Designing a Java Connector for Software Integrations
  • Mastering Advanced Aggregations in Spark SQL
  • Is Agile Right for Every Project? When To Use It and When To Avoid It
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Setting Up Selenium WebDriver for MSTest Framework in C#

Setting Up Selenium WebDriver for MSTest Framework in C#

This MSTest testing tutorial covers different ways of installing Selenium WebDriver for the MSTest framework in C#.

By 
Himanshu Sheth user avatar
Himanshu Sheth
DZone Core CORE ·
Jan. 23, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
2.8K Views

Join the DZone community and get the full member experience.

Join For Free

In the ongoing "Selenium MSTest testing tutorial" series, we had an earlier 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 this Selenium MSTest testing tutorial, we take a look at setting up Selenium WebDriver with Visual Studio in C#. Before we install the Selenium WebDriver, we create a new project in C#.

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).’
  • 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.

Steps to Download Selenium WebDriver

Before running your first script in MSTest, 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.’Manage NuGet Packages
  • Select Selenium.WebDriver from the search list and click on the Install button.Select Selenium WebDriverLicense Acceptance Package
  • For automated browser testing, 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.Chromedriver install
  • 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.
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
 
namespace MSTest_Test_Project
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
        }
    }
}

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.Package Manager Console Photo
  • 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: 

Install Package Selenium

Package Manager Console

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

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

Conclusion

With this Selenium MSTest setup example, we had a look at setting up Selenium WebDriver for automated testing with MSTest and C#. The steps mentioned in this Selenium C# tutorial 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 or automated browser testing with MSTest, Selenium, and C#.

csharp Package manager Framework

Published at DZone with permission of Himanshu Sheth. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Introduce a New API Quickly Using Quarkus and ChatGPT
  • Vision AI on Apple Silicon: A Practical Guide to MLX-VLM
  • Feature Flag Framework in Salesforce Using LaunchDarkly
  • Why GenAI Apps Could Fail Without Agentic Frameworks

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!