title: E2E Testing - WebdriverJS, Selenium and Jasmine
body: <p>OK so I have followed several slightly differing examples, as you can see in my commented code below.  They all claim to work, but I cannot get it to do so.</p>
  
  <p>I'm using; 
  - <code>selenium-webdriver</code>
  - <code>jasmine-node-reporter-fix</code> (<code>jasmine-node</code> errors)</p>
  
  <p>So its quite a simple asynchronous test, opening Google and searching, then getting the page title.</p>
  
  <p><strong>Problem;</strong>
  The page title returned is the Google homepage and not the search results page. (Browser ends up on the search results page).</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>var webdriver = require('selenium-webdriver');
  
  var driver = new webdriver.Builder().
      withCapabilities(webdriver.Capabilities.firefox()).
      build();
  
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 9999999;
  
  describe('basic test', function () {
  
      it('should be on correct page', function (done) {
          //driver.get('http://www.wingify.com');
          //driver.getTitle().then(function (title) {
          //  expect(title).toBe('Wingify');
          //  // Jasmine waits for the done callback to be called before proceeding to next specification.
          //  done();
          //});
  
  
          driver.get("http://www.google.com");
          driver.findElement(webdriver.By.name("q")).sendKeys("webdriver");
          driver.findElement(webdriver.By.name("btnG")).click();
          //driver.getTitle().then(function (title) {
          //  console.log(title);
          //  console.log(expect);
          //  expect(title).toBe('webdriver - Google Search');
          //  done();
          //});
          driver.wait(function () {
              driver.getTitle().then(function (title) {
                  expect(title).toBe('webdriver - Google Search');
                  done();
              });
          }, 5000);
  
      });
  });
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>Failures:
  
    1) basic test should be on correct page
     Message:
       Expected 'Google' to be 'webdriver - Google Search'.
     Stacktrace:
       Error: Expected 'Google' to be 'webdriver - Google Search'.
      at C:\Stash\Will-Hancock\grunt-jasmine\spec\test-spec.js:31:19
      at C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\goog\base.js:1243:15
      at webdriver.promise.ControlFlow.runInNewFrame_ (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539
  :20)
      at notify (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:362:12)
      at notifyAll (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:331:7)
      at resolve (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:309:7)
      at fulfill (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:429:5)
      at Object.webdriver.promise.asap (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:671:5)
  
  Finished in 4.281 seconds
  1 test, 1 assertion, 1 failure, 0 skipped
  </code></pre>
  
  <p>So some people have said I need the jasmine timeout extended, this makes no difference.</p>
  
  <p>Others saying you need the Jasmine done() method - without this the test doesn't complete.</p>
  
  <p>I cannot see why the wait doesn't wait! - the result is returned immediately whatever the timeout provided.</p>