PlaywrightContrib.PageObjects 1.0.0

Contributions to Playwright for .NET 🎭🧪

✔️ PlaywrightContrib.PageObjects is a library for writing browser tests using the page object pattern with the Playwright API
✔️ It provides a convenient way to write readable and robust browser tests in .NET
✔️ Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast

Install-Package PlaywrightContrib.PageObjects -Version 1.0.0
dotnet add package PlaywrightContrib.PageObjects --version 1.0.0
<PackageReference Include="PlaywrightContrib.PageObjects" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PlaywrightContrib.PageObjects --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PlaywrightContrib.PageObjects, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install PlaywrightContrib.PageObjects as a Cake Addin
#addin nuget:?package=PlaywrightContrib.PageObjects&version=1.0.0

// Install PlaywrightContrib.PageObjects as a Cake Tool
#tool nuget:?package=PlaywrightContrib.PageObjects&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

PlaywrightContrib.PageObjects 🎭🧪

build CodeFactor

PlaywrightContrib.PageObjects is a library for writing browser tests using the page object pattern with the Playwright API.

using FluentAssertions;
using Microsoft.Playwright;
using PlaywrightContrib.FluentAssertions;
using PlaywrightContrib.PageObjects;
using System.Threading.Tasks;

var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();

var repoPage = await page.GotoAsync<GitHubRepoPage>("https://github.com/microsoft/playwright-dotnet");
var link = await repoPage.Link;
await link.Should().HaveContentAsync("playwright-dotnet");
await link.Should().HaveAttributeValueAsync("href", "/microsoft/playwright-dotnet");

var actionsPage = await repoPage.GotoActionsAsync();
var latestStatus = await actionsPage.GetLatestWorkflowRunStatusAsync();
latestStatus.Should().Be("This workflow run completed successfully.");

public class GitHubRepoPage : PageObject
{
    [Selector("h1 strong a")]
    public virtual Task<IElementHandle> Link { get; }

    [Selector("a span[data-content='Actions']")]
    public virtual Task<IElementHandle> Actions { get; }

    public async Task<GitHubActionsPage> GotoActionsAsync()
    {
        await (await Actions).ClickAsync();
        return await Page.WaitForNavigationAsync<GitHubActionsPage>();
    }
}

public class GitHubActionsPage : PageObject
{
    public async Task<string> GetLatestWorkflowRunStatusAsync()
    {
        var status = await Page.QuerySelectorAsync("#partial-actions-workflow-runs .Box-row div[title]");
        return await status.GetAttributeAsync("title");
    }
}

Extensions for IPage 📄

Where T is a PageObject:

  • GoToAsync<T>
  • RunAndWaitForNavigationAsync<T>
  • RunAndWaitForResponseAsync<T>
  • To<T>
  • WaitForNavigationAsync<T>
  • WaitForResponseAsync<T>

Where T is an ElementObject:

  • QuerySelectorAllAsync<T>
  • QuerySelectorAsync<T>
  • WaitForSelectorAsync<T>

Extensions for IElementHandle 📑

Where T is an ElementObject:

  • To<T>
  • QuerySelectorAllAsync<T>
  • QuerySelectorAsync<T>
  • WaitForSelectorAsync<T>

Would you like to know more? 🤔

Further documentation is available at https://github.com/hlaueriksson/playwright-dotnet-contrib

PlaywrightContrib.PageObjects 🎭🧪

build CodeFactor

PlaywrightContrib.PageObjects is a library for writing browser tests using the page object pattern with the Playwright API.

using FluentAssertions;
using Microsoft.Playwright;
using PlaywrightContrib.FluentAssertions;
using PlaywrightContrib.PageObjects;
using System.Threading.Tasks;

var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();

var repoPage = await page.GotoAsync<GitHubRepoPage>("https://github.com/microsoft/playwright-dotnet");
var link = await repoPage.Link;
await link.Should().HaveContentAsync("playwright-dotnet");
await link.Should().HaveAttributeValueAsync("href", "/microsoft/playwright-dotnet");

var actionsPage = await repoPage.GotoActionsAsync();
var latestStatus = await actionsPage.GetLatestWorkflowRunStatusAsync();
latestStatus.Should().Be("This workflow run completed successfully.");

public class GitHubRepoPage : PageObject
{
    [Selector("h1 strong a")]
    public virtual Task<IElementHandle> Link { get; }

    [Selector("a span[data-content='Actions']")]
    public virtual Task<IElementHandle> Actions { get; }

    public async Task<GitHubActionsPage> GotoActionsAsync()
    {
        await (await Actions).ClickAsync();
        return await Page.WaitForNavigationAsync<GitHubActionsPage>();
    }
}

public class GitHubActionsPage : PageObject
{
    public async Task<string> GetLatestWorkflowRunStatusAsync()
    {
        var status = await Page.QuerySelectorAsync("#partial-actions-workflow-runs .Box-row div[title]");
        return await status.GetAttributeAsync("title");
    }
}

Extensions for IPage 📄

Where T is a PageObject:

  • GoToAsync<T>
  • RunAndWaitForNavigationAsync<T>
  • RunAndWaitForResponseAsync<T>
  • To<T>
  • WaitForNavigationAsync<T>
  • WaitForResponseAsync<T>

Where T is an ElementObject:

  • QuerySelectorAllAsync<T>
  • QuerySelectorAsync<T>
  • WaitForSelectorAsync<T>

Extensions for IElementHandle 📑

Where T is an ElementObject:

  • To<T>
  • QuerySelectorAllAsync<T>
  • QuerySelectorAsync<T>
  • WaitForSelectorAsync<T>

Would you like to know more? 🤔

Further documentation is available at https://github.com/hlaueriksson/playwright-dotnet-contrib

Release Notes

Initial release 🎉

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 105 6/28/2021