QA Interview Hub · Knowledge base · Quizzes · Українська

All topics

Patterns interview questions

32 questions on Patterns, from the basics to the hard ones. Answers and explanations are in the quiz and the knowledge base.

By level: Junior QA interview questions · Middle QA interview questions · Senior QA interview questions

Page Object Model

  1. What main problem does the Page Object Model solve? Junior
  2. Which split of assertions between the test and the Page Object is most often recommended in Playwright projects? Middle
  3. The check in this code sometimes fails even though the error appears on screen. Why? Middle
    async isErrorShown() {
      return this.error.isVisible();
    }
    
    // test
    await loginPage.login('a@b.com', 'bad');
    expect(await loginPage.isErrorShown()).toBe(true);

Take the quiz for this chapter · Read the explanation in the knowledge base

Page Component and composition

  1. What does a Page Component usually take in its constructor? Junior
  2. A page has two tables with the same structure and behaviour: active and archived payments. How is it best to describe them in a Page Object? Middle
  3. BasePage has a header and a menu, and all pages inherit it. A login page without a header was added. What is the problem? Middle
  4. The component is created for the active payments table, but the page also has an archived table. What will rows() return? Middle
    class DataTable {
      constructor(private root: Locator, private page: Page) {}
    
      rows() {
        return this.page.getByRole('row');
      }
    }

Take the quiz for this chapter · Read the explanation in the knowledge base

Fixtures as Dependency Injection

  1. What happens with this fixture? Senior
    export const test = base.extend<{}, { account: Account }>({
      account: [async ({ page }, use) => {
        const acc = await createViaUi(page);
        await use(acc);
      }, { scope: 'worker' }],
    });
  2. What is a fixture with { auto: true } appropriate for? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base

Builder and Test Data Builder

  1. What is the main idea of a Test Data Builder? Junior
  2. What will p1.amount be? Middle
    class PaymentBuilder {
      private data = { amount: 100, currency: 'EUR' };
      withAmount(a: number) { this.data.amount = a; return this; }
      build() { return this.data; }
    }
    
    const b = new PaymentBuilder();
    const p1 = b.build();
    const p2 = b.withAmount(0).build();
  3. A test checks a fee of 1% of the payment amount, and faker generates the amount. What is the main problem? Middle
  4. Tests run with workers: 4, and faker.seed() is never called. What happens to the users' emails? Senior
    class UserBuilder {
      static readonly DEFAULTS = { email: faker.internet.email() };
      private overrides: Partial<NewUser> = {};
    
      build() {
        return { ...UserBuilder.DEFAULTS, ...this.overrides };
      }
    }

Take the quiz for this chapter · Read the explanation in the knowledge base

Factory and data factories

  1. Why is Partial used in the factory createCard(overrides: Partial<Card> = {})? Junior
  2. What value will card.holder have? Middle
    function createCard(o: Partial<Card> = {}): Card {
      return { holder: 'TEST USER', expiry: '12/30', ...o };
    }
    
    const card = createCard({ holder: undefined });
  3. When is a Builder more appropriate than a simple factory function? Middle
  4. In Playwright Test, a factory returns the exported object DEFAULT_USER without copying it. One test does user.email = 'x@test.com'. What happens? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base

Facade, Steps and App Actions

  1. In which situation should you NOT use a steps layer (Facade)? Middle
  2. 200 tests need a logged-in user, but login is not what is being checked. What is the best way to do it? Middle
  3. What does the { box: true } option change in this step? Senior
    async sendMoney(to: string, amount: number) {
      return test.step(`send ${amount} to ${to}`, async () => {
        await this.transfer.fill(to, amount);
        await this.transfer.confirm();
      }, { box: true });
    }

Take the quiz for this chapter · Read the explanation in the knowledge base

Strategy

  1. What does the Strategy pattern describe? Junior
  2. How is it most natural in Playwright Test to choose a strategy implementation for different config projects? Middle
  3. A colleague suggests a BrowserStrategy with classes for Chromium, Firefox and WebKit. Your reaction? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base

Singleton and global state

  1. A module exports the variable let cache = {}. Tests run in 4 workers. How many copies of cache exist? Middle
  2. Why does the test see undefined instead of the token? Middle
    // global-setup.ts
    export default async function globalSetup() {
      (globalThis as any).token = await fetchToken();
    }
    
    // payments.spec.ts
    test('list', async ({ request }) => {
      const token = (globalThis as any).token; // undefined
    });
  3. What is the best replacement for a Singleton for a DB connection pool in Playwright? Middle
  4. For a pool of pre-created accounts, test.info().parallelIndex is chosen rather than workerIndex. Why? Senior
  5. A candidate says: I made a Singleton for the browser so as not to launch it in every test. What is wrong? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base

SOLID, DRY, KISS in tests, and anti-patterns

  1. What does the DAMP principle mean for tests? Junior
  2. What is the main problem with this code in a test? Middle
    if (await page.getByRole('dialog', { name: 'Promo' }).isVisible()) {
      await page.getByRole('button', { name: 'Close' }).click();
    }
    await checkout.pay();
  3. Which Page Object method violates Single Responsibility? Junior
  4. BasePage has this method, and all tests use it instead of locator.click(). What is wrong with it? Senior
    async click(locator: Locator) {
      await locator.click();
    }

Take the quiz for this chapter · Read the explanation in the knowledge base