您可以将重复的代码保存在单独的文件中,我们称之为 helper.js:
module.exports = {
"login": function(test) {
test.open(some_url)
.assert.exists("some_selector", "verify that some_selector exists")
}
};
然后在您的主文件上,我们将其称为 index.js,您可以要求该模块:
var helper = require("./helper") // path is realtive, this is assuming that both files are in the same folder
module.exports = {
"my main test": function(test) {
helper.login(test);
** some more tests **
.done();
}
}
还要检查这个网址,它有一些例子:
https ://github.com/asciidisco/jsdays-workshop/tree/8-dry/test/dalek