title: Nightwatch.js Async Selenium Operations
body: <p>Say I have a Nightwatch test with two steps that fill out a form. As part of the first step, I need to dynamically query some data from the page (using the Selenium api), then use that data to make additional selenium calls, and use the final result to make custom assertions. The reason I need to use the Selenium api is not that I do not know how to use the normal Nightwatch assertions, but rather that the normal assertions are not sufficient to test the types of things I want to test. Additionally, at the end of the first step a button is clicked that moves on to the next part of the form (in preparation for the second step).</p>
  
  <p>(code version):</p>
  
  <pre class="lang-js prettyprint-override"><code>module.exports = {
    'Part 1': (client) =&gt; {
  
      // ... do cool stuff
  
      client.SOME_SELENIUM_COMMAND(...SOME_ARGS..., (result) =&gt; {
  
        client.SOME_OTHER_SELENIUM_COMMAND(...SOME_OTHER_ARGS..., (result2) =&gt; {
          // ... do more cool stuff with result2
        });
      });
  
      // moves the page onto part 2
      client.click(SOME_BUTTON);
    },
  
    'Part 2': (client) =&gt; {
      // ... part 2 stuff
    }
  };
  </code></pre>
  
  <p>My problem is this: the test moves on to the second part before the selenium command result part resolves.</p>
  
  <p>I am aware that internally Nightwatch uses some kind of event queue and EventEmitters to make sure that commands are executed in the correct order however it appears that the click command at the end of part one is being queued up before the commands in the callback can be.</p>