我正在尝试创建一个 nightwatchJS 自定义断言,它将检查文件是否存在。断言似乎触发了,但 nightwatch 在断言命令完成后立即退出。
我想我不会将控制权返回给 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;
};
最佳答案
我知道这是一个老问题,但我在编写自己的自定义断言时发现您需要在命令函数中返回“this”。回调将您的值发送到传递函数中使用的 this.value。
所以它看起来像这样
this.command = function(callback) {
fs.exists(fname, callback);
return this;
};
关于selenium-webdriver - Nightwatch 自定义断言导致测试执行停止,无论结果如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30963234/