Selenium C# Tutorial: Deployment and configuration using Visual Studio
Updated: Mar 5
Selenium WebDriver supports the main coding languages such as Payton, java, and c#, in this book I will use C#, but you can use whatever coding language you preferred.
Before writing any code, we need to prepare the work environment, in our case, we will use Microsoft "visual studio" platform that allows us to create and run the code examples throughout this book.
A free version of this platform is available at this address:
Deployment of Selenium WebDriver V4.01 using Nugget
After that, you downloaded Visual studio we can start creating our project:
1. Open visual studio.
2. Create a new project.
3. Select the template “Nunit Test Project (.NET Core)”.
4. In the search box, locate “NUnit” and select “Nunit Test Project (.NET Core)” and click “Next”.
5. Provide the project name and press “Create”.
6. Add test explorer for easy management of test execution(Ctrl +E, T).
7. In the “Solution Explorer” -> Right Click on “Packages” -> select “Manage NuGet Packages …”
8. In the search window -> Write “Selenium” and select the “Selenium WebDriver” NuGet -> Press “Install”.
9. Validate NuGet is installed:
Deployment of Selenium WebDriver V2.53 using binding files
To use the WebDriver framework, we need to select the relevant files per the coding language that we choose, in our case; we will download the C# binding files.
You can find these files at http://www.seleniumhq.org/download/
Step 1: Extract the WebDriver ZIP file
Now that you downloaded the WebDriver binding files, you will see that the download contains a single ZIP file, before we can use this content we first need to extract it into a dedicated folder.
Zip File: selenium-Dotnet-2.45.0.zip
Dedicated Folder Name: you can use any name that you like (for this post I called it “Selenium WebDriver – C# Files”).
Step 2: Create a Visual Studio project
Now we need to create a new Visual Studio project, this project is going to host the selenium setup files in step 3, to create this project please follow these basic steps:
1. Open the Visual Studio application.
2. Press “File” - > New -> Select a new “Project” (Another option is to use the shortcut combination “Ctr l+ Shift+ N”).
3. At the new project window, select the “Test” option located under the “Visual C#”, and then select the “Unit Test Project” (See Image below).
Step 3: Add the Selenium Driver to our new project
Now, we need to add the selenium Web Driver DLL’s to our newly created project, to accomplish this task, please follow these basic steps:
1. On the new project that we created in the previous step.
2. Add a new reference to the Selenium WebDriver DLL’s.
3. On the Solution Explorer -> locate the project Name -> Right Click ->Add-> "Reference"
4. In the reference manager, navigate to the selenium WebDriver setup files.
5. Click “Browse” -> Locate the Predefined folder that we created “C:\Selenium WebDriver – C# Files\net40” -> Mark All files (Four Files should be selected) - > Press “Add” - > Press “OK”
6. Add the relevant Selenium namespace