我按照here中的指令(在夜间守望中暂停命令),以创建一个获取当前使用的选择器(css或xpath)的自定义命令。
var util = require('util');
var events = require('events');
function GetSelector() {
events.EventEmitter.call(this);
}
util.inherits(GetSelector, events.EventEmitter);
GetSelector.prototype.command = function (callback) {
callback(this.client.locateStrategy);
};
module.exports = GetSelector;
实现获取当前选择器,尽管程序在调用自定义命令时卡住了。
browser
.getSelector(function (currentSelector) {
console.log('getSelector: ' + currentSelector);
})
我也尝试用" self.perform"按照建议here,不幸的是没有运气。
GetSelector.prototype.command = function (browser, callback) {
browser.perform(function () {
callback(this.client.locateStrategy);
})
};
我错过了什么?
先谢谢!
答案 0 :(得分:0)
"完成事件的信号需要在异步操作中完成"根据守夜人homepage,action"self.emit('complete');
。
GetSelector.prototype.command = function (cb) {
var self = this;
process.nextTick(function () {
cb(self.client.locateStrategy);
//Signaling the complete event needs to be done inside an asynchronous action.
self.emit('complete');
});
return this;
};
process.nextTick确保在由Node处理的事件循环的下一个滴答中调用self.emit('complete');
。