nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

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

Open Ayush-Vish opened 5 months ago

Ayush-Vish commented 5 months ago

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 commented 5 months ago

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

pujagani commented 4 months ago

@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.

Ayush-Vish commented 4 months ago

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

pujagani commented 4 months ago

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

Ayush-Vish commented 4 months ago

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

TECH-NINJA06 commented 3 months ago

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

reallymello commented 2 months ago

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?

pujagani commented 2 months ago

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.