Nutstone.Selenium.Core 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package Nutstone.Selenium.Core --version 1.0.7
                    
NuGet\Install-Package Nutstone.Selenium.Core -Version 1.0.7
                    
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.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nutstone.Selenium.Core" Version="1.0.7" />
                    
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.0.7
                    
#r "nuget: Nutstone.Selenium.Core, 1.0.7"
                    
#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.
#addin nuget:?package=Nutstone.Selenium.Core&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=Nutstone.Selenium.Core&version=1.0.7
                    
Install as a Cake Tool

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

work in progress - comming soon

Contact

nutstone.selenium@gmail.com

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  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 277 4/24/2023
1.1.1 301 3/19/2023
1.0.130 780 7/22/2022
1.0.129 476 7/22/2022
1.0.128 494 7/19/2022
1.0.127 493 7/19/2022
1.0.126 512 7/19/2022
1.0.125 509 7/18/2022
1.0.124 484 7/18/2022
1.0.123 521 7/11/2022
1.0.122 491 7/11/2022
1.0.121 501 7/11/2022
1.0.120 500 7/11/2022
1.0.119 503 7/11/2022
1.0.118 501 7/11/2022
1.0.117 854 6/29/2022
1.0.116 497 6/27/2022
1.0.115 898 6/8/2022
1.0.114 485 6/8/2022
1.0.113 485 6/8/2022
1.0.112 507 6/8/2022
1.0.111 508 6/8/2022
1.0.110 497 6/8/2022
1.0.109 522 6/7/2022
1.0.108 650 6/7/2022
1.0.107 755 6/7/2022
1.0.106 524 6/7/2022
1.0.105 556 6/7/2022
1.0.104 571 6/7/2022
1.0.103 506 6/5/2022
1.0.102 887 5/30/2022
1.0.101 3,178 5/6/2022
1.0.100 509 5/5/2022
1.0.99 540 5/5/2022
1.0.98 513 5/5/2022
1.0.97 505 5/5/2022
1.0.96 812 5/5/2022
1.0.95 1,285 4/25/2022
1.0.94 555 4/9/2022
1.0.93 543 4/8/2022
1.0.92 532 4/8/2022
1.0.91 528 4/5/2022
1.0.90 1,212 3/29/2022
1.0.89 1,082 3/23/2022
1.0.88 525 3/23/2022
1.0.87 535 3/18/2022
1.0.86 560 3/16/2022
1.0.85 1,262 3/14/2022
1.0.84 556 3/9/2022
1.0.83 536 3/9/2022
1.0.82 531 3/8/2022
1.0.81 529 3/7/2022
1.0.80 518 3/6/2022
1.0.79 532 3/4/2022
1.0.78 516 3/4/2022
1.0.77 533 3/4/2022
1.0.76 530 3/3/2022
1.0.75 543 3/2/2022
1.0.74 530 3/2/2022
1.0.73 533 2/23/2022
1.0.72 520 2/22/2022
1.0.71 539 2/21/2022
1.0.70 543 2/21/2022
1.0.69 553 2/20/2022
1.0.68 519 2/18/2022
1.0.67 560 2/18/2022
1.0.66 526 2/18/2022
1.0.65 541 2/18/2022
1.0.64 518 2/18/2022
1.0.63 505 2/18/2022
1.0.62 1,478 2/6/2022
1.0.61 555 2/5/2022
1.0.60 548 2/5/2022
1.0.59 557 2/5/2022
1.0.58 534 1/31/2022
1.0.57 537 1/31/2022
1.0.56 544 1/29/2022
1.0.55 546 1/26/2022
1.0.54 545 1/26/2022
1.0.53 525 1/26/2022
1.0.52 548 1/26/2022
1.0.51 529 1/26/2022
1.0.50 544 1/26/2022
1.0.49 561 1/25/2022
1.0.48 574 1/25/2022
1.0.47 558 1/25/2022
1.0.46 554 1/25/2022
1.0.45 1,553 1/24/2022
1.0.44 520 1/24/2022
1.0.43 530 1/24/2022
1.0.42 1,108 1/21/2022
1.0.41 554 1/21/2022
1.0.40 543 1/21/2022
1.0.39 518 1/21/2022
1.0.38 547 1/21/2022
1.0.37 543 1/19/2022
1.0.36 555 1/19/2022
1.0.35 565 1/19/2022
1.0.34 526 1/19/2022
1.0.33 539 1/19/2022
1.0.32 1,095 1/18/2022
1.0.31 1,085 1/18/2022
1.0.30 1,060 1/17/2022
1.0.29 529 1/15/2022
1.0.28 1,478 1/9/2022
1.0.27 351 12/29/2021
1.0.26 378 12/29/2021
1.0.25 401 12/29/2021
1.0.24 388 12/28/2021
1.0.23 362 12/22/2021
1.0.22 388 12/22/2021
1.0.21 737 12/22/2021
1.0.20 733 12/21/2021
1.0.19 776 12/20/2021
1.0.18 407 12/2/2021
1.0.17 427 12/2/2021
1.0.16 397 12/2/2021
1.0.15 389 12/2/2021
1.0.14 1,096 12/1/2021
1.0.13 368 11/28/2021
1.0.12 1,660 11/26/2021
1.0.11 381 11/22/2021
1.0.10 483 11/18/2021
1.0.9 516 11/18/2021
1.0.8 467 11/14/2021
1.0.7 435 11/13/2021