node.js - phantomjs+ mocha + node + opening a web page -
i'm trying simple. or thought.
all want use phantomjs open webpage , assert title. i'm using mocha-phantomjs invoke test runner looks like:
<html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="../../node_modules/mocha/mocha.css" /> </head> <body> <div id="mocha"></div> <script src="../../node_modules/mocha/mocha.js"></script> <script src="../../node_modules/chai/chai.js"></script> <script> mocha.ui('bdd'); mocha.reporter('html'); </script> <script src="test.js"></script> <script> if (window.mochaphantomjs) { mochaphantomjs.run(); } else { mocha.run(); } </script> </body> </html> and test file looks
(function() { var page, url; page = require('webpage'); page = webpage.create(); url = "http://localhost:3000"; page.open(url, function(status) { var ua; if (status !== "success") { return console.log("unable access network"); } else { ua = page.evaluate(function() { return document.title.should.equal('blah'); }); phantom.exit(); } }); describe('sanity test', function() { return it('true should true', function() { return true.should.equal(true); }); }); }).call(this); when run using mocha-phantomjs complains doesn't know require need require webpage.
how can solve this?
you might want casper.js, it's easier:
casper.test.begin('my test', function suite(test) { casper.start("your url", function() { test.asserttitle("expected title"); }); casper.run(function() { test.done(); }); });
Comments
Post a Comment