18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
How to take screenshot in PhantomJS?
Best Answer
-
Well, thats a tricky one, it is possible though.
Have a look at http://phantomjs.org/documentation/ there you will find something on how to take screenshots. The tricky part is telling when to take the screenshot.
You may use the web server module. http://phantomjs.org/api/webserver/
Just create a server which when requested will take a screenshot. In Sahis onScriptFailure _execute() a script which calls the phantomjs server (e.g. on linux with wget or curl).
Would this be a solution for you? And could you please post an example here when you get it to run?
Regards
Wormi

Answers
m not able to proceed, I need more help on this topic as phantomjs people are telling there is no such option and should use SlimerJS as it has the bowser window on-screen option.
please suggest some other way
Thank You
It's all in the docs:
https://github.com/ariya/phantomjs/wiki/API-Reference-WebServer
http://phantomjs.org/screen-capture.html
http://daker.me/2013/07/testing-your-responsive-design-with-phantomjs.html
and that's all you should need to figure it out.
I could write you all the code that's needed, but I would consider this work and would charge you for that. If that's ok for you, send me a mail and we talk rates.
Regards
Wormi
phantomjs takes url of the page to take screenshot? what if this page requires authentication? phantonjs will not have that when it opens that url. There will be session going on in your current browser with particular jsessionid. I have done lot of research on this. i dont think you can take sceen capture of errored out page from your current browser window using phantomjs.
To take a screenshot, you just call page.render(). The naviagtion is provided by sahi which also handles authentication.
Ok so some code:
phantomjs (sahi.js) script: browser.xml:
now when running a suite, a screenshot from every site will be taken and written to /tmp.
And as I said, it's all in the doc, there are blogposts about this etc. Why should this not work?