Page Object Model

Knowledge Videos

Short animated explainers, organised by subject.

Page Object Model

Stop repeating locators across tests: put each page's locators and actions in a class, so tests read like manual steps and a UI change is fixed in one place.

Transcript

Imagine ten tests that all log in. Each one repeats the same locators. Then the Log in button is renamed to Sign in, and you have to fix ten files.

A page object puts everything about one page in one class. The locators, and the actions you can do on that page, like log in.

Now your test reads like a manual test case. Create the login page, call log in, then check the result. No locators in the test, just steps.

When the page changes, you edit one place, and every test is fixed. Keep the locators and actions in the page object, and keep the assertions in the tests.

Remember: one page, one class. Locators and actions live in the page object, and tests read like steps.

More in this series