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.
You will need the following components to create and run WebDriver tests using C#.
- Visual Studio
- C# Bindings for WebDriver
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.
- 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.
2. Here, we will be creating a simple Class Library project. Go to File->New->Project.
3. While the project templates are built, you will see a template selection dialog.
4. Select C# class library, enter the project name and click OK. This will add one class file to the project.
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…’.
6. Search for WebDriver from the Browser tab and install the required WebDriver package.
7. Search for NUnit and add the required 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.