2
我試圖創建一個nightwatchJS自定義斷言來檢查文件是否存在。斷言看起來會觸發,但是斷言命令結束後即會退出。Nightwatch自定義斷言導致測試執行停止,無論結果如何
我想我不會控制夜視api,但如果那是這種情況,那我該如何實現呢?
// filename = doesFileExist.js
exports.assertion = function(fname, msg) {
var fs = require('fs');
this.message = msg + 'FileExists: ' + fname ;
this.expected = true;
this.pass = function(value) {
return value == this.expected;
} ;
this.value = function(result) {
return result;
};
this.command = function(callback) {
return fs.exists(fname, callback);
};
};
和測試用例(使用nightwatch.json作爲一個例子)是;
this.checkForFile = function() {
browser
.verify.doesFileExist('nightwatch.json', 'test1')
return browser;
};