Module Casperjs-如何向模块发送javascript对象
我正在使用casperjs为我的GUI编写一个测试套件。我已将代码拆分为由主脚本调用的模块 我似乎无法将javascript对象传递给我的模块。我正在读取一个json配置文件,将其转换为一个对象,然后将其传递给我的模块 testSuite.js(主脚本): auth.js(模块) config.json(配置文件) 当我运行上述操作时,我得到:Module Casperjs-如何向模块发送javascript对象,module,casperjs,Module,Casperjs,我正在使用casperjs为我的GUI编写一个测试套件。我已将代码拆分为由主脚本调用的模块 我似乎无法将javascript对象传递给我的模块。我正在读取一个json配置文件,将其转换为一个对象,然后将其传递给我的模块 testSuite.js(主脚本): auth.js(模块) config.json(配置文件) 当我运行上述操作时,我得到: Test file: jstests/admin/testSuite.js
Test file: jstests/admin/testSuite.js
username: something
--- Running auth ---
test: testme
username: undefined
我猜我可能会将文件内容作为字符串传递,然后将其转换为模块中的对象,但这对我来说似乎不太正确
还有人试过这个吗?成功?看起来您只需要包装
test1.runTest(casper,config,“testme”)
在一个Casper#然后语句中,如下所示
var casper = require('casper').create();
var test1 = require('../jstests/admin/auth');
var config = {};
casper.start('http://localhost:8080/ipiadmin', function() {});
var fs = require('fs');
configFile = fs.read('./jstests/admin/config.json');
casper.then(function() {
config = JSON.parse(configFile);
});
casper.then(function() {
this.echo("username: " + config.username); // outputs the name correctly
});
// ---
casper.then(function() {
test1.runTest(casper, config, "testme");
});
// ---
casper.run(function() {
this.test.done();
this.test.renderResults(true);
});
使用PhantomJS 1.9.1和CasperJS 1.1.0(主分支)进行测试。看起来您只需要包装test1.runTest(casper,config,“testme”)
在一个Casper#然后语句中,如下所示
var casper = require('casper').create();
var test1 = require('../jstests/admin/auth');
var config = {};
casper.start('http://localhost:8080/ipiadmin', function() {});
var fs = require('fs');
configFile = fs.read('./jstests/admin/config.json');
casper.then(function() {
config = JSON.parse(configFile);
});
casper.then(function() {
this.echo("username: " + config.username); // outputs the name correctly
});
// ---
casper.then(function() {
test1.runTest(casper, config, "testme");
});
// ---
casper.run(function() {
this.test.done();
this.test.renderResults(true);
});
使用PhantomJS 1.9.1和CasperJS 1.1.0(主分支)进行测试
Test file: jstests/admin/testSuite.js
username: something
--- Running auth ---
test: testme
username: undefined
var casper = require('casper').create();
var test1 = require('../jstests/admin/auth');
var config = {};
casper.start('http://localhost:8080/ipiadmin', function() {});
var fs = require('fs');
configFile = fs.read('./jstests/admin/config.json');
casper.then(function() {
config = JSON.parse(configFile);
});
casper.then(function() {
this.echo("username: " + config.username); // outputs the name correctly
});
// ---
casper.then(function() {
test1.runTest(casper, config, "testme");
});
// ---
casper.run(function() {
this.test.done();
this.test.renderResults(true);
});