Playwright Awesome Selectors
Nov 19, 2022
Playwright selectors were already great but with the new release they have made it Aweeesomeeee.
Check out new and improved ways of selectors:
page.getByRole(role, options)
page.getByLabel(label, options)
page.getByPlaceholder(placeholder, options)
page.getByText(text, options)
page.getByAltText(altText, options)
page.getByTitle(title, options)
page.getByTestId(testId)
A quick comparison between before and after:
My personal favourite is:
page.getByRole(role, options)
eg:
await page.getByRole('button', { name: 'Sign in' }).click();
Tell me yours.