title: Executing callback from a CucumberJS with Selenium step definition
body: <p>I'm trying out CucumberJS with Selenium and PhantomJS. I've successfully <a href="https://stackoverflow.com/a/29592119/1489537">built a World object using this StackOverflow answer</a> as a guide.</p>
  
  <p>So now I'm testing out some basic step definitions, but having some confusion about how to execute the callback at the end of the step. This works great:</p>
  
  <pre><code>module.exports = function () {
    this.World = require("../support/world.js").World;
  
    this.Given(/^I am visiting Google$/, function (callback) {
      this.driver.get('http://www.google.com')
          .then(function() {
            callback();
          });
    });
  };
  </code></pre>
  
  <p>The driver hits Google.com and the callback isn't fired until after the requested document is loaded. But I find this syntax to be a little wordy, so I thought maybe I could just pass <code>callback</code> straight to the <code>then()</code> after my first promise, like so:</p>
  
  <pre><code>module.exports = function () {
    this.World = require("../support/world.js").World;
  
    this.Given(/^I am visiting Google$/, function (callback) {
      this.driver.get('http://www.google.com')
          .then(callback);
    });
  };
  </code></pre>
  
  <p>This, however fails, and seems to <code>console.log</code> the <code>callback</code>. Here's the output:</p>
  
  <pre><code>  Scenario: Googling           # features/theGoogle.feature:6
      Given I am visiting Google # features/theGoogle.feature:7
        [object Object]
  
  
      (::) failed steps (::)
  
      [object Object]
  </code></pre>
  
  <p>What's going on here? I was expecting that <code>callback</code> could simply be passed to the <code>then()</code> function and executed after the promise is fulfilled. Why would wrapping it in an anonymous function make it work?</p>