storycap icon indicating copy to clipboard operation
storycap copied to clipboard

Expose setViewport on window

Open Jamie5 opened this issue 2 years ago • 2 comments

The request is to, in https://github.com/reg-viz/storycap/blob/master/packages/storycap/src/node/capturing-browser.ts , add to expose() another function, something like setViewport: (vp) => this.page.setViewport(vp), so that a test could do await window.setViewport(...)

Why?

We now have play functions, and hence UI interactions. These UI interactions may differ due to the size of the UI (i.e. responsive design might hide text when the window is narrow), which fundamentally goes to the window size. So it would be nice to be able to set the window size at the beginning of the test, rather than only when the screenshot happens. Otherwise play functions might become flaky and confusing.

Note that any other solution to the problem would be fine too - only that it would be strongly preferred for it to be possible to resize the viewport dynamically, rather than e.g. declaring in a test's parameters that it should have a given set of dimensions.

It might be possible to pass arguments to storycap to have a given viewport, but such a global option would not be preferred as individual tests might have individual viewports.

Jamie5 avatar Jul 13 '22 21:07 Jamie5

https://github.com/Jamie5/storycap/pull/1/commits/cff4d388903cebc908d2ebe2e3f7ba156af707ba works, though I imagine you would prefer to not just expose things on window itself. If this general feature is something you'd like to have I can work on something that is more wrapped properly, as it would be nice not to have to maintain forks and stuff.

Jamie5 avatar Jul 14 '22 16:07 Jamie5

I'm also interested in the ability to set the window size at the beginning of the test -- would it be possible to merge Jamie's change linked above?

throwandgo avatar Oct 03 '23 16:10 throwandgo