grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
344 stars 41 forks source link

Implement `Page.pdf([options])` #106

Open robingustafsson opened 3 years ago

robingustafsson commented 3 years ago

Add support for Page.pdf([options]), to saving a page down to a PDF file.

Relevant links:

imiric commented 3 years ago

Unlike browser downloads (#98), which happen entirely on the browser side AFAIU, this would return the PDF data to the JS script, right? From there the user could upload the file somewhere or inspect it directly, but k6 can't write it to the filesystem, unless we use something like xk6-file, which would run into issues with more than one VU. I guess we could template the filename per VU, or something like that.

How do you envision this working @robingustafsson?

robingustafsson commented 3 years ago

Yes, it would be returned to the JS script (see Page.printToPDF()).

The user should be able to specify a path option to save the file to the filesystem, same as with Page.screenshot() and ElementHandle.screenshot(). This raises issues with disk writes while running the test, yes. We'll need to find a solution that would both work for the single VU functional test use case where writing to disk makes sense (but perhaps async off-thread) as well as when running in a load test with many VUs where writing directly to disk for every VU doesn't make as much sense.

Same situation for video capture in https://github.com/grafana/xk6-browser/issues/103.

Let's start with the use cases as I seem them:

I don't have a ready solution how to implement this in terms of APIs/options right now :sweat_smile: but I'm confident we can come up with something that will work.

robingustafsson commented 3 years ago

Perhaps @nicolevanderhoeven and @tom-miseur can fill in with more use cases for screenshots, videos, PDFs and downloads.

nicolevanderhoeven commented 3 years ago

+1 to everything Robin said. Some other use cases I can think of: