我正在尝试使用phantomjs-node和mocha来运行一些测试
var phantom = require('phantom');
phantom.create().then(function(ph) {
ph.createPage().then(function(page) {
page.open('http://localhost:8900').then(function(status) {
console.log(status);
if ( status === "success" ) {
page.injectJs("../node_modules/mocha/mocha.js");
page.injectJs("../node_modules/chai/chai.js");
//inject your test reporter
page.injectJs("testMocha/reporter.js");
//inject your tests
tests.forEach(function(test) {
page.injectJs(test);
})
page.property('evaluate').then(function() {
window.mocha.run();
});
}else{
ph.exit();
}
});
});
});我用以下命令运行文件
node myFile.js但是,当我运行该文件时,控制台中什么也没有显示,我的任何测试都没有运行,并且脚本挂起。
如果我没有使用phantomjs-node,我就能够运行并显示我的测试,用以下命令启动文件
phantomjs myFile.js但是我需要phantomjs-node来做我的测试所需的其他事情。如何使用phantomjs-node来添加mocha?
发布于 2016-02-26 15:59:20
我的问题的解决方案是,首先我需要这样开始评估:
page.evaluate(function() {我认为我必须使用page.property('evaluate').then(function() {,因为我使用的是phantomjs-node,但事实并非如此
其次,我无法从mocha查看测试结果的原因是,在我的报告器文件中,我使用callPhantom显示了结果:
window.callPhantom({ message: args.join(" ") }); 但是对于phantomjs-node,这似乎不起作用,所以只需执行一个简单的console.log
console.log( args.join(" ") );我使用的一个记者的例子,以及如何一起使用phantomJS和mocha的一个很好的教程可以在那里找到:
http://doublenegative.com/phantomjs-mocha-and-chai-for-functional-testing/
https://stackoverflow.com/questions/35581464
复制相似问题