Repository navigation
feat: leave elements out of a shot with hide - #7
Conversation
guide.shot takes hide: locators whose elements are left out of the shot with display: none, for data chosen by content such as rows other tests created. A locator may match no element or several. The rule goes into the page instead of the screenshot's style, so the crop is measured with the elements gone. The README gains a recipe on keeping shots stable between runs.
An injected <style> is blocked by a strict CSP and does not reach shadow roots or frames, which locators do. Set each matched element's inline display instead, restore the same elements in reverse order after the shot, and leave no empty style attribute behind.
IzumiSy
left a comment
There was a problem hiding this comment.
Approving this PR, as I think the hide option is useful. That said, if the goal is to control which data appears in the UI, shouldn't we allow each test to configure its seed or mock data instead, rather than hiding unwanted rows during screenshot capture?
|
Thanks @IzumiSy! Agreed: keeping each test's data apart is the real fix, and I did not add a seed or mock mechanism to e2g itself, since guides are plain Playwright tests and fixtures and |
Summary
guide.shottakes a newhideoption: locators whose elements are left out of the shot withdisplay: none.maskkeeps an element's box and paints over it, which suits values that change in place. Some elements should not be in the shot at all, such as rows that other tests or earlier runs created. Locale projects that run in parallel against one backend see each other's data, so these rows come and go between runs and change the image every time. A masked row would still leave a grey row behind.elementHandles), unlike a highlight.displayis set tonone, rather than adding a stylesheet:styleonly while the shot is taken, so the crop would be measured with the elements still there and land in the wrong place.<style>would be blocked by a strict CSP (setting astyleproperty directly is not), and would not reach shadow roots or frames, which locators do.displayback, in reverse order so an element matched twice ends up as it was, even if the locators match other elements by then. An element that had nostyleattribute is left without one. If hiding fails partway, the elements hidden so far are restored.display: ... !importantwins over the inline value; hide such an element withstyle.Docs
hideis added to theguide.shotoptions table and example.mask,hideandstyle.Test plan
pnpm test: 161 passedpnpm run test:browser: 120 passed, including three newcaptureShottests: hidden elements come back as they were (an inlinedisplay, an element matched twice, no leftoverstyleattribute); a shadow root; several matches, with the crop measured without thempnpm run typecheck,pnpm run lint,pnpm run check:pkg