nightwatch icon indicating copy to clipboard operation
nightwatch copied to clipboard

Feat: Add `.print()` command in nightwatch.

Open Ayush-Vish opened this issue 9 months ago • 8 comments

Description

This command will return a PDF of the paginated pages, which will be helpful for the overall view of the website. This pdf will be shown in the respective HTML Report.

Suggested solution

No response

Alternatives / Workarounds

No response

Additional Information

No response

Ayush-Vish avatar Apr 28 '24 14:04 Ayush-Vish

@garg3133 Should I add this command in Nightwatch? It is there in the W3C webdriver.

Ayush-Vish avatar Apr 29 '24 04:04 Ayush-Vish

@Ayush-Vish Yes, it is a good idea to go ahead with it. All major the browsers support printing https://wpt.fyi/results/webdriver/tests/classic/print?label=master&label=experimental&aligned&view=subtest The Nightwatch print command can be mapped to the Selenium print command https://github.com/SeleniumHQ/selenium/blob/4f457b14e06cb28693a64750b4e6960b13ccbe4a/javascript/node/selenium-webdriver/lib/webdriver.js#L1176.

pujagani avatar May 22 '24 07:05 pujagani

@pujagani Definitely, I will come up with a solution to implement it.

Ayush-Vish avatar May 22 '24 11:05 Ayush-Vish

Nightwatch has a "method-mappings.js" class which maps Nightwatch methods to the underlying Selenium method. That might be a good place to start.

pujagani avatar May 22 '24 11:05 pujagani

@pujagani Absolutely, I'll definitely check that out!

Ayush-Vish avatar May 22 '24 12:05 Ayush-Vish

I am new to open source contributions. Can i try working on this issue??

TECH-NINJA06 avatar Jun 08 '24 06:06 TECH-NINJA06

I got this working by mapping to the printPage command from selenium webdriver inside method-mappings.js and exposing it through a lib/api/protocol command.

Some questions though, printPage outputs to a base64-encoded string. What do we want to ultimately do with it? For example, I can use fs and write that to a PDF file on the system. Would we use the screens folder from nightwatch.conf.js or allow the user to provide the save path in the command parameters? If we want to embed the PDF in the Nightwatch HTML report as @Ayush-Vish suggested in the original post here I would need to see some documentation on how to do that though.

@pujagani how do you think we should expose the output of the command? One of the options I suggested or something else?

reallymello avatar Jul 07 '24 02:07 reallymello

Thank you for helping out with this. "What do we want to ultimately do with it? For example, I can use fs and write that to a PDF file on the system" - I think this is a good idea. To write it to a PDF. Maybe we could use that screens folder if the user does not provide a path. What do you think about that?

Regarding the HTML reporter integration, it should be a separate set of changes. I honestly don't think there is a contributing doc for it. But you can probably follow the way the screenshot was handled there. There is a separate conf too for the screenshot. Maybe print page can have something similar.

pujagani avatar Jul 09 '24 05:07 pujagani