gulp-protractor error with chrome v54 / web driver v2.25

PremiumTier picture PremiumTier · Oct 28, 2016 · Viewed 9k times · Source

Due to the latest update of chrome (v54) we've noticed our protractor tests failing. We attempted to update to the latest version of gulp-protractor (v3.0.0) which in turn downloads the latest web driver (v2.25) to resolve the issue but unfortunately a new error occurs we've been unable to resolve.

Everything worked fine before chrome's update.

Our protractor configuration is as follows:

exports.config = {
  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  onPrepare: function () {
      var fs = require('fs');
      var testDir = 'testresults/';
      if (!fs.existsSync(testDir)) {
          fs.mkdirSync(testDir);
      }

      var jasmineReporters = require('jasmine-reporters');

      // returning the promise makes protractor wait for the reporter config before executing tests
      return browser.getProcessedConfig().then(function () {
          // you could use other properties here if you want, such as platform and version

          var browserName = 'browser';
          browser.getCapabilities().then(function (caps) {
              browserName = caps.caps_.browserName.replace(/ /g, "_");

              var junitReporter = new jasmineReporters.JUnitXmlReporter({
                  consolidateAll: true,
                  savePath: testDir,
                  // this will produce distinct xml files for each capability
                  filePrefix: 'test-protractor-' + browserName,
                  modifySuiteName: function (generatedSuiteName) {
                      // this will produce distinct suite names for each capability,
                      // e.g. 'firefox.login tests' and 'chrome.login tests'
                      return 'test-protractor-' + browserName + '.' + generatedSuiteName;
                  }
              });
              jasmine.getEnv().addReporter(junitReporter);
          });
      });
  },

  baseUrl: 'http://localhost:3000',

  // Spec patterns are relative to the current working directory when
  // protractor is called.
  specs: [paths.e2e + '/**/*.js'],

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  }
};

The error is:

[13:27:13] E/launcher - Error: Error
    at C:\ws\node_modules\protractor\built\util.js:55:37
    at _rejected (C:\ws\node_modules\q\q.js:844:24)
    at C:\ws\node_modules\q\q.js:870:30
    at Promise.when (C:\ws\node_modules\q\q.js:1122:31)
    at Promise.promise.promiseDispatch (C:\ws\node_modules\q\q.js:788:41)
    at C:\ws\node_modules\q\q.js:604:44
    at runSingle (C:\ws\node_modules\q\q.js:137:13)
    at flush (C:\ws\node_modules\q\q.js:125:13)
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)
[13:27:13] E/launcher - Process exited with error code 100

Answer

cnishina picture cnishina · Oct 28, 2016

onPrepare is being evaluated in built/util.js in the runFilenameOrFn_ function. The stacktrace unfortunately is not helpful but what this means is that onPrepare has errors. Looking at your onPrepare method, the error is made when assigning the browserName from the browser capabilities. In your code, caps.caps_ is actually undefined. Because caps.caps_ is undefined, caps.caps_.browserName is throwing an error. The capabilities object should be accessed as the following:

browser.getCapabilities().then(capabilities => {
  let browserName = capabilities.browserName.replace(/ /g, "_");