2015-06-21 39 views
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; 
 
    };

回答

0

我知道這是一個老問題,但我以書面形式,你需要在你的命令函數返回「這個」我自己的自定義斷言找到。回調函數是將值傳遞給pass函數中使用的this.value的值。

因此,它看起來像這樣

this.command = function(callback) { 
    fs.exists(fname, callback); 
    return this; 
}; 
相關問題