![]() |
VOOZH | about |
dotnet add package PuppeteerSharp.Contrib.Should --version 7.0.0
NuGet\Install-Package PuppeteerSharp.Contrib.Should -Version 7.0.0
<PackageReference Include="PuppeteerSharp.Contrib.Should" Version="7.0.0" />
<PackageVersion Include="PuppeteerSharp.Contrib.Should" Version="7.0.0" />Directory.Packages.props
<PackageReference Include="PuppeteerSharp.Contrib.Should" />Project file
paket add PuppeteerSharp.Contrib.Should --version 7.0.0
#r "nuget: PuppeteerSharp.Contrib.Should, 7.0.0"
#:package PuppeteerSharp.Contrib.Should@7.0.0
#addin nuget:?package=PuppeteerSharp.Contrib.Should&version=7.0.0Install as a Cake Addin
#tool nuget:?package=PuppeteerSharp.Contrib.Should&version=7.0.0Install as a Cake Tool
PuppeteerSharp.Contrib.Should is a should assertion library for the Puppeteer Sharp API.
IPageIResponseIElementHandleIPageShouldHaveContentAsyncShouldHaveTitleAsyncShouldHaveUrlAsyncShouldNotHaveContentAsyncShouldNotHaveTitleAsyncShouldNotHaveUrlAsyncIResponseShouldBeRedirectionShouldBeSuccessfulShouldHaveClientErrorShouldHaveErrorShouldHaveServerErrorShouldHaveStatusCodeShouldHaveUrlShouldNotHaveStatusCodeShouldNotHaveUrlIElementHandleShouldBeCheckedAsyncShouldBeDisabledAsyncShouldBeEmptyAsyncShouldBeEnabledAsyncShouldBeHiddenAsyncShouldBeReadOnlyAsyncShouldBeRequiredAsyncShouldBeSelectedAsyncShouldBeVisibleAsyncShouldExistShouldHaveAttributeAsyncShouldHaveAttributeValueAsyncShouldHaveClassAsyncShouldHaveContentAsyncShouldHaveFocusAsyncShouldHaveValueAsyncShouldNotBeCheckedAsyncShouldNotBeEmptyAsyncShouldNotBeReadOnlyAsyncShouldNotBeRequiredAsyncShouldNotBeSelectedAsyncShouldNotExistShouldNotHaveAttributeAsyncShouldNotHaveAttributeValueAsyncShouldNotHaveClassAsyncShouldNotHaveContentAsyncShouldNotHaveFocusAsyncShouldNotHaveValueAsyncThe 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".
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. 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. |
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 |
This package is not used by any popular GitHub repositories.
๐ฏ Change TargetFramework to net8.0
โฌ๏ธ Bump PuppeteerSharp to 20.0.0