I am currently working on creating end-to-end tests using PhantomJS and CasperJS. I came across a situation where PhantomJS lacks promises. Our project is currently implementing them. The application is used only in Google Chrome, which supports promises natively.
When I run my tests, I get the error message: Error: ReferenceError: cannot find the variable: Promise
It looks like the current version of Webkit in PhantomJS does not support promises. I understand that SlimerJS has this support through Gecko, however our application works in Chrome, and therefore I would like the tests to run in Webkit.
What I was struggling with was inserting the ES6 polyfill promise into Phantom so that the test passes correctly. I used both Casper JS injectjs and casper.options.clientScripts.push - both seem to return this lack of support for the promises problem.
I noticed that others have stated in support of github from CasperJS that they got it to work through polyfill, but I'm not sure how they did it, as examples are not provided.
I have included an example of my current script. If someone dealt with this problem and found a way to solve this problem, it would be very helpful. Thank you in advance!
casper.test.begin('Example test loading', 3, function(test) { casper.options.clientScripts.push("node_modules/es6-promise/es6-promise.js"); casper.start('http://localhost:8080/', function() { this.captureSelector('stuff.png', 'html'); }); casper.on("remote.message", function(msg) { this.echo("Console: " + msg); }); casper.on("page.error", function(msg, trace) { this.echo("Error: " + msg); }); casper.on("resource.error", function(resourceError) { this.echo("ResourceError: " + JSON.stringify(resourceError, undefined, 4)); }); casper.on("page.initialized", function(page) { page.onResourceTimeout = function(request) { console.log('Response Timeout (#' + request.id + '): ' + JSON.stringify(request)); }; }); casper.then(function() { test.assertTitle('Example Title', 'Example title is incorrect'); }); casper.run(function() { test.done(); }); });
javascript ecmascript-6 testing phantomjs casperjs
Ryan rentfro
source share