microsoft / microsoft/playwright
[Feature] `locator.screenshot()` add option for expanding space captured around locator
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 96.3k
- Forks
- 6.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 180
Description
When creating visual regression tests(VRT) for a variety of elements it would be very helpful if the `locator.screenshot()` method had an option to add extra space around the locator.
This is particularly handy for testing `:focus-visible` CSS states that are actually outside the bounding box of the element. It would also be helpful for hover and active states that may go outside the element, likely other scenarios as well.
Example
```js
const button = page.locator('button');
await button.focus();
expect(await button.screenshot({ expandAreaBy: '20px' })).toMatchSnapshot(
'button-focused.png',
);
// Alternative option syntax
expect(await button.screenshot({ expandAreaBy: { value: 20, unit: 'px' } })).toMatchSnapshot(
'button-focused.png',
);
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the locator.screenshot() API and its screenshot implementation, then inspect existing screenshot option tests. Verify how focus-visible, hover, and active visuals can extend beyond the locator bounds, and add coverage showing that the requested expansion syntax captures the surrounding area as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100