Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ayush-Vish opened this issue Apr 28, 2024 · 8 comments
Open

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

Ayush-Vish opened this issue Apr 28, 2024 · 8 comments

Comments

@Ayush-Vish
Copy link
Contributor

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
Copy link
Contributor Author

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

@pujagani
Copy link
Member

@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
Copy link
Contributor Author

Ayush-Vish commented May 22, 2024

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

@pujagani
Copy link
Member

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
Copy link
Contributor Author

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

@TECH-NINJA06
Copy link

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

@reallymello
Copy link
Contributor

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
Copy link
Member

pujagani commented Jul 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants