Andrej
Andrej

Reputation: 568

protractor is unable to open a new tab

Could you please suggest what I am doing wrong that I am getting this very strange exception:

Failed: unknown error: 'name' must be a string (Session info: chrome=53.0.2785.101) (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 3.13.0-100-generic x86_64)

function ensureNumberOfTabs(numberOfTabs) {
  return this.browser.getAllWindowHandles()
    .then(function(handles) {
      return handles && handles.length >= numberOfTabs && handles[numberOfTabs];
    });
}

this.openTab = function(index, timeout) {
  timeout = timeout || DEFAULT_WAIT_FOR_TIMEOUT;
  var thisBrowser = this.browser;
  var deferred = protractor.promise.defer();

  function errHandler(err) {
    deferred.reject(err);
  }
  //wait to open the tab
  thisBrowser.wait(ensureNumberOfTabs(index), timeout, 'waiting for opening tab #' + index);
  //switch to the tab
  thisBrowser.getAllWindowHandles().then(function(tabs) {
    var tab = tabs[index]; // this is your new window
    thisBrowser.switchTo().window(tab).then(function() {
      deferred.fulfill();
    }, errHandler);
  }, errHandler);

  return deferred.promise;
};

As far as I understand I am actually checking that name has something by && handles[numberOfTabs];

The problem, of course happens just sometimes...

Any advice would be very welcomed:)

This issue appears on node 6, protractor 4.0.11, chrome 53 and driver 2.25, on Ubuntu 14

Upvotes: 4

Views: 4607

Answers (1)

AdityaReddy
AdityaReddy

Reputation: 3645

You will see the error related to name when the browser.switchTo().window() receives an undefined/null argument

You can reproduce by directly calling browser.switchTo().window() passing a null argument. You need to debug further your code why the window handle - var tab = tabs[index]; is being sent null

Upvotes: 3

Related Questions