✨ About

πŸš€ Selenium Framework using C# (CSharp) development from scratch

✨ Requirements.

  • Visual Studio IDE

✨ Instructions for Windows

  • Clone the repo
    https://gitlab.com/the-ta-crowd/SeleniumUsingCSharp
  • Once done, open the solution in Visual Studio IDE
    SeleniumCSharpNetCore.sln
  • Install Nuget packgae
    Right-click on project and click "Manage NuGet Package" and install it

✨ Package information

Framework used

  • Selenium WebDriver is an open-source web automation framework that permits you to execute cross-browser tests.
  • Specflow is a tool supporting BDD (Behavior Driven Development) practices in .NET framework
  • ExtentReport allows to generate custom logs, snapshots along with pie chart and dashboard

✨ Structure

  • Base- Page Initialization with base class
  • Config- Configuratio of config xml file
  • Extension- WebDriver and WebElement extension method
  • Feature- Feature reside here
  • Hooks- Specflow hooks
  • Pages- Pages of POM (Page Object Model)
  • Steps- Step definition glue code reside here
  • Result- Test result

✨ CodeBase is developed on below components

  • [πŸš€ Page Initialization with Base Class]
  • [πŸš€ Page Navigation]
  • [πŸš€ Page Generator]
  • [πŸš€ WebDriver and WebElement Extension Methods]

πŸš€ Page Initialization with Base Class

Old Code Implementation:

Many times, we try to pass the WebDriver object over and over again from one class to another class.
By the means of Constructor or passing it as a parameter in the method where IWebDriver instance is required.

image

New Code Implementation

  Created a base abstract class and create a private property

image

πŸš€ Page Navigation

Old Code function without return type

We create a function or method without any return type.

image

New Code for Page Navigation

Ensure that business logic is embedded in our test code.
We can establish relationships between each page.
While an operation is performed on one method it may or may not return a page object.

image

πŸš€ Page Generator

The Thumb Rule of Factory Design Pattern is the avoiding object initialization in the test.

Old Code

image

New Code

    How did we accomplish this? Generics in C# were used to accomplish this. 
    In the following section, we discuss this topic in more detail

image

πŸš€ Introduction to Generics in C#

Generics in C# give the user the ability to write classes or functions that can work with any data type easily.
We might say a generic class or function that is compatible with any other data type. 
All we need to do is define it with a placeholder.
To put it simply, we have to write a set of methods or classes that take arguments based on the data type. 
The constructor will therefore generate code to handle the specified data type when it encounters a compiler.

Generics Implementation in Code

tempsnip1

πŸš€ WebDriver and WebElement Extension Methods

Extension Methods enable you to add methods to an existing type without creating a new derived type.
An extension method is a static method of a static class.
Where the β€œthis” modifier is applied to the first parameter.
The type of the first parameter will be the type that is extended.

image

Calling extension method in script

image

πŸš€ Further, proposed improvements

  • Executing test in parallel