PuppeteerSharp.Contrib.Extensions 6.0.0

dotnet add package PuppeteerSharp.Contrib.Extensions --version 6.0.0                
NuGet\Install-Package PuppeteerSharp.Contrib.Extensions -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.Extensions" 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.Extensions --version 6.0.0                
#r "nuget: PuppeteerSharp.Contrib.Extensions, 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.Extensions as a Cake Addin
#addin nuget:?package=PuppeteerSharp.Contrib.Extensions&version=6.0.0

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

PuppeteerSharp.Contrib.Extensions

build CodeFactor

PuppeteerSharp.Contrib.Extensions is a library with convenient extension methods for writing browser tests with the Puppeteer Sharp API.

Content

Extensions for IPage

Query:

  • QuerySelectorWithContentAsync
  • QuerySelectorAllWithContentAsync

Evaluation:

  • HasContentAsync
  • HasTitleAsync
  • HasUrlAsync

Extensions for IResponse

  • HasUrl

Extensions for IElementHandle

Attributes:

  • ClassListAsync
  • ClassNameAsync
  • GetAttributeAsync
  • HrefAsync
  • IdAsync
  • NameAsync
  • SrcAsync
  • ValueAsync

Content:

  • InnerHtmlAsync
  • InnerTextAsync
  • OuterHtmlAsync
  • TextContentAsync

Evaluation:

  • Exists
  • HasAttributeAsync
  • HasAttributeValueAsync
  • HasClassAsync
  • HasContentAsync
  • HasFocusAsync
  • IsCheckedAsync
  • IsDisabledAsync
  • IsEmptyAsync
  • IsEnabledAsync
  • IsHiddenAsync
  • IsReadOnlyAsync
  • IsRequiredAsync
  • IsSelectedAsync
  • IsVisibleAsync

Query:

  • QuerySelectorWithContentAsync
  • QuerySelectorAllWithContentAsync

Samples

Sample projects are located in the samples folder.

This is an example with NUnit:

using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using PuppeteerSharp.Contrib.Extensions;

namespace PuppeteerSharp.Contrib.Sample
{
    public class ExtensionsTests
    {
        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 Query()
        {
            await Page.SetContentAsync(@"
<html>
  <div id='foo'>Foo</div>
  <div id='bar'>Bar</div>
  <div id='baz'>Baz</div>
</html>");

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

            var div = await Page.QuerySelectorWithContentAsync("div", "Ba.");
            Assert.AreEqual("bar", await div.IdAsync());

            div = await html.QuerySelectorWithContentAsync("div", "Ba.");
            Assert.AreEqual("bar", await div.IdAsync());

            var divs = await Page.QuerySelectorAllWithContentAsync("div", "Ba.");
            Assert.AreEqual(new[] { "bar", "baz" }, await Task.WhenAll(divs.Select(x => x.IdAsync())));

            divs = await html.QuerySelectorAllWithContentAsync("div", "Ba.");
            Assert.AreEqual(new[] { "bar", "baz" }, await Task.WhenAll(divs.Select(x => x.IdAsync())));
        }

        [Test]
        public async Task Attributes()
        {
            await Page.SetContentAsync(@"
<html>
  <form method='post'>
      Name: <input type='text' name='name' id='name' required>
      Email: <input type='email' name='email' id='email' required>
      <input type='submit' value='Subscribe!'>
  </form>
  <img src='unsubscribe.png' />
  <a href='/unsubscribe/'>Unsubscribe</a>
</html>");

            var form = await Page.QuerySelectorAsync("form");
            Assert.AreEqual("post", await form.GetAttributeAsync("method"));

            var input = await Page.QuerySelectorAsync("#name");
            Assert.True(await input.HasAttributeAsync("required"));

            var link = await Page.QuerySelectorAsync("a");
            Assert.AreEqual("/unsubscribe/", await link.HrefAsync());

            input = await Page.QuerySelectorAsync("input[type=email]");
            Assert.AreEqual("email", await input.IdAsync());

            input = await Page.QuerySelectorAsync("#email");
            Assert.AreEqual("email", await input.NameAsync());

            var img = await Page.QuerySelectorAsync("img");
            Assert.AreEqual("unsubscribe.png", await img.SrcAsync());

            input = await Page.QuerySelectorAsync("input[type=submit]");
            Assert.AreEqual("Subscribe!", await input.ValueAsync());
        }

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

            var div = await Page.QuerySelectorAsync("div");
            Assert.AreEqual("foo bar", await div.ClassNameAsync());
            Assert.AreEqual(new[] { "foo", "bar" }, await div.ClassListAsync());
            Assert.True(await div.HasClassAsync("bar"));
        }

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

            var html = await Page.QuerySelectorAsync("html");
            Assert.True(await html.HasContentAsync("Foo"));

            var div = await Page.QuerySelectorAsync("div");
            Assert.AreEqual("\n    Foo\n    <span>Bar</span>\n  ", await div.InnerHtmlAsync());
            Assert.AreEqual("<div>\n    Foo\n    <span>Bar</span>\n  </div>", await div.OuterHtmlAsync());
            Assert.AreEqual("Foo Bar", await div.InnerTextAsync());
            Assert.AreEqual("\n    Foo\n    Bar\n  ", await div.TextContentAsync());
        }

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

            var div = await Page.QuerySelectorAsync("div");
            Assert.True(div.Exists());
            Assert.False(await div.IsHiddenAsync());
            Assert.True(await div.IsVisibleAsync());
        }

        [Test]
        public async Task Input()
        {
            await Page.SetContentAsync(@"
<form>
  <input type='text' autofocus required>
  <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]");
            Assert.True(await input.HasFocusAsync());
            Assert.True(await input.IsRequiredAsync());

            input = await Page.QuerySelectorAsync("input[type=radio]");
            Assert.False(await input.IsDisabledAsync());
            Assert.True(await input.IsEnabledAsync());
            Assert.True(await input.IsReadOnlyAsync());

            input = await Page.QuerySelectorAsync("input[type=checkbox]");
            Assert.True(await input.IsCheckedAsync());

            input = await Page.QuerySelectorAsync("#foo");
            Assert.True(await input.IsSelectedAsync());
        }
    }
}
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 (5)

Showing the top 5 NuGet packages that depend on PuppeteerSharp.Contrib.Extensions:

Package Downloads
PuppeteerSharp.Contrib.Should

Contributions to the Headless Chrome .NET API 🌐🧪 ✔️ PuppeteerSharp.Contrib.Should 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/

Rosie.Quality

Package Description

E13.Common.Nunit.Api

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

PuppeteerSharp.Contrib.Extensions.Unsafe

Contributions to the Headless Chrome .NET API 🌐🧪 ✔️ PuppeteerSharp.Contrib.Extensions.Unsafe is a library with extension methods for writing tests with the Puppeteer Sharp API. ✔️ It provides a convenient way to write readable and robust browser tests in .NET 📄 https://hlaueriksson.me/PuppeteerSharp.Contrib.Extensions.Unsafe/ ⚠️ These extension methods are the sync over async versions of the originals from the PuppeteerSharp.Contrib.Extensions 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

E13.Common.Nunit.UI

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

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on PuppeteerSharp.Contrib.Extensions:

Repository Stars
IvanJosipovic/BlazorTable
Blazor Table Component with Sorting, Paging and Filtering
Version Downloads Last updated
6.0.0 3,236 11/18/2023
5.0.0 11,989 8/9/2022
4.0.0 15,388 4/17/2021
3.0.0 12,701 9/13/2020
2.0.0 3,044 5/8/2020
1.0.0 21,647 1/9/2019

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

New extensions for IPage:
◼️ HasUrlAsync

New extensions for IElementHandle:
◼️ HasAttributeValueAsync
◼️ IsEmptyAsync

Extensions for IResponse:
◼️ HasUrl