Skip to content

Repository files navigation

Power Playwright

Power Playwright makes test automation for Power Apps easier by providing a page object model built on top of Playwright.

  • All regions supported
  • Resilient to platform updates
  • Extensible for custom pages and controls

Table of Contents

Prerequisites

You will need a test project setup with Playwright.

Installation

Install the NuGet package in your test project:

dotnet add package PowerPlaywright

Usage

Create an instance of IPowerPlaywright. You can reuse a single instance across your test suite:

var powerPlaywright = await PowerPlaywright.CreateAsync();

You can use this to create instances of IModelDrivenApp by providing the Playwright IBrowserContext (refer to the Playwright docs) along with the environment url, app unique name, and credentials:

var homePage = await powerPlaywright.LaunchAppAsync(this.Context, environmentUrl, appUniqueName, username, passsword)

This will return a generic IModelDrivenAppPage that provides access to functionality common across all app pages (e.g. the site map). If you know the type of home page then you can pass the type as an argument:

var listPage = await powerPlaywright.LaunchAppAsync<IEntityListPage>(this.Context, environmentUrl, appUniqueName, username, passsword)

Pages

Writing tests with Power Playwright involves interacting with page and control interfaces.

Page interfaces model the different pages available within model-driven apps (documented here). These page interfaces provide you with the relevant controls.

At the time of writing, the supported pages are:

  • Dataverse form (IEntityRecordPage)
  • Dataverse table (IEntityListPage)
  • Dashboard (IDashboardPage)
  • Custom page (ICustomPage)
  • Web resource (IWebResourcePage)

You should pass one of these interfaces as a type argument when calling methods that return a page.

Custom pages

You can create a custom page by creating a sub-class of the CustomPage class and adding properties with public getters to represent its controls. These getters should be implemented using the inherited GetControl method.

At present, there are no canvas app controls included in Power Playwright. This means you will need to implement these controls as custom controls.

Controls

Controls are accessible via properties on the pages. For example, an IEntityListPage page exposes a Grid control property that provides access to the grid control:

var recordPage = await listPage.Grid.OpenRecordAsync(0);

In addition, some controls are accessible by interacting with other controls. For example, an IEntityRecordPage page exposes a Form control property with a GetControl method:

var readOnlyGrid = recordPage.Form.GetControl<IReadOnlyGrid>(pp_Record.Forms.Information.RelatedRecordsSubgrid);

Control classes

In most cases, PCF controls are added to forms as control classes rather than specific controls. This means that the actual PCF control that gets rendered on the form can change over time.

You can retrieve form controls by specifying either a control class or a specific control. These can be found in the PowerPlaywright.Framework.Controls.Pcf.Classes and PowerPlaywright.Framework.Controls.Pcf namespaces respectively.

This subgrid has been added without configuring a specific control:

var subGrid = recordPage.Form.GetControl<IReadOnlyGrid>(pp_Record.Forms.Information.RelatedRecordsSubgrid);

This subgrid has been added with the PowerAppsOneGrid control explicitly configured:

var subGrid = recordPage.Form.GetControl<IPowerAppsOneGridControl>(pp_Record.Forms.Information.RelatedRecordsSubgrid); 

Custom controls

Power Playwright can be extended by consumers to support their own custom controls or controls that have not yet been implemented by Power Playwright. To add additional controls, pass the names of your assemblies containing the controls to the PowerPlaywright.CreateAsync method.

PowerPlaywright.CreateAsync(
  new PowerPlaywrightConfiguration 
  {
    PageObjectAssemblies = [new() { Path = "Company.Project.PageObjects.dll" }] 
  });

For information on implementing controls, refer to CONTRIBUTING.md.

Contributing

Please refer to the CONTRIBUTING.md.

About

A Playwright-based library that provides robust test automation for Power Apps.

Resources

Contributing

Stars

13 stars

Watchers

6 watching

Forks

Releases

Packages

Contributors

Languages