PhantomJS, but not headless?

北慕城南 提交于 2019-12-23 07:39:04

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



回答4:


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



来源:https://stackoverflow.com/questions/24769471/phantomjs-but-not-headless

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!