Skip to content

Simple framework for creating Selenium tests using the Selenium WebDriver and the Selenium Grid.

Notifications You must be signed in to change notification settings

ramazankizilkaya/SeleniumHelper

 
 

Repository files navigation

SeleniumHelper for C#

This project is a simple framework for creating Selenium tests using the Selenium WebDriver and the Selenium Grid. This version is using version 3 of the Selenium WebDriver.

The project has two main classes: Connector and Utility.

Connector Class:

Use this class to initialize an instance of the WebDriver, either local or remote. Current browsers supported are:

There are several overloadeds for the Initialize method:

Local execution: Firefox, Chrome or PhantomJS
  1. string browser
  2. string browser, string driverPath
  3. string browser, bool remote, string driverPath, Uri seleniumHubURL, string operatingSystem, , bool maximize
Remote execution: Firefox or Chrome
  1. string browser, Uri seleniumHubURL
  2. string browser, Uri seleniumHubURL, string operatingSystem, bool maximize

operatingSystem defaults to Any
maximize (the browser window) defaults to true for local execution and false for remote execution

InitializeRemote: Browser browser, Uri seleniumHubURL, string operatingSystem
You can use this method to initialize the remote webdriver directly.

You can set the remote webdriver URL in the app.config:

<appSettings>
<add key="SeleniumHubURL" value="http://127.0.0.1:4444/wd/hub" />
</appSettings>

Utility Class:

This class contains useful methods to make tests easier to create.

GoTo: navigates to the desired URL
InputValue: sets the value of an Input textbox
SetDropDownItem: sets an option list to a specified option
WaitForElementReady: returns an iWebElement once it is available on the web page
WaitForElementByIdReady: returns an iWebElement based on the document Id once it is available on the web page
WaitForElementXpathIdReady: returns an iWebElement based on an Xpath selector once it is available on the web page
GetDriver: returns an instance of the driver that is associated with an iWebElement
GetID: returns the document Id of an iWebElement if it exists
GetClasses: returns a list of CSS classes for an iWebElement
HasClass: returns a bool if a class is present on an iWebElement
SetAttribue: sets the value of an HTML element's attribute
ExtractManifestResourceToDisk: supports extracting embedded resources allowing them to be utilized for tests
ResetDriver: quit the driver and release any resources
CaptureScreenshot: captures the screen of a browser running on a remote node and saves it to a text file in Base64 format

The project includes unit tests for the classes listed above as well as sample tests using the framework. Unit tests have categories so that you can segregate them if needed. For tests that have a category of RemoteWebDriver you must have a selenium grid running and the app.config with appSettings to provide the URL and location of where to store a screenshot if you with to capture them. Below is an example:

<appSettings>
<add key="SeleniumHubURL" value="http://127.0.0.1:4444/wd/hub" />
<add key="CaptureScreenshot" value="true"/>
<add key="ScreenShotPath" value="C:\\Temp\\screenshot"/>
</appSettings>

About

Simple framework for creating Selenium tests using the Selenium WebDriver and the Selenium Grid.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 98.1%
  • HTML 1.9%