'nightwatch custom command prototype

I followed the instruction from here (pause command in nightwatch), in order to create a custom command which gets the current used selector (css or 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;

The implementation gets the current selector, although the program stuck when the custom command is called.

  browser
    .getSelector(function (currentSelector) { 
      console.log('getSelector: ' + currentSelector); 
    })
    

I have also tried to wrap around with "self.perform" as suggested here, unfortunatelly without any luck.

GetSelector.prototype.command = function (browser, callback) {
    browser.perform(function () {
        callback(this.client.locateStrategy);
    })
};

What am I missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source