title: How to validate if its a login page using webdriverio
body: <p>I am using Javascript, webdriverio (v2.1.2) to perform some data extraction from an internal site. The internal site is SSO enabled, so if I have been authenticated on another application, I need not login for this application (common in enterprise intranet applications). 
  I plan to achieve the below,</p>
  
  <ul>
  <li>Create a client with required capabilities</li>
  <li>Pass the required URL</li>
  <li>For fun : Print the title of the page</li>
  <li><p>Check if an element exist on the page. If yes, then it's a login page. If not, then it's not login page</p>
  
  <pre><code>login = function (username, password) {
  if (!browserClientUtil) {
      throw "Unable to load browserClientUtil.js";
  }
  browserClientUtil
    .createClient()
    .url(_Url)
    .title(function (err, res) {
          console.log('Title is: ' + res.value);
    }) .isExisting('input#login_button.login_button', function (err, isExisting) {
      browserClientUtil.getCurrentClient()
          .setValue('input#USER.input', username)
        .setValue('input#PASSWORD.input', password)
        //.saveScreenshot('ultimatixLoginDetails.png')
        .click('input#login_button.login_button')
        .pause(100);
        handlePostLogin();
  });
  </code></pre>
  
  <p>};</p></li>
  </ul>
  
  <p>Is this the best way to do? I tried to separate the code for verifying login page in a separate function, it didn't work as everything in webdriver happens as part of callback and I am not sure if I am doing it in a right way. 
  <strong>How do I return from a callback, that will in-turn be the final value returned by that function?</strong></p>
  
  <pre><code>    login = function (username, password) {
      if (!browserClientUtil) {
          throw "Unable to load browserClientUtil.js";
      }
      browserClientUtil
        .createClient()
        .url(_Url)
        .title(function (err, res) {
              console.log('Title is: ' + res.value);
        });
        if(isThisLoginPage()){
              browserClientUtil.getCurrentClient()
              .setValue('input#USER.input', username)
            .setValue('input#PASSWORD.input', password)
            //.saveScreenshot('ultimatixLoginDetails.png')
            .click('input#login_button.login_button')
            .pause(100);
            handlePostLogin();
          }
  };
  
      isThisLoginPage = function() {
      var client = browserClientUtil.getCurrentClient();
      if(!client) {
          throw "Unable to get reference for current client, hence cannot validate if this is login page.";
      }
  
      client.isExisting('input#login_button.login_button', function (err, isExisting) {
          if(isExisting) {
              return true;
          }
      });
      return false;
  };
  </code></pre>