我正在尝试将较旧的Nightwatch-Cucumber框架迁移到Nightwatch-api。一切都与WaitForText自定义命令分开。但是,它适用于旧实例。
这是尝试运行自定义命令时出现的错误:
Error while running "WaitForText" command: Cannot read property 'isES6Async' of undefined
TypeError: Error while running "WaitForText" command: Cannot read property 'isES6Async' of undefined
at queuedCommandFn (/home/kieran/Documents/automation/updated-framework/node_modules/nightwatch/lib/api/_loaders/command.js:195:35)
at CommandInstance.WaitForText.check (/home/kieran/Documents/automation/updated-framework/lib/CustomCom/WaitForText.js:34:5)
at CommandInstance.WaitForText.command (/home/kieran/Documents/automation/updated-framework/lib/CustomCom/WaitForText.js:20:10)
at /home/kieran/Documents/automation/updated-framework/node_modules/nightwatch/lib/api/_loaders/command.js:154:29
at processTicksAndRejections (internal/process/task_queues.js:93:5)
这是WaitForText.js定制命令:
var util = require('util');
var events = require('events');
function WaitForText() {
events.EventEmitter.call(this);
this.startTime = null;
}
util.inherits(WaitForText, events.EventEmitter);
WaitForText.prototype.command = function (element, getter, checker, ms) {
this.startTime = new Date().getTime();
var self = this;
var message;
if (typeof ms !== 'number') {
ms = 1000;
}
this.check(element, getter, checker, function (result, loadedMs) {
if (result) {
message = 'Expression was true after ' + (loadedMs - self.startTime) + ' ms.';
} else {
message = 'Expression wasn\'t true in ' + ms + ' ms.';
}
self.client.assertion(result, 'expression false', 'expression true', message, true);
self.emit('complete');
}, ms);
return this;
};
WaitForText.prototype.check = function (element, getter, checker, cb, maxTime) {
var self = this;
getter(element, function (result) {
var now = new Date().getTime();
if (result.status === 0 && checker(result.value)) {
cb(true, now);
} else if (now - self.startTime < maxTime) {
setTimeout(function () {
self.check(element, getter, checker, cb, maxTime);
}, 1000);
} else {
cb(false);
}
});
};
module.exports = WaitForText;
我不知道从哪里开始,因为我不了解自定义命令的工作原理,它已经包含在以前的框架中。
任何帮助将不胜感激。