Wszystkie Lokatory w Playwright

Główną rzeczą w pisaniu testów jest zlokalizowanie elementu na stronie. Do tego używamy Lokatorów (locators).

To ich pełna lista:

page.getByRole()		to locate by explicit and implicit accessibility attributes.
page.getByText()		to locate by text content.
page.getByLabel()		to locate a form control by associated label's text.
page.getByPlaceholder()	to locate an input by placeholder.
page.getByAltText()		to locate an element, usually image, by its text alternative.
page.getByTitle()		to locate an element by its title attribute.
page.getByTestId()		to locate an element based on its data-testid attribute (other attributes can be configured).

Proste użycie z wykorzystaniem zmiennej jest takie:

const locator = page.getByRole('button', { name: 'Sign in' });

await locator.hover();
await locator.click();

Dodaj komentarz