9

Is there a way to get a realtime view of what PhantomJS (or similar) is rendering?

I would like to develop my automation script while interacting with (or at least seeing a screencap of) the page it's targeted to.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
themirror
  • 9,963
  • 7
  • 46
  • 79
  • 2
    Can you use Selenium/webdriver instead? You can run tests in a similar way to phantomjs, but in real browsers. It now supports phantom as a browser so you can keep using it alongside (much slower) browsers. – joews Aug 05 '14 at 08:35

4 Answers4

3

No, there is no such thing. SlimerJS has the same API as PhantomJS, but runs the Gecko engine. You can see directly what is going on and run it headlessly with xvfb-run.

You will not be able to interact with it. You may want to use a screengrabber to record a video of the interaction when the tests are long and you don't want to run the test suite again if you didn't catch the problem in the test case.


The obvious way to debug PhantomJS scripts is to render many screenshots using page.render() and logging some objects to the console with

console.log(JSON.stringify(yourObj, undefined, 4));

with nice formatting.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
1

Solution we use is an automatic screenshoting in case of exceptions, phantomJs will render the current page into a file that you can exam later .

That's for test execution phase.

When you writing the tests, just keep additional window open ("normal browser") with the application you trying to test and design the test according to it.

When the design is done, execute the test with phantomJS.

Johnny
  • 14,397
  • 15
  • 77
  • 118
  • The bad thing is that you have a *lot* of screenshots to go through and piece together to understand what's going on. The good thing is that you have all the time in the world to look for issues in those screenshots when something isn't going to plan. This is hard to do with a automated browser window like in my answer. – Artjom B. Aug 05 '14 at 09:13
0

My Suggestion is to use logging alongside. http://casperjs.org/

CasperJS is an open source navigation scripting & testing utility written in Javascript for the PhantomJS WebKit headless browser and SlimerJS (Gecko). It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar for doing common tasks such as:

  • defining & ordering browsing navigation steps
  • filling & submitting forms
  • clicking & following links
  • capturing screenshots of a page (or part of it)
  • testing remote DOM
  • logging events
  • downloading resources, including binary ones
  • writing functional test suites, saving results as JUnit XML
  • scraping Web contents
Abs
  • 3,902
  • 1
  • 31
  • 30
0

The solution to this problem is using the remote debugger:

--remote-debugger-port=9000

Using slimerjs for testing scripts with a browser is not advisable since it is based on gecko, which means the script might work on slimerjs and not on phantomjs or viceversa.

take a look at this guide for more info... https://drupalize.me/blog/201410/using-remote-debugger-casperjs-and-phantomjs

untore
  • 603
  • 8
  • 16