Skip to content

Instantly share code, notes, and snippets.

@deterralba
Last active June 16, 2023 21:12
Show Gist options
  • Save deterralba/5862ec98613dbf073545a7d7e87a637d to your computer and use it in GitHub Desktop.
Save deterralba/5862ec98613dbf073545a7d7e87a637d to your computer and use it in GitHub Desktop.
Custom nightwatch command waitForElementClickable() - tested with nightwatch 1.1.13 - inspired by https://gist.github.com/JamesBoon/dc19bc202673e19baf4b9b85d78df27f
// Much simpler version (this history for the previous ones), suggested by @beatfactor
// More info https://github.com/nightwatchjs/nightwatch/issues/705
module.exports.command = function(selector, timeout=5000) {
this.expect.element(selector).enabled.before(timeout);
this.perform(() => {
// eslint-disable-next-line no-console
console.log(`🖱️ Element clickable: <${selector}>`);
});
return this;
};
@deterralba
Copy link
Author

deterralba commented May 24, 2019

FYI: broken by nightwatch 1.1
New gist version: now working with 1.1.11

@jonstorer
Copy link

use nightwatch's logger

const { Logger, symbols } = require('nightwatch/lib/utils');
const { colors } = Logger

module.exports.command = function (selector, timeout=5000) {
  const start = Date.now()
  this.expect.element(selector).enabled.before(timeout)
  this.perform(() => {
    const message = `Element <${selector}> was present after ${Date.now() - start} milliseconds.`
    Logger.logDetailedMessage(`  ${colors.green(symbols.ok)} ${message}`);
  });
  return this
};

@jonstorer
Copy link

It may be better to use this.globals.waitForConditionTimeout for the default timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment