title: Selenium + node running multiple test at the same time
body: <p>Situation:</p>
  
  <ul>
  <li><p>I've setup 4 computers with different versions of Microsoft Internet Explorer and connected them to a selenium grid (hub). </p></li>
  <li><p>I can use selenium-webdriver in node and target a test to different browser/machine combinations.</p></li>
  <li><p>Selenium grid performs without any problem.</p></li>
  </ul>
  
  <p>However when I call my Getscreen() function multiple times everything is good until one of the test servers has a problem (like timeout). </p>
  
  <p>The error is captured with 
  <code>Client.controlFlow().on('uncaughtException', function(e) {...</code>
  in the function.</p>
  
  <p>But strangely this listener does not get destroyed with the function completing it's run. So if I've already called the function 50 times and test 51 fails I get 51 error messages. </p>
  
  <p>My node code is like this:</p>
  
  <pre><code>var fs = require('fs');
  var webdriver = require('selenium-webdriver');
  var HubIP = '192.168.1.201';
  
  var Resolutions = [{
      width: 1920,
      height: 1080
  }, //0
  {
      width: 1680,
      height: 1050
  }, //1
  {
      width: 1600,
      height: 900
  }, //2
  ...
  ];
  
  function writeScreenshot(data, name) {
    name = name || 'ss.png';
    var screenshotPath = '../tests/';
    fs.writeFileSync(screenshotPath + name, data, 'base64');
  };
  
  
  function Getcreen(urltoget,resolutionN,WaitN,browsernameN,TableRowID)
  {
      var xCapabilities = {};
  
      if (browsernameN=="ie8") { xCapabilities = { browserName: 'internet explorer', version: '8', platform: 'WINDOWS' }; }
      if (browsernameN=="ie9") { xCapabilities = { browserName: 'internet explorer', version: '9', platform: 'WINDOWS' }; }
      if (browsernameN=="ie10") { xCapabilities = { browserName: 'internet explorer', version: '10', platform: 'WINDOWS' }; }
      if (browsernameN=="ie11") { xCapabilities = { browserName: 'internet explorer', version: '11', platform: 'WINDOWS' }; }
      if (browsernameN=="chrome") { xCapabilities = { browserName: 'chrome',  platform: 'WINDOWS' }; }
      if (browsernameN=="firefox") { xCapabilities = { browserName: 'firefox', platform: 'WINDOWS' }; }
  
      var Client = new webdriver.Builder().usingServer('http://'+HubIP+':4444/wd/hub').withCapabilities(xCapabilities).build();
  
      Client.controlFlow().on('uncaughtException', function(e) {
          console.error('**** ERROR ***** \n ' + e);
      });
  
      Client.manage().timeouts().pageLoadTimeout(parseInt(WaitN,10));
      Client.manage().timeouts().setScriptTimeout(10000);
      Client.manage().window().setSize(Resolutions[parseInt(resolutionN,10)].width,Resolutions[parseInt(resolutionN,10)].height);
  
      Client.get(urltoget).then(function() {
          Client.getTitle().then(function(title) { console.log(browsernameN+": " + title); });
          Client.takeScreenshot().then(function(data) {
          writeScreenshot(data, TableRowID + '-'+browsernameN+'.png');
      });
      Client.quit();
  }
  </code></pre>