QA Interview Hub · Knowledge base · Quizzes · Українська
19 Patterns questions that come up in QA interviews, with short answers. Open the topic in the knowledge base for a deeper explanation.
A Page Object is a class that encapsulates the locators and actions of one page or logical screen. I pass page into the constructor, declare the locators as readonly fields and write async methods with business names, for example login(email, password). Locators in Playwright are lazy, so it is safe to create them in the constructor before the page opens. The main benefit is that when the UI changes, I fix one place, and the tests read like a scenario.
I keep business checks in tests, because the test decides what to verify, and that way the purpose of the scenario is visible at once. In a Page Object I allow only state-waiting methods, for example expectLoaded(), which waits for the page heading. Methods like verifyTotalIs100() in a PO hide the point of the test and are poorly reusable. I also don't return a boolean from a PO through isVisible(), but give the test the locator for a web-first check.
A Page Component describes not a whole page, but a repeating block: a header, a table, a modal, a date picker. It takes a root Locator in its constructor and builds all inner locators from it. So one DataTable class can be used on different pages and even twice on one, for example for active and archived payments. A Page Object then simply consists of such components.
Deep hierarchies like BasePage, AuthPage, AdminPage become brittle over time: a change in the base breaks everything, and to understand a method you have to go through several files. Besides, a login page without a header still inherits the header. With composition a page has component fields, for example readonly header = new Header(...), and takes only what it really has. A base class, if there is one, should be very thin.
A test declares in its arguments what it needs, and the runner creates those objects, passes them in and then cleans up. I add my own fixtures through test.extend, for example registering Page Objects and API clients there. The code before use is setup, the code after use is teardown, and it runs even if the test failed. Fixtures are lazy, so only what the test actually requested is created.
A test fixture is created anew for every test, while a worker fixture is one per worker process and lives between the tests of that worker. I use worker scope for expensive and immutable things: a service token, a DB connection pool. Everything a test can change, for example a test account, I make a test fixture with cleanup after use. A worker fixture can't depend on test fixtures like page.
A BaseTest with beforeEach creates everything for all tests, while fixtures are lazy and created only on request. Each test gets its own instances, so there are no shared fields that can be accidentally corrupted. Teardown is guaranteed, and fixtures combine through extend and mergeTests, whereas a base class can be inherited only once. I leave beforeEach for simple steps within one file.
A builder creates an object with valid default values, and the test changes only what is important for the scenario, for example new PaymentBuilder().withAmount(0).failed().build(). That way the point of the test is visible at once, and I add a new required field in one place. The methods return this for chaining, and build() returns a copy so as not to share a mutable object. For objects with two or three fields I don't make a Builder, because a factory with Partial is enough.
I use faker for unique fields like email or a name, so parallel tests don't conflict. But the values that a check depends on, for example the amount for a fee calculation, I set explicitly. The main risk is non-reproducibility, so I log the generated data or use faker.seed(). I also watch that a default isn't generated in a static constant, otherwise all the worker's tests get the same email.
Most often it is a function with defaults and a parameter overrides: Partial<T> that returns { ...defaults, ...overrides }. It is short and type-safe: TypeScript won't let you pass a field that isn't in the type. There is also a factory that creates an entity through the API with request, and I wrap that in a fixture for cleanup. It is important that a factory always returns a new object, not a shared constant.
A Factory is one function with parameters, a Builder is a fluent chain of methods. I take a factory for simple and medium objects where overriding a few fields is enough. I choose a Builder when the object is complex and there are many variations, because methods like failed() or inForeignCurrency() read like a domain language. In practice they are often combined: a Builder takes its defaults from a factory.
A Facade combines several Page Objects and API calls into one business action, for example sendMoney(from, to, amount). I wrap such methods in test.step, so the report and trace show a business step, not a set of clicks. I use it for preconditions and repeated paths. If a test verifies exactly this action, it works with the page directly, so the check isn't hidden.
In the narrow sense App Actions means calling the application's internal actions directly, for example through an object on window; more broadly, any preparation of state around the UI, including through the API. I log in once in a setup project and save the state to a file, and the tests pick it up through storageState. I create test data through the request fixture with cleanup. Through the UI I go only through what the test actually verifies, plus a few end-to-end smoke scenarios.
A classic example is the login method: there is an interface LoginStrategy and the implementations UiLogin and ApiLogin. The test doesn't know how the login happened, it just depends on the loggedIn fixture. Which strategy to use is decided by an option fixture, whose value I set in projects or through test.use. A new method, for example SSO, is added as a new class without changes in the tests.
If there are only two variants and no new ones are expected, a simple if in the fixture is more honest than an interface and three classes. If the difference is a single parameter, passing a parameter is enough. For different browsers and devices I don't write my own strategy, because Playwright already does this through projects and devices. Strategy is needed when there is real polymorphism and the implementations evolve independently.
Each Playwright worker is a separate Node process that loads modules anew. So a module-level singleton exists separately in each worker, and with workers: 4 there will be four instances. There is no shared state between workers, and the variables from globalSetup aren't visible to tests, because it is also a separate process. I pass data from there through a file, environment variables or storageState.
Page Object hides a page’s locators and actions in a class, so after a markup change the code is fixed in one place. Factory creates objects by type (for example a driver for a browser), and Builder assembles complex test data step by step: new UserBuilder().withRole('admin').build(). Fixtures and dependency injection prepare state and resources for a test and clean them up afterwards. Strategy swaps an algorithm without changing the code that calls it, say different ways to log in. Singleton gives one shared instance, but I use it carefully in parallel runs. The common goal: less duplication and easier maintenance.
DRY says remove duplication, DAMP says a test must be understandable on its own even at the cost of repetition. I apply DRY to infrastructure: locators, steps, fixtures, factories. And in the body of a test I leave the input data and expectations visible, so you don't have to open other files. A test like runScenario(SCENARIOS[3]) is formally DRY, but it is impossible to read.
Most often these are god page objects, deep page inheritance, shared mutable state between tests and waitForTimeout instead of web-first assertions. I also saw wrappers over click() with no value and if (isVisible) in tests, which makes them non-deterministic. I fixed this with components, fixtures, isolated data for each test and expect with auto-retry. For example, moving login to storageState noticeably cut the run time.