4

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

Andrej
  • 558
  • 6
  • 14
  • Are you sure `tab` is a string in `thisBrowser.switchTo().window(tab)`? Seems like this would be where the issue is? What does the stacktrace tell you about where the error is occurring? – tehbeardedone Nov 29 '16 at 17:44
  • That is the problem, I am not the owner of the code that provides the `tab`. So my question is why I am not getting the handler? – Andrej Nov 30 '16 at 10:32
  • more over when I added between steps some sleep commands now I am able to open tab,but I am getting "[ng:test] no injector found for element argument :( Any help would be great – Andrej Dec 03 '16 at 09:29
  • 1
    Check out this answer http://stackoverflow.com/questions/28040078/no-injector-found-for-element-argument-to-gettestability#answer-32202674 – tehbeardedone Dec 05 '16 at 14:57

1 Answers1

3

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

AdityaReddy
  • 3,625
  • 12
  • 25