title: How to call an external function from within casper.start or casper.thenOpen
body: <p>I am trying to split the following code such that the callback function which is stored in its own file.</p>
  
  <pre><code>var casper = require('casper').create();
  casper.start("http://www.google.com/", function() {
      this.echo(this.getTitle());
  });
  casper.run(); // "Returns Google"
  </code></pre>
  
  <p>Following <a href="https://stackoverflow.com/questions/26538463/how-to-pass-data-from-the-then-methods-in-casperjs">this example</a>, I define a function in a separate file called "getPageTitle.js";</p>
  
  <pre><code>function getPageTitle(casper) {
      casper.echo(casper.getTitle());
  }
  exports.getPageTitle = getPageTitle;
  </code></pre>
  
  <p>and call the function in another file called "main.js" by passing the CasperJS object into the function directly;</p>
  
  <pre><code>var casper = require('casper').create();
  var casperFunctions = require('./getPageTitle.js');
  casper.start("http://www.google.com/", casperFunctions.getPageTitle(casper));
  # Error: CasperError: Casper is not started, can't execute `getTitle()`                  
  </code></pre>
  
  <p>Further, if I replace the last line in the above with a <code>thenOpen()</code> call;</p>
  
  <pre><code>casper.start();
  casper.thenOpen("http://www.google.com/", casperFunctions.getPageTitle(casper));
  </code></pre>
  
  <p>The above code does not throw errors; CasperJS is able to navigate to the website, but the page title "Google" is not returned.</p>
  
  <p>Could someone please shed light on why this doesn't behave as I expect. This seems like a natural way to modularize functions that CasperJS would call once pages are loading, but am I missing something here?</p>