Selenium.Essentials 1.0.0

.NET Standard 2.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package Selenium.Essentials --version 1.0.0
NuGet\Install-Package Selenium.Essentials -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Selenium.Essentials" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Selenium.Essentials --version 1.0.0
#r "nuget: Selenium.Essentials, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Selenium.Essentials as a Cake Addin
#addin nuget:?package=Selenium.Essentials&version=1.0.0

// Install Selenium.Essentials as a Cake Tool
#tool nuget:?package=Selenium.Essentials&version=1.0.0

Selenium.Essentials

Build Selenium web automation test using advanced web controls with wrappers and plenty of extensions to fasten your automation development time. Focus more on script logic with better consistent script execution, less maintenance, no hardwaits, with improved script execution performance and integrated Api testing framework.

Overview

Selenium provides only option to create only a single generic control which is called the IWebElement. Imagine if you have option to declare controls which resemble the html elements and provide its functionality, for example, Checkbox, Textbox, Button.

Selenium Essentials provide new custom controls giving meaning to your page objects and making it more readable. Every control is defined from a BaseControl which has a set of definitions applicable to all controls as well as its custom actions. For example, Checkbox control will have all properties of the BaseControl and also defines Check() which ticks the checkbox in the UI, UnCheck() which unticks the checkbox, IsChecked returns a bool value based on the control is Checked or Unchecked reading from the UI.

The Custom control also expose the underlying IWebElement as a property used by Selenium, in case you need to do any operations on top of this.

There are plenty of Wait operation defined on the base control which flows through all the custom controls. There are different overrides to the wait operation where you can control the time to wait, whether to throw exception if fails, message for assertions when the waits are used for assert operations. Some custom control overrides the default wait to give a better meaning.

Read more about controls here

WebDriver and WebElement comes with some useful extensions which helps during the automation. For example, executing javascript, scroll operations, taking screenshot, getting driver capabilities.

There is a simple Api framework, which can help in writing Integration tests using a fluent approach.

Package contains lots of extensions and helpers over different types which will help increase productivity. Example,

  • Loading excel and converting to C#
  • Converting Json to Dictionary
  • Serialization and Deserialization
  • Regular Expression, DateTime, String, Enumerable, Async

Benefits

  • Readable page objects which clearly defines what each control resemble in the browser
  • Custom controls with wrapped operations
    • Checkbox - Check, UnCheck, IsChecked, more
    • Textbox - Custom clear and set operations (extented clear which will make sure the content is cleared by doing Ctrl+a and BackSpace) and Set operation to overcome some responsive issues
    • UnorderedList - Total, Items
    • Select - operations on SelectElement
    • Table - TotalColumns, TotalRows, ColumnNames, GeCellContent, GetRowPosition, GetColumnPosition, more
    • Collection - working with Driver.FindElements(...)
    • FileUpload - UploadFile
    • Button
    • WebControl - for all generic html control
  • WebElement and WebDriver extension methods for most of the
  • Api framework to write integration tests
    • Supports fluent
    • Support most of the operations
    • Simple and easy to manage the tests
  • Extensions which provide many methods for automation engineering works
    • String, RegEx, Enumerable, DatTime, Async, more
  • Helpers to load excel, serialization, Json to Dictonary, more
  • Attributes for test to load json and xml data

Prerequisites

Visual Studio 2017 or higher

You need to know

  • Minimum
    • about the basics of writing test using Selenium (concept of IWebDriver, IWebElement and starting the driver)
    • know how to inspect and find elements (creating better selectors)
    • know about the page object model
    • any test framework, for example, nUnit
    • c# beginner
  • Good to know
    • CI CD pipelines
    • Multibrowser automated test configurations (any)
      • Selenium Grid
      • Sauce Labs
      • Browser Stack
      • Inhouse setup with physical servers and Vm
      • Cloud configured machines to run tests
      • Any custom setup to run multibrowser tests
    • Mobile test with Appium
    • Advanced Logging
    • Test Reporting
    • Programming knowledge
      • c# Generics
      • OOPS concepts
      • Linq and Lamda (basic)
      • Multithread programming

Install

nuget install Selenium.Essentials

Setup

Once you have setup your project or added the nuget package to your existing project, follow the links below to speed up your development.

  1. Onboarding
  2. Initialize Web Driver
  3. PageObject with new controls
  4. Some Tips

Usage

Conventional way to declare elements (IWebElement)

private IWebElement _headerContent = driver.FindElement(By.Id("chkAreYouRobot"));

The below section show how to use new Checkbox control. This definition is clear on what element in the UI corresponds to and also contains its custom properties and methods.

Add the using statement for this package

using Selenium.Essentials

Define the new control in your page object. If you have existing page objects with IWebElement, then you can easily change with same selector and passing it to the new custom control. Remember, the driver is explicitly passed to the control, in order to have better control over the page object if you intend to run the scripts in parallel, on the same machine.

private CheckboxControl _userTypeCheck => new CheckboxControl(driver, By.Id("chkAreYouRobot"));

Notice the declaration is by an expression (=>) which does not store the value but fetch everytime when accessed. Following this pattern reduces StaleElementException.

To tick the checkbox

public void CheckUserType() {
  _userTypeCheck.WaitForElementVisible(errorMessage: "The User Type checkbox was not visible in the UI"); //This can be used as an assertions, and when not found, it will throw with an exception with "errorMessage" passed
  _userTypeCheck.Check();
}

Conditionally check if the element exist by waiting for maximum of 2 seconds and make a check operation if available. The below sample will not throw an exception if the control was not found in the browser, instead the WaitForElementVisible will return false after 2 seconds and will not go inside the if condition

public void CheckUserType() {
  if (_userTypeCheck.WaitForElementVisible(waitTimeSec: 2, throwExceptionWhenNotFound: false)) {
    _userTypeCheck.Check();
  }
}

This is how it looks like when you have new controls in your page object

private ButtonControl _loginBtn => new ButtonControl(driver, By.Name("loginUser"));
private TextboxControl _usernameTxt => new TextboxControl(driver, By.Id("txtUserName"));
private TextboxControl _passwordTxt => new TextboxControl(driver, By.Id("txtPassword"));
private WebControl _headerContent => new WebControl(driver, By.CssSelector("div.user h2"));
private UnorderedListControl _tabNavigation => new UnorderedListControl(driver, By.XPath("//div[@id='p-namespaces']/ul"));
private TableControl _tableMainContent => new TableControl(driver, By.Id("mp-upper"));

Documentation

https://github.com/peterrexj/Selenium.Essentials/wiki

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5.14 315 11/21/2022
1.0.5.13 145 11/20/2022
1.0.5.12 164 11/15/2022
1.0.5.11 301 10/16/2022
1.0.5.10 417 9/1/2022
1.0.5.8 1,117 5/25/2022
1.0.5.6 2,333 4/12/2022
1.0.5.5 413 4/6/2022
1.0.5.4 375 4/5/2022
1.0.5.3 398 4/4/2022
1.0.5.2 460 3/20/2022
1.0.5.1 628 1/9/2022
1.0.5 315 12/31/2021
1.0.4.1 1,346 7/3/2021
1.0.4 393 7/3/2021
1.0.3.1 405 6/14/2021
1.0.3 345 6/14/2021
1.0.2.1 7,296 10/15/2020
1.0.2 1,634 11/3/2019
1.0.1 455 10/6/2019
1.0.0 459 10/6/2019