PuppeteerSharp.Contrib.Should 6.0.0

dotnet add package PuppeteerSharp.Contrib.Should --version 6.0.0                
NuGet\Install-Package PuppeteerSharp.Contrib.Should -Version 6.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="PuppeteerSharp.Contrib.Should" Version="6.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PuppeteerSharp.Contrib.Should --version 6.0.0                
#r "nuget: PuppeteerSharp.Contrib.Should, 6.0.0"                
#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.
// Install PuppeteerSharp.Contrib.Should as a Cake Addin
#addin nuget:?package=PuppeteerSharp.Contrib.Should&version=6.0.0

// Install PuppeteerSharp.Contrib.Should as a Cake Tool
#tool nuget:?package=PuppeteerSharp.Contrib.Should&version=6.0.0                

PuppeteerSharp.Contrib.Should

build CodeFactor

PuppeteerSharp.Contrib.Should is a should assertion library for the Puppeteer Sharp API.

Content

Should assertions for IPage

  • ShouldHaveContentAsync
  • ShouldHaveTitleAsync
  • ShouldHaveUrlAsync
  • ShouldNotHaveContentAsync
  • ShouldNotHaveTitleAsync
  • ShouldNotHaveUrlAsync

Should assertions for IResponse

  • ShouldBeRedirection
  • ShouldBeSuccessful
  • ShouldHaveClientError
  • ShouldHaveError
  • ShouldHaveServerError
  • ShouldHaveStatusCode
  • ShouldHaveUrl
  • ShouldNotHaveStatusCode
  • ShouldNotHaveUrl

Should assertions for IElementHandle

  • ShouldBeCheckedAsync
  • ShouldBeDisabledAsync
  • ShouldBeEmptyAsync
  • ShouldBeEnabledAsync
  • ShouldBeHiddenAsync
  • ShouldBeReadOnlyAsync
  • ShouldBeRequiredAsync
  • ShouldBeSelectedAsync
  • ShouldBeVisibleAsync
  • ShouldExist
  • ShouldHaveAttributeAsync
  • ShouldHaveAttributeValueAsync
  • ShouldHaveClassAsync
  • ShouldHaveContentAsync
  • ShouldHaveFocusAsync
  • ShouldHaveValueAsync
  • ShouldNotBeCheckedAsync
  • ShouldNotBeEmptyAsync
  • ShouldNotBeReadOnlyAsync
  • ShouldNotBeRequiredAsync
  • ShouldNotBeSelectedAsync
  • ShouldNotExist
  • ShouldNotHaveAttributeAsync
  • ShouldNotHaveAttributeValueAsync
  • ShouldNotHaveClassAsync
  • ShouldNotHaveContentAsync
  • ShouldNotHaveFocusAsync
  • ShouldNotHaveValueAsync

Failures

The following failing examples will throw an exception with a message explaining why the assertion failed.

await Page.SetContentAsync(@"
<html>
  <body>
   <div id='foo'>Foo</div>
  <body>
</html>");

var div = await Page.QuerySelectorAsync("#foo");
await div.ShouldHaveContentAsync("Bar");

Expected element to have content "Bar", but it did not.

await Page.SetContentAsync(@"
<html>
  <body>
   <form>
    <input id='foo' value='Foo' />
   </form>
  <body>
</html>");

var input = await Page.QuerySelectorAsync("#foo");
await input.ShouldHaveValueAsync("Bar", "that would be the perfect example");

Expected element to have value "Bar" because that would be the perfect example, but found "Foo".

Samples

Sample projects are located in the samples folder.

This is an example with NUnit:

using System.Threading.Tasks;
using NUnit.Framework;
using PuppeteerSharp.Contrib.Should;

namespace PuppeteerSharp.Contrib.Sample
{
    public class ShouldTests
    {
        IBrowser Browser { get; set; }
        IPage Page { get; set; }

        [SetUp]
        public async Task SetUp()
        {
            await new BrowserFetcher().DownloadAsync();
            Browser = await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless = true
            });
            Page = await Browser.NewPageAsync();
        }

        [TearDown]
        public async Task TearDown()
        {
            await Browser.CloseAsync();
        }

        [Test]
        public async Task Attributes()
        {
            await Page.SetContentAsync("<div data-foo='bar' />");

            var div = await Page.QuerySelectorAsync("div");
            await div.ShouldHaveAttributeAsync("data-foo");
            await div.ShouldNotHaveAttributeAsync("data-bar");
        }

        [Test]
        public async Task Class()
        {
            await Page.SetContentAsync("<div class='foo' />");

            var div = await Page.QuerySelectorAsync("div");
            await div.ShouldHaveClassAsync("foo");
            await div.ShouldNotHaveClassAsync("bar");
        }

        [Test]
        public async Task Content()
        {
            await Page.SetContentAsync("<div>Foo</div>");

            var div = await Page.QuerySelectorAsync("div");
            await div.ShouldHaveContentAsync("Foo");
            await div.ShouldNotHaveContentAsync("Bar");
        }

        [Test]
        public async Task Visibility()
        {
            await Page.SetContentAsync(@"
<html>
  <div id='foo'>Foo</div>
  <div id='bar' style='display:none'>Bar</div>
</html>");

            var html = await Page.QuerySelectorAsync("html");
            html.ShouldExist();

            var div = await Page.QuerySelectorAsync("#foo");
            await div.ShouldBeVisibleAsync();

            div = await Page.QuerySelectorAsync("#bar");
            await div.ShouldBeHiddenAsync();
        }

        [Test]
        public async Task Input()
        {
            await Page.SetContentAsync(@"
<form>
  <input type='text' autofocus required value='Foo Bar'>
  <input type='radio' readonly>
  <input type='checkbox' checked>
  <select>
    <option id='foo'>Foo</option>
    <option id='bar'>Bar</option>
  </select>
</form>
");

            var input = await Page.QuerySelectorAsync("input[type=text]");
            await input.ShouldHaveFocusAsync();
            await input.ShouldBeRequiredAsync();
            await input.ShouldHaveValueAsync("Foo Bar");

            input = await Page.QuerySelectorAsync("input[type=radio]");
            await input.ShouldBeEnabledAsync();
            await input.ShouldBeReadOnlyAsync();

            input = await Page.QuerySelectorAsync("input[type=checkbox]");
            await input.ShouldBeCheckedAsync();

            input = await Page.QuerySelectorAsync("#foo");
            await input.ShouldBeSelectedAsync();
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on PuppeteerSharp.Contrib.Should:

Package Downloads
Rosie.Quality

Package Description

E13.Common.Nunit.Api

Common package containing helpers for an Nunit based testing project targeting an Api layer

E13.Common.Nunit.UI

Common package containing helpers for an Nunit based testing project for a front end

PuppeteerSharp.Contrib.Should.Unsafe

Contributions to the Headless Chrome .NET API 🌐🧪 ✔️ PuppeteerSharp.Contrib.Should.Unsafe is a should assertion library for the Puppeteer Sharp API. ✔️ It provides a convenient way to write readable and robust browser tests in .NET 📄 https://hlaueriksson.me/PuppeteerSharp.Contrib.Should.Unsafe/ ⚠️ These extension methods are the sync over async versions of the originals from the PuppeteerSharp.Contrib.Should package. They may be convenient, but can be considered unsafe since you run the risk of a deadlock. ✔️ Works with: ◼️ Machine.Specifications ◼️ SpecFlow.xUnit ◼️ xunit

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.0 1,335 11/18/2023
5.0.0 6,277 8/9/2022
4.0.0 2,690 4/17/2021
3.0.0 7,175 9/13/2020
2.0.0 877 5/8/2020
1.0.0 7,503 1/9/2019

⬆️ Bump PuppeteerSharp to 12.0.0
👽️ Use PuppeteerSharp interfaces; IPage and IElementHandle

New assertions for IPage:
◼️ ShouldHaveUrlAsync
◼️ ShouldNotHaveUrlAsync

New assertions for IElementHandle:
◼️ ShouldHaveAttributeValueAsync
◼️ ShouldNotHaveAttributeValueAsync
◼️ ShouldBeEmptyAsync
◼️ ShouldNotBeEmptyAsync

Assertions for IResponse:
◼️ ShouldHaveUrl
◼️ ShouldNotHaveUrl
◼️ ShouldHaveStatusCode
◼️ ShouldNotHaveStatusCode
◼️ ShouldBeSuccessful
◼️ ShouldBeRedirection
◼️ ShouldHaveClientError
◼️ ShouldHaveServerError
◼️ ShouldHaveError