Visual Studio is a product of Microsoft with the Integrated Development Environment (IDE). It uses Microsoft’s software development platforms like Windows API, Forms, etc. to develop web apps, web sites, and other computer programs.

You can go through “How to use WebDriver in Python on OSx” to see how WebDriver work in various editors and language platforms.

Components

You will need the following components to create and run WebDriver tests using C#.

  • Framework
  • Visual Studio
  • C# Bindings for WebDriver
Visual Studio

Visual Studio is available in various versions, including commercial and the community version available for students and individuals. Many versions follow the same approach while using it. However, you can either get it from the homepage or get it as a Microsoft Developer Network Package.

Project Creation
  1. Once the Visual Studio has been installed, you can create the project and start working on it. However, there could be many ways of building a test project. For example, you can use the following approach.
                                                                                             Creating the Project

2. Here, we will be creating a simple Class Library project. Go to File->New->Project.

                                                                  Creating a Simple Class

3. While the project templates are built, you will see a template selection dialog.

                                                                              Template Selection Dialog

4. Select C# class library, enter the project name and click OK. This will add one class file to the project.

                                        Adding C# Class Library

5. Add WebDriver and NUnit to the project using the NuGet tool, which automatically adds WebDriver from central repositories. This can be done by right clicking the project and clicking ‘Manage NuGet Packages…’.

                               Adding WebDriver and NUnit

6. Search for WebDriver from the Browser tab and install the required WebDriver package.

                                 Installing WebDriver Package

7. Search for NUnit and add the required framework and Adapter.

                              Adding Framework and Adapter

8. Add the appropriate Firefox driver proxy from the Mozilla’s Gecko Driver releases. Here, you need to add the location of the driver where it is downloaded to the PATH environment variable of your system. Thereafter, re-start Visual Studio.

Writing and Running a Simple Test

You will need a test framework like NUnit to write the test cases. You can either use the earlier added class or add another complete class.

To run the test, you need to open Test Explorer by clicking Tests->Windows->Test Explorer. Select ‘Run All’ to execute the tests.

Leave a comment

Your email address will not be published. Required fields are marked *