In this article, I will cover the basic implementation and configurations of “Selenium WebDriver” (You can read more about this component on this link).
There are few basic things that you need to prepare before we can start and dive into the implementation process, the first thing that you need is the coding platform, in our case we will use “Microsoft Visual Studio”, in my case I use the 2013 version.
A free version of this platform is available at this address:
Selenium WebDriver for C#
Ok, we got the platform that we can use to configure and run our tests, but wait… where is the application that we need to implement..?
Well, 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/
In this tutorial, I will use the “Firefox” browser, this browser contains the Selenium drivers by default, if you want to use any other browser, and you must download a dedicated driver.
Let’s assume that you want to run your tests on a Goggle “Chrome” browser, in that case, you will need to download a dedicated driver from this link (Select the latest release date J).
The implementation phase
Now, that you have the Host application (Visual Studio) and the WebDriver files, it’s now the time to learn how to combine and use them with a dedicated VS project.
Step 1: Extract the WebDriver ZIP file
After downloading 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”).
Folder Content after Extraction:
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 this basic steps:
- Open the Visual Studio application.
- Press “File” - > New -> Select a new “Project” (Another option is to use the shortcut combination “Ctrl+Shift+N”).
- At the new project window, select the “Test” option that 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 this basic steps:
- On the new project that we created in the previous step.
- Add a new reference to the Selenium WebDriver DLL’s.
3. On the reference manager, navigate to the selenium WebDriver setup files.
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”.
Step 4: Add the Selenium Classes that we are going to use during our development
To use the Selenium commands, we first need to add the classes that we received after we attached the selenium DLL’s.
To do so, please add the following commands:
This allows the user to access commands that can be used on “Firefox” browsers only!