VOOZH about

URL: https://www.nuget.org/packages/Nutstone.Selenium.Core/

⇱ NuGet Gallery | Nutstone.Selenium.Core 1.1.2




Nutstone.Selenium.Core 1.1.2

dotnet add package Nutstone.Selenium.Core --version 1.1.2
 
 
NuGet\Install-Package Nutstone.Selenium.Core -Version 1.1.2
 
 
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="Nutstone.Selenium.Core" Version="1.1.2" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nutstone.Selenium.Core" Version="1.1.2" />
 
Directory.Packages.props
<PackageReference Include="Nutstone.Selenium.Core" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nutstone.Selenium.Core --version 1.1.2
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Nutstone.Selenium.Core, 1.1.2"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nutstone.Selenium.Core@1.1.2
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nutstone.Selenium.Core&version=1.1.2
 
Install as a Cake Addin
#tool nuget:?package=Nutstone.Selenium.Core&version=1.1.2
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Introduction

Hi. this package is written out of boredom with havng to run UI tests manually whilst developing .net core (5) full-stack applications.

It provides a fluent interface for writing selenium based unit TESTS, but could be used to create full functioning selenium applications.

it is not complete , but is basically functional (hence the readme)

David.

Installation

Install-Package Nutstone.Selenium.Core

install the selenium package of your choice.

This package ONLY (currently) supports ChromeDriver , but can be extended be implementing by implementing ISeleniumWebDriver.

note this package makes extensive use of the excellent Scrutor package so ALL supported interfaces will be loaded at startup , you do not have to register them yourself

for example:-

using Nutstone.Selenium.Core.Browser.Drivers;
using Nutstone.Selenium.Core.Configuration;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using System.IO;

namespace test_nutstone_selenium.Drivers
{
 public class SeleniumEdgeDriver : ISeleniumWebDriver
 {
 public string BrowserType => DriverConstants.Edge;
 public IWebDriver GetDriver(DriverConfiguration driverConfiguration)
 {
 var edgeOptions = new EdgeOptions
 {
 LeaveBrowserRunning = driverConfiguration.LeaveBrowserRunning,
 BinaryLocation = Path.Combine(driverConfiguration.DriverPath, "msedgedriver.exe")
 };
 return new EdgeDriver(edgeOptions);
 }

 public string GetDriverExecutable()
 {
 return "msedgedriver";
 }
 }
}

Getting Started

Define your page models


using Nutstone.Selenium.Core.Attributes;

namespace test_nutstone_selenium.Tests
{
 public class TestModel
 {
 [SeleniumModel(SelectorType.Xpath, "//*[@id='simpletests']")]
 public bool SimpleTestsButton { get; set; } = false;

 [SeleniumModel(SelectorType.Xpath, "//*[@id='firstname']")]
 public string FirstName { get; set; }

 [SeleniumModel(SelectorType.Xpath, "//*[@id='surname']")]
 public string Surname { get; set; }

 [SeleniumModel(SelectorType.Xpath, "//*[@id='amount']")]
 public decimal? Amount { get; set; } = null;

 [SeleniumModel(SelectorType.Xpath, "//*[@id='amountText']")]
 public string AmountText { get; set; } = null;

 [SeleniumModel(SelectorType.Xpath, "//*[@id='sex']")]
 public string Sex { get; set; } = null;

 [SeleniumModel(SelectorType.Xpath, "//*[@id='email']")]
 public string Email { get; set; } = null;

 public DateTime DateOfBirth { get; set; } 
 }
}

Define your page processor

using Nutstone.Selenium.Core.Custom.Page;
using Nutstone.Selenium.Core.Test.Service;
using Nutstone.Selenium.Core.Webdriver.Extensions;

namespace test_nutstone_selenium.Tests
{
 public class TestPage : CustomSeleniumPage<TestModel>
 {
 public TestPage(IWebDriverProxy webDriverProxy, IWebTestService webTestService) : base(webDriverProxy, webTestService)
 {
 }

 public override IWebTestService Run()
 {
 this
 .WithClick(x => x.SimpleTestsButton) // click on a page
 .WithUrl("/simplepage") // wait or this url to contain 
 .WithInput(x => x.FirstName) // populate firstname 
 .WithInput(x => x.Surname)
 .WithInput(x => x.Amount)
 .WithSelect(x => x.Sex)
 .WithInput(x => x.Email)
 .Assert(); // run any assertions
 return this.webTestService;
 }
 }
}

Run your test

using NUnit.Framework;
using Nutstone.Selenium.Core.Configuration;
using Nutstone.Selenium.Core.Loggers.LoggerFile;
using Nutstone.Selenium.Core.Testing;

namespace test_nutstone_selenium.Tests
{
 public class NutstoneCoreTests : SeleniumTestIntergrationFixture
 {
 
 public NutstoneCoreTests()
 {
 this.Initialise((logBuilder) => 
 {
 logBuilder.AddFileLogger(@"The-full-filename-of-the-log-file"); 
 }, () => 
 {
 return DriverConfiguration.WithChrome()
 .SetDriverPathFromLocation(@"The-Fullpath-of-the-seleniumdriver")
 .SetLeaveBrowserRunng(true)
 .SetFullscreen(true)
 .SetTakeScreenShots(true)
 .SetClearScreenShots(true)
 .SetScreenShotDirectoryPath(@"Wherever-You-Want-TheScreenShots-directory");
 });
 }

 [Test]
 public void Can_Run_A_Selenium_Test()
 {
 this.RunWebTest(() =>
 {
 var basicModel = new TestModel();

 this.webTestService.OpenUrl("http://localhost:4200")
 .WithCustomPage(basicModel)
 .SetValue(x => x.SimpleTestsButton, true)
 .SetValue(x => x.FirstName, "Tess")
 .SetValue(x => x.Surname, "nutstone")
 .SetValue(x => x.Amount, 200.34M)
 .WithAssertion(x => x.FirstName).IsEqualTo(basicModel.FirstName)
 .WithAssertion(x => x.AmountText).IsMonetaryEqualTo(200.34M)
 .Run();
 });
 } 
 
 }
}

Extending your page functionality

Each custom page has access to the underlying WebDriverProxy interface and the underlying IWebdriver interface (via webDriverProxy.Driver).

so you can extend the functionaly o your page relatvely easily. In this case we are going to populate a date of birth element that has 3 html input elements:-

using Nutstone.Selenium.Core.Custom.Page;
using Nutstone.Selenium.Core.Test.Service;
using Nutstone.Selenium.Core.Webdriver.Extensions;
using OpenQA.Selenium;

namespace test_nutstone_selenium.Tests
{
 public class TestPage : CustomSeleniumPage<TestModel>
 {
 public TestPage(IWebDriverProxy webDriverProxy, IWebTestService webTestService) : base(webDriverProxy, webTestService)
 {
 }

 private TestPage WithDate()
 {
 var dobAsStringArray = this.Model.DateOfBirth.ToShortDateString()
 .Split("/");
 this.webDriverProxy
 .WithInput(By.XPath("//*[@id='dob-dd']"), dobAsStringArray[0], true)
 .WithInput(By.XPath("//*[@id='dob-mm']"), dobAsStringArray[1], true)
 .WithInput(By.XPath("//*[@id='dob-yy']"), dobAsStringArray[2], true);
 return this;
 } 

 public override IWebTestService Run()
 {
 this
 .WithClick(x => x.SimpleTestsButton) // click on a page
 .WithUrl("/simplepage") // wait or this url to contain 
 .WithInput(x => x.FirstName) // populate firstname 
 .WithInput(x => x.Surname)
 .WithInput(x => x.Amount)
 .WithSelect(x => x.Sex);
 this.WithDate(); 
 this
 .WithInput(x => x.Email)
 .Assert(); // run any assertions
 return this.webTestService;
 }
 }
}

Extending your page functionality using an injected service

You can define your own transient service to supply extra functionality to your page(s).

define an interface that implements the pseudo interface ICustomWebProxyDriver

using Nutstone.Selenium.Core.Webdriver.Extensions;
using System;

namespace test_nutstone_selenium.Tests
{
 public interface ITestCustomWebProxyDriver : ICustomWebDriverProxy
 {
 void WithDate(DateTime date);
 }
}

Implement the interface

using Nutstone.Selenium.Core.Loggers.Extended.Logger;
using Nutstone.Selenium.Core.Webdriver.Extensions;
using OpenQA.Selenium;
using System;

namespace test_nutstone_selenium.Tests
{
 public class TestCustomWebProxyDriver : ITestCustomWebProxyDriver
 {
 private readonly IExtendedLogger log;

 private readonly IWebDriverProxy webDriverProxy;


 public TestCustomWebProxyDriver(IExtendedLogger extendedLogger, 
 IWebDriverProxy webDriverProxy)
 {
 this.log = extendedLogger;
 this.webDriverProxy = webDriverProxy;
 }

 public void WithDate(DateTime date)
 {
 var dobAsStringArray = date.ToShortDateString()
 .Split("/");
 this.webDriverProxy
 .WithInput(By.XPath("//*[@id='dob-dd']"), dobAsStringArray[0], true)
 .WithInput(By.XPath("//*[@id='dob-mm']"), dobAsStringArray[1], true)
 .WithInput(By.XPath("//*[@id='dob-yy']"), dobAsStringArray[2], true);
 }
 }
}

inject the interface into your page

using Nutstone.Selenium.Core.Custom.Page;
using Nutstone.Selenium.Core.Test.Service;
using Nutstone.Selenium.Core.Webdriver.Extensions;

namespace test_nutstone_selenium.Tests
{
 public class TestPage : CustomSeleniumPage<TestModel>
 {
 private readonly ITestCustomWebProxyDriver testCustomWebProxyDriver;


 public TestPage(ITestCustomWebProxyDriver testCustomWebProxyDriver, IWebDriverProxy webDriverProxy, IWebTestService webTestService) : base(webDriverProxy, webTestService)
 {
 this.testCustomWebProxyDriver = testCustomWebProxyDriver;
 }

 public override IWebTestService Run()
 {
 this
 .WithClick(x => x.SimpleTestsButton) // click on a page
 .WithUrl("/simplepage") // wait or this url to contain 
 .WithInput(x => x.FirstName) // populate firstname 
 .WithInput(x => x.Surname)
 .WithInput(x => x.Amount)
 .WithSelect(x => x.Sex);
 this.testCustomWebProxyDriver.WithDate(this.Model.DateOfBirth); 
 this
 .WithInput(x => x.Email)
 .Assert(); // run any assertions
 return this.webTestService;
 }
 }
}

Defining an Application to Chain Pages

To create an application that will chain pages together in a predefinied order first create a custom application model that contains all the properties from the various pages you want to include in the application. The property names and types should EXACTLY match the names/types of the target pages:-

 public class BasicTestSeleniumApplication
 {
 public string FirstName { get; set; }

 public string Surname { get; set; }

 public decimal? Amount { get; set; }

 public string Sex { get; set; }

 public string Email { get; set; }

 public string MatInput { get; set; }

 }

Then create your application.

 public class BasicCustomApplication : CustomSeleniumApplication<BasicTestSeleniumApplication>
 {
 public BasicCustomApplication(IWebTestService webTestService, IExtendedLogger logger)
 : base(webTestService, logger)
 {
 }

 /// <summary>
 /// Register all the pages we are going to use in our application
 /// </summary>
 public override void RegisterPages()
 {
 this
 .RegisterPage(new BasicTestSeleniumModel())
 .RegisterPage(new BasicMaterialSeleniumModel());
 }

 public override IWebTestService Run()
 {
 this.MapByConvention(); // map our model to the pages we have registered

 // Run that application pages in the order we want
 return this.webTestService
 .WithCustomPage<BasicTestSeleniumModel>()
 .SetValue(x => x.SimpleTestsButton, true)
 .Run() // assertions are run as part of the model run
 .WithCustomPage<BasicMaterialSeleniumModel>()
 .SetValue(x => x.MaterialTestsButton, true)
 .Run();
 }
 }

You must register the pages you are going to use. call MapByConvetion method of the base class if you want it to automatically map (using reflection) the values in your application model to the associated properties in the page models (that you have registered)

Run the test!

note to run assertions in your application test you must reference the assertion of the page model directly.

 [Test]
 public void Can_RunSimple_Application_With_Assertions()
 {
 this.RunWebTest(() =>
 {
 this.webTestService
 .OpenUrl(baseUrl)
 .WithApplication(new BasicTestSeleniumApplication()
 {
 Amount = 20012.43M,
 FirstName = "Tess",
 Surname = "Nuttall",
 Sex = "Female",
 Email = "Tess@somewhere.com",
 MatInput = "This is a mat input"
 })
 .WithPage<BasicTestSeleniumModel>((page) => 
 {
 page
 .WithAssertion(x => x.FirstName).IsEqualTo("Tess");
 })
 .Run();
 });
 }

Contact

nutstone.selenium@gmail.com

Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Nutstone.Selenium.Core:

Package Downloads
Nutstone.Selenium.Mongo.Provider

Generic mongo selenium page/configuration provider for use with nutstone.selenium.core

Nutstone.Selenium.Core.Testing

Provides selenium testfixture and test runner for nutstone.selenium

Nutstone.Selenium.Mongo.Custom.Provider

Selenium data provider using mongo

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2 414 4/24/2023
1.1.1 416 3/19/2023
1.0.130 934 7/22/2022
1.0.129 605 7/22/2022
1.0.128 631 7/19/2022
1.0.127 627 7/19/2022
1.0.126 645 7/19/2022
1.0.125 647 7/18/2022
1.0.124 612 7/18/2022
1.0.123 654 7/11/2022
1.0.122 617 7/11/2022
1.0.121 635 7/11/2022
1.0.120 628 7/11/2022
1.0.119 635 7/11/2022
1.0.118 627 7/11/2022
1.0.117 984 6/29/2022
1.0.116 632 6/27/2022
1.0.115 1,065 6/8/2022
1.0.114 618 6/8/2022
1.0.113 638 6/8/2022
Loading failed