An Introduction to Selenium WebDriver: WebDriver is an open source automating web application testing tool which is very popular in software testing field right now.
This provides APIs that easily integrate with any programming language such as C#, Java, Python. In simple words, it is an API that’s easy to explore and understand, which help us to make our tests easier to read and maintain.” The use of Selenium WebDriver is to basically test any web application.
Features of Selenium WebDriver:
A well-designed Object-Oriented API that provides improved support for web-app testing problems.
Supports dynamic web pages where the element of a Page may change without the Page itself being reloaded.
All the limitations of SELENIUM RC rectified in this Selenium WebDriver
It supports all the major programming and scripting languages like Java, C#, Python, Ruby, PHP, Perl and JavaScript.
It also supports all the major and popular browsers available in the market like Google Chrome, Mozilla Firefox, Safari, Opera, Internet Explorer.
Selenium WebDriver supports multiple platforms to test web application like Windows, Mac, Linux, IOS, Android.
An Introduction to C#: C# is an Object-Oriented Language, introduced in the .NET framework developed by Anders Hejlsberg as a Microsoft initiative to develop a Common Language Interface environment. C# is a Simple, Powerful, general purpose and Type-Safe language.
We can develop C# projects in Visual Studio Environment, a powerful tool-rich programming environment from Microsoft. We can create console based applications as well as windows based applications from the C# environment. C# Coding style is very similar to C++ and JAVA so the developers who are familiar with those languages can pick up C# coding quickly.
Software Required:
Visual Studio (Preferably 2013 or higher version)
C# Selenium WebDriver Client (2.53)
C# NuGet package manager
Chrome Driver.exe to launch Chrome Browser
IE Driver.exe to launch Internet Explorer Browser
Steps to Download Visual Studio Community
Visit the below mentioned link and download Visual Studio 2015 community edition as shown in screenshot https://www.visualstudio.com/enus/downloads/download-visual-studio-vs.aspx.
Save the .exe file that needs to install and configure Visual Studio 2015 Community edition.
Steps to Install Visual Studio Community
Double click on the saved file to start the installation.
Click on the Run button.
Click ‘Install ‘. Be sure to read and agree to the License Terms and Privacy Policy.
Note: Change the default location if you like to and let the ‘Type of Installation’ be default as Typical, unless you know what you are doing.
Wait for the install to complete.
Note: Installation would take around 10 to 15 mins.
Click on Launch button to start the Visual Studio.
Steps to Create a New Project
1) Click on New Project.
2) Select Visual C# from the left, then select Console Application from the middle. It will give the option to mention the Project name, location & solution name. Give the sensible name to the project, just for the sake of simplicity, enter ProjectQA and give the preferred location to the project. Click on OK button to proceed.
Note: Let the solution name be same as FirstSeleniumProgram.
Steps to add Selenium .dll files to the new project
1) Right click on Solution Name on right-hand side panel and select Manage NuGet Package Manager as shown in screenshot
2) Nuget Package Manager Screen will be displayed. Notice under installed tab “No Package “text. It means nothing has been added from Nuget package manager to this project.
3) Click on Browse tab and you will notice all the popular packages available as shown in screenshot.
Type selenium in the search box and hit Enter. You will find all the Selenium related packages available in NuGet Package Manager. You need to install all the packages present under yellow boundary as shown in the screenshot in order to run your first selenium script.

Click on one of the package just say Selenium Webdriver, then click on install button. Next click on Ok button in next pop up window. Follow the same for other packages too.

Once you will click on Ok button, NuGet Package Manager will start installing Selenium Web driver for your project as shown in screen shot. Notice output window in your visual studio. It is saying Selenium Web driver has been installed with all the details like URL, version, time etc.
After installing all the packages as mentioned in step 4, Click on Installed tab once again. This time you will see all the installed packages are listed there.
To verify whether Selenium Web Driver has been installed or not. Notice the solution pane on right hand side where you will notice Web Driver and Web Driver Support packages are attached with your project or solution. For details see attached screenshot.
To launch the Firefox browser and navigate to a URL, write below code in your program.cs (Note file name can be anything. It’s your wish what name you choose.). I have used default program file created by VS 2015.
using System;
using OpenQA.Selenium.Firefox;
namespace FirstSeleniumProgram
{
public class Program
{
public void LaunchBrowser
{
// 1. Launch Firefox Browser
FirefoxDriver firefox = new FirefoxDriver();
// 2. Go to Google Home Page
firefox.Url = "https://www.google.co.in";
// 3. Print Page Title
Console.WriteLine("Page Title is {0}", Firefox. Title);
// 4. Print Current URL Open in Browser
Console.WriteLine("Current URL is {0}", firefox.Url);
// 5. Print Length of the page Source Code
IWebElementl length=firefox.PageSource.Length);
Console.WriteLine("Page Contains {0} characters in it", length.
// 6. Close the Browser
firefox.Quit();
// ALTERNATE of Step 6
// firefox.Close();
}
}
}
I hope you would find this article simple and helpful if you are beginner in C# automation. I also hope that this article would have helped you to do all the required setup to kick start with Selenium first script i.e. launching the browser this tutorial. In my next article, I will discuss how to add Selenium without using NuGet Package Manager. I will be coming with my new article very soon. Till then bye.
I would appreciate your comments. You can contact me any time through email at jharakesh1991@gmail.com.
Great blog..It was so informative for learners..i suggest this blog to my friends..keep update selenium training in chennai
ReplyDeleteselenium training in velachery
best selenium training in chennai