Open Exoow opened 11 months ago
I found the caveat though: when running more than 1 test, Playwright throws an exception because the selector is already registered...
Yes, there is currently no great way of adding a custom selector engine in .NET. TestInitialize
is too late.
What kind of selector engine are you creating? We learned that for most users the integrated selector engines are enough.
In TestInitialize
works after adding a try/catch so it won't fail from the second test onwards.
We have tests running against Microsoft Dynamics, and it's easiest to select components by data-dyn-role
or data-dyn-controlname
attributes.
So instead of css=[data-dyn-controlname=something]
I can write ddc=something
.
An alternative could be to write extension methods on IPage and ILocator for this, but I like the brevity of the custom selectors.
The documentation (both in code and https://playwright.dev/dotnet/docs/extensibility) states:
Selectors must be registered before creating the page.
However the code below works, in a
TestClass
inheriting fromPageTest
. Isn't the page already created when entering this method, given that actions are performed on it?