mobify / nightwatch-commands

A set of Mobify specific custom commands for Nightwatch.js
60 stars 18 forks source link

What's the best way to pass arguments to `condition` in the `waitForCondition` command? #83

Open anatoliyarkhipov opened 6 years ago

anatoliyarkhipov commented 6 years ago

For example, in a condition like this I want to pass the selector argument:

const condition = (selector) => {
  return !! $(selector).attr('disabled')
}

But it looks like there is no way to do this except of constructing condition as string:

// like this
const condition = `return !! $(${selector}).attr('disabled')`

// or this
const conditionFunc = () => {
  return !! $({{SELECTOR}}).attr('disabled')
}

const condition = conditionFunc.toString().replace('{{SELECTOR}}', selector)

Not a big deal in the exampe, but there might be really big condition functions where such constructing can really bother.

Wouldn't it be as simple to add support for arguments as to add the extra argument for the execute call here?

https://github.com/mobify/nightwatch-commands/blob/4d3984a7943d59deed832fd48258222071d141d6/commands/waitForCondition.js#L49-L69