Design Selenium Framework with C# – Part 2

After learning the basics of the interface design pattern, lets look at actual implementation in step by step manner.

Lets first discuss about how to set up the required nuget packages for the selenium.

Open visual studio and create a unit test project by selecting the project type unit testing.

Once the project is created, lets install the required Nuget packages. This Nuget package is similar to maven repository in Java. It contains all binaries required for the purpose.

NuGet

We will download and map to the current project just enough to create some simple selenium tests.

The Nuget packages can be downloaded from different sources, lets download packages from default location https://www.nuget.org/

We need following packages for the purpose of creating the selenium tests.

Nuget required packages for selenium

Once we download and attach it to the project we need to do download another set of install-able files meaning that driver exes to steer the web browsers.

  • IEDriverServer
  • ChromeDriver
  • geckodriver (firefox dirver)

Now our project setup is ready for creating the Framework and implementing the simple selenium tests.

Before we dive into creating classes, lets create folder structure so that we can partition our classes into different directories like below. Will discuss one by one while we go through each of the items. Lets create following folders in the solution.

  • DriverExecutables
    • This will contain the driver executable files we have downloaded
  • IDrivers
    • Contract definitions for creating the WebDrivers
  • WebTesting
    • Actual web driver classes implementing the IDrivers interface.

FolderStructure

As we mentioned in the part one, let us first create the IDrivers interface to make browser object as described below.

IDrivers Interface

In the above Interface, we are defining the objects required fro web driver creation and also using the ‘Driver’ property we are setting and getting the driver back from each implementation.

In this step lets create the configuration class which defines the driver executable locations, timeouts and other browser configuration details we have just defined in the interface.

Configuration

Lets look at each of the web driver class, how it is done. I have kept all the code in git repository for reference.

Lets create filepath property to set and get the file path. Also see how we can set the driver services and desired capabilities/options as class properties.

After creating these properties, next step is to initialize the driver with these options

chrome driver implementation 1

If you look at  below code the folder path is set by config driver exe folder whereas DesiredServices and DesiredCapabilites/Options properties in config class are set by chrome driver class.

chrome driver implementation 2

I will try to explain the logical flow once we complete the entire post.

As of now the summary is, all driver classes (ChromeDriver, FireFox driver class, and IEdriver class)  have all the three methods.

driver classes

The link to the whole repository from git is given below for reference.

selenium framework git repository

It will be much more straight forward if you already well versed with the basic idea of properties, methods, and oops concepts.

Now lets discuss about how to create these browser instances as separate threads so that we can run tests in parallel in next part.

Design Selenium Framework with C# – Part 3

Advertisement

One thought on “Design Selenium Framework with C# – Part 2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s