PuppeteerSharp.Contrib.Extensions
5.0.0
See the version list below for details.
dotnet add package PuppeteerSharp.Contrib.Extensions --version 5.0.0
NuGet\Install-Package PuppeteerSharp.Contrib.Extensions -Version 5.0.0
<PackageReference Include="PuppeteerSharp.Contrib.Extensions" Version="5.0.0" />
paket add PuppeteerSharp.Contrib.Extensions --version 5.0.0
#r "nuget: PuppeteerSharp.Contrib.Extensions, 5.0.0"
// Install PuppeteerSharp.Contrib.Extensions as a Cake Addin #addin nuget:?package=PuppeteerSharp.Contrib.Extensions&version=5.0.0 // Install PuppeteerSharp.Contrib.Extensions as a Cake Tool #tool nuget:?package=PuppeteerSharp.Contrib.Extensions&version=5.0.0
PuppeteerSharp.Contrib.Extensions
PuppeteerSharp.Contrib.Extensions
is a library with convenient extension methods for writing browser tests with the Puppeteer Sharp API.
Content
Installation
Extensions for Page
Query:
QuerySelectorWithContentAsync
QuerySelectorAllWithContentAsync
Evaluation:
HasContentAsync
HasTitleAsync
Extensions for ElementHandle
Attributes:
ClassListAsync
ClassNameAsync
GetAttributeAsync
HrefAsync
IdAsync
NameAsync
SrcAsync
ValueAsync
Content:
InnerHtmlAsync
InnerTextAsync
OuterHtmlAsync
TextContentAsync
Evaluation:
Exists
HasAttributeAsync
HasClassAsync
HasContentAsync
HasFocusAsync
IsCheckedAsync
IsDisabledAsync
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
{
Browser Browser { get; set; }
Page 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>
", new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } });
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 | Versions 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. |
-
.NETStandard 2.0
- PuppeteerSharp (>= 7.1.0)
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
|
⬆️ Bump PuppeteerSharp to 7.1.0