Home > Casper On > Casper On Error

Casper On Error

are basically ways to alter values asynchronously. Events¶ Using casperjs exit events is pretty much straightforward if you're a node

Casperjs Try Catch

developer, or if you worked with any evented system before: var casper = casperjs fail fast require('casper').create(); casper.on('resource.received', function(resource) { casper.echo(resource.url); }); Emitting you own events¶ Of course you can emit your own events, using the Casper.emit() casperjs waitfor method: var casper = require('casper').create(); // listening to a custom event casper.on('google.loaded', function() { this.echo('Google page title is ' + this.getTitle()); }); casper.start('http://google.com/', function() { // emitting a custom event this.emit('google.loaded'); }); casper.run(); Removing events¶ You can also remove events. This is particularly useful when

Casperjs Onresourcereceived

running a lot of tests where you might need to add and remove different events for different tests: var casper = require('casper').create(); // listener function for requested resources var listener = function(resource, request) { this.echo(resource.url); }; // listening to all resources requests casper.on("resource.requested", listener); // load the google homepage casper.start('http://google.com/', function() { this.echo(this.getTitle()); }); casper.run().then(function() { // remove the event listener this.removeListener("resource.requested", listener); }); Here is an example of how to use this in a casperjs test within the tearDown function.: var currentRequest; //Resource listener function onResourceRequested(requestData, request) { if (/\/jquery\.min\.js/.test(requestData.url)) { currentRequest = requestData; } } casper.test.begin('JQuery Test', 1, { setUp: function() { // Attach the resource listener casper.on('resource.requested', onResourceRequested); }, tearDown: function() { // Remove the resource listener casper.removeListener('resource.requested', onResourceRequested); currentRequest = undefined; }, test: function(test) { casper.start('http://casperjs.org/',

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn casperjs onerror more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags casperjs onresourcerequested Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.3 million programmers, just like you,

Casperjs Log To File

helping each other. Join them; it only takes a minute: Sign up Catch and Handle CasperError up vote 5 down vote favorite Using CasperJS how do I catch and handle CasperError? The default appears to continue execution of http://docs.casperjs.org/en/latest/events-filters.html the program (which does nothing but propagates the error). These errors are logged to the console/stdout but I don't seem to see a way (from the docs) to catch and handle these errors. Example: this.fillSelectors(selector, data); May produce: CasperError: Errors encountered while filling form: form not found I know I can check to make sure everything exists before calling, but is there a way to catch after the fact? (this applies to many other operations like http://stackoverflow.com/questions/20480536/catch-and-handle-caspererror casper.click as well) casperjs share|improve this question edited Jun 27 '14 at 13:50 Artjom B. 41.5k154975 asked Dec 9 '13 at 20:52 arcyqwerty 5,38311854 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote accepted I use something currently like this: casper.on('error', function(msg,backtrace) { this.capture('./out/error.png'); throw new ErrorFunc("fatal","error","filename",backtrace,msg); }); and then I have a custom function ErrorFunc to process array of any warnings or a fatal error. If you have an unsuccessful click it should throw the casper.on('error'). So you can put custom code there for how you would like to handle the error. Here's the documentation for Casper events. share|improve this answer edited Jan 23 at 23:21 mikemaccana 22.8k23147204 answered Dec 9 '13 at 21:41 Topher Ellis 9711610 Hm, this is not working for me. I can not catch anything. –MrD Jul 27 '15 at 8:15 add a comment| up vote 0 down vote var casper = require('casper').create({ onError: function(msg, backtrace) { this.capture('error.png'); throw new ErrorFunc("fatal","error","filename",backtrace,msg); } }); This works pretty well. (See http://docs.casperjs.org/en/latest/modules/casper.html#index-1) share|improve this answer answered May 2 at 16:36 zziemke 82 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your an

(Brasil)DeutschInscriptionConnexionMessengerFacebook LiteMobileRetrouver des amisBadgesPersonnesPagesLieuxJeuxLieuxCélébritésGroupesMomentsInstagramÀ proposCréer une publicitéCréer une PageDéveloppeursEmploisConfidentialitéCookiesChoisir sa pubConditions d’utilisationAideParamètresHistorique Casper On personnel Facebook © 2016

website statistics