Playwright C# - Handling Common Components and Their Actions

116 views Asked by At

Overview

I am looking at transitioning away from an extensive C# Selenium project into PlayWright as a POC.

As part of this our application uses an internal component library which we automate through using selenium and a number of component classes which our testers just need to reference in their Page file along with the unique locator, which then exposes a number of actions available to them which can be performed on that component (some are simple, some have complex/multiple steps) which are all accessed via a method off the component(class).

For example:

Page

public readonly Input depositValue = Input.ByName("depositValue");

Steps

page.depositPercentage.EnterValue(10.00);

Question

In Playwright I would like to do something similar to this, making a centralised location for each component which can be maintained in one location.

The issues I have here are:

  • Some of our applications are contained in a master IFrame (IFrameLocator) where as others exist without an Iframe so can use IPage. Is there a way to make a generic Interface which would work for both of these examples?

  • the syntax for Playwright is very different to that we use for Selenium, I would like to make it so our components work in a similar flow to playwright's default language. Is this possible?

e.g. for Component X this would look like:

MyPage

ILocator fieldx = page.page.ComponentXLocator("unique locator"); <- Note this is usually a Data-TestId

Steps

await myPage.fieldx.SelectFromListAsync()

In an ideal world I would also like to surface all the built in ILocator interface actions here so users can still benefit from the Assertion Library and built in actions and not just the custom ones.

Any help with this would be fantastic. Playwright seems to have a lot of potential, but maintainability is key for us to reduce overhead when our component library (handled by another team internally) change their UI

Many thanks

0

There are 0 answers