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

QA Fundamentals › Web and client-server

The DOM, layout and responsiveness

The DOM is the tree of page elements, and the browser recomputes layout each time from width, content and state. So that input space is explored: widths on both sides of a breakpoint (such as 767 and 768), extreme content (empty value, long word, translation), states (hover, focus, disabled, error), zoom and keyboard. An element can be in the DOM yet invisible, and the tolerance against the mockup is agreed beforehand.

QA Fundamentals · Web and client-server

In the mockup a long name fits, in production it breaks the card. How do you check layout systematically?

In Figma a user card looks perfect: the name "Olena", an avatar, a button. In production "Oleksandra-Viktoriia Kovalenko-Shevchenko" appears, and the name runs over the button. The designer and the developer are right that the mockup was reproduced. It is just that the mockup shows one width and ideal data, and a real screen has neither. This lesson is about what the DOM is, why the same page looks different, and which inputs (width, content, states) are worth going through so that the layout does not fall apart.

How it works and why. The browser reads the HTML and builds the DOM: a tree of nodes where each tag becomes an element, and JavaScript can change this tree and with it what the user sees. Then the browser combines the DOM with CSS styles and computes the position of every element (layout): the size depends on the available width of the parent, the content, the margins and the rules. So the layout is not drawn once but computed every time the window width, the content or the state changes. The main conclusion: checking one screen with one data set is one point out of many.

Widths to check

320 px · small phone768 px · tablet (edge: 767 and 768)1024 px · small laptop1440 px · monitor
Figure 1. Four typical widths to start with. Real breakpoints are taken from the project's CSS (they can be learned from developers or in the styles), and they are checked on both sides of the edge.

Two more dimensions complete it: content and state. Content: an empty value, a very long word without spaces, a long text, big numbers, emoji, a translation into another language (Ukrainian words are often longer than English ones). Element state: normal, hover, focus, active, disabled, error, loading, an empty list. They can be forced in Elements through forced state (Force state: :hover, :focus). Together width, content and state form the space of inputs in which the layout breaks: the same principle as in test design techniques, only for appearance.

A few facts about the DOM that are useful to QA. "View source" shows the HTML the server returned, and Elements shows the live DOM after scripts have run: for modern applications these are different things. An element can be in the DOM but invisible to the user: display: none, visibility: hidden, zero size, moved off the screen, covered by another element. Automated tests also distinguish presence from visibility: for example, Playwright considers an element visible if it has a non-empty bounding box and no visibility: hidden, and an element with opacity: 0 is considered visible. Locators in automated tests rely on the DOM: a role, a label and data-testid are more stable than nesting depth or classes that change with the layout.

Example: from "the layout is shifted" to a report. The complaint "the card is shifted" says nothing. After going through the inputs (narrowing the window to 375 px, inserting a long name) the bug can be described so that it is reproduced and fixed:

Before: "The product card got shifted".

After:
Title: [Catalog] A long name without spaces sticks out of the card
Environment: Chrome, window width 375 px (Device toolbar)
Steps: open a product with a name of 46 characters without spaces
Actual: the name sticks out past the right edge of the card and
  a horizontal page scroll appears
Expected: the name wraps or is cut with "…" (the Figma mockup
  "Card / Mobile", the rule for long names)
Hypothesis: in Elements .card-title has the computed white-space: nowrap

The "Hypothesis" line makes reproduction faster: Elements shows the computed styles, and the developer at once sees the rule because of which the text does not wrap. The mark about a hypothesis matters: it does not claim a diagnosis but only hints where to look. For comparison with the mockup we use the box model panel in Elements (sizes, padding, border, margin) and the Figma Inspect tool. Beforehand we agree on the tolerance: whether an exact pixel match is needed or deviations within a few pixels are acceptable. Without that every remark turns into an argument.

What to checkHow
Margins, fonts, colours, sizes against the mockupElements: Computed and the box model, Figma Inspect
Extreme contentAn empty value, a word without spaces, 200 characters, big numbers, another language
Element statesHover, focus (the Tab key), disabled, error, loading, empty state
Widths and breakpoint edgesDevice toolbar: 320, 768, 1024, 1440 and values on both sides of an edge, for example 767 and 768
Zoom and orientation200% zoom, a font size change, rotating the screen
KeyboardThe Tab order, a visible focus, reachability of all actions

Limits and alternatives. Width is handled by breakpoints, and they are only approximate classes of devices: a real phone in landscape or a foldable screen can land in an unexpected range, so intermediate widths are checked too. Edge values (767 and 768) catch off-by-one errors in media queries, like boundary values in test design. Responsiveness under accessibility requirements has its conditions as well: under WCAG 2.1 (the Reflow criterion) content must rearrange into one column at a width of 320 CSS pixels without two-dimensional scrolling, that is, at a large zoom. Visual regression tests (screenshots, Percy, Applitools or toHaveScreenshot in Playwright) catch a layout shift between builds, but give noise from fonts and animations, and a new design is still judged by a person. Right-to-left scripts or very long words may also be in the requirements. Finally, not every difference from the mockup is a defect: small deviations are agreed with the designer and recorded as a decision.

Common mistakes.

  • Checking only one "convenient" width and one "convenient" data set.
  • Resizing a desktop browser window and calling it a phone check.
  • Ignoring states: hover, focus, disabled and errors break more often than the normal look.
  • Writing "the layout is shifted" without the width, the data and a link to the mockup or the requirement.
  • Confusing an element's presence in the DOM with its visibility for the user.

Check yourself

An element is in Elements but the user does not see it. Name three causes.

Answer

For example: display: none or visibility: hidden; zero size or a colour that matches the background; the element is moved off the screen or covered by another element (z-index, an overlay). Each can be checked in Elements by the computed styles and the box model.

The CSS breakpoint is 768 px. Which widths do you check and why?

Answer

At least 767 and 768, that is, on both sides of the edge, because errors in media queries are often off by one (less than or at most). Plus the typical 320 and 1024 for the ends of the ranges.

Why is "View source" not suitable for seeing the current state of a page?

Answer

It shows the HTML that came from the server. The live DOM after JavaScript has run (added elements, changed text, attributes) is visible in Elements. For modern SPAs these two pictures differ a lot.

In an interview. Junior: The DOM is a tree of the HTML document in the browser's memory, controlled by JavaScript, and locators in automated tests work with it. I compare the layout with the mockup: margins, fonts, colours, sizes. I look at responsiveness in Device mode on several widths and on real devices. Middle/Senior: The layout is computed from width, content and state, so I go through this space: widths on both sides of breakpoints, extreme content (empty, a long word, a translation), states (hover, focus, disabled, error, loading), zoom and the keyboard. I agree the pixel tolerance beforehand. In a report I give the width, the data and a link to the mockup, and I mark the cause from Elements as a hypothesis. For regression screenshot tests can be used, but a person judges what is new.

More articles in this chapter