-1

I'm running my first ever Nightwatch test as shown in the code below, everything runs fine, selenium types 'wiki' into google and submits the form fine, test passes. However I want it to automatically close the browser window down after the test has finished.

I've tried adding the below:

driver.closeWindow();

However it fails as it cannot recognise the 'closeWindow()' function, I'm finding the documentation to be very lacking (http://nightwatchjs.org/api/closeWindow.html), so I'd be grateful if someone could point out how I need to implement this.

var webdriver = require('selenium-webdriver'),


By = webdriver.By,
  Until = webdriver.Until;

var driver = new webdriver.Builder()
  .forBrowser('chrome')
  .build();

driver.get('http://www.google.com');
driver.findElement(By.name('q')).sendKeys('wiki');
driver.findElement(By.name('btnK')).submit();
driver.wait(check_title, 1000);

function check_title(){
  var promise = driver.getTitle().then(function(title) {
    if (title === 'wiki - Google Search') {
      console.log('success');
      return true;
    } else {
      console.log('fail, title was ' + title);
    }
  });
  return promise;
}
mvee
  • 241
  • 1
  • 13

1 Answers1

2

You are using selenium-webdriver, not nightwatch itself. Take a look to the examples.

Also take a look to this github repo should be very usefull to start setting up your nightwatch tests.

To close the driver with selenium-webdriver you should call Dispose method driver.Dispose()

Frankusky
  • 890
  • 7
  • 17
  • Thanks for the clarification @Frankusky, I'll have a look at those links as well. In case anyone is having an issue with the above WebDriver issue, the solution was to add driver.close(); – mvee Aug 15 '17 at 23:39