Protractor with jasmine does not show stack traces to line with error

岁酱吖の 提交于 2021-01-29 07:09:37

问题


I've got a protractor test that does this:

  it('Test', async () => {
     throw new Error()
  }

When this errors, it outputs this:

    ✗ Test
      - Failed: Error
          at callWhenIdle (.../node_modules/jasminewd2/index.js:62:5)
          at .../node_modules/jasminewd2/index.js:127:13
          at <anonymous>
          at process._tickCallback (internal/process/next_tick.js:188:7)    (node:43369) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: EPIPE write EPIPE

How do I get a useful stack trace that says the error was thrown on the appropriate line of the test?

Here's my protractor configuration file:

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const {SpecReporter} = require('jasmine-spec-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');

var reporter = new HtmlScreenshotReporter({
  dest: '../build/test-results/e2e/screenshots',
  filename: 'e2e-report.html',
  reportOnlyFailedSpecs: true,
  captureOnlyFailedSpecs: true,
  showQuickLinks: true,
  reportFailedUrl: true,
  inlineImages: true
});

exports.config = {
  SELENIUM_PROMISE_MANAGER: false,
  allScriptsTimeout: 11000,
  specs: [
    './src/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome',
    chromeOptions: {
      args: ["--headless", "--disable-gpu", "--window-size=1920,1080"]
    }
  },
  directConnect: true,
  baseUrl: 'http://localhost:4201/',
  params: {},
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function () {
    }
  },

  beforeLaunch: function () {
    return new Promise(function (resolve) {
      process.on('uncaughtException', function () {
        reporter.jasmineDone();
        reporter.afterLaunch();
      });

      reporter.beforeLaunch(resolve);
    });
  },

  onPrepare() {
    require('ts-node').register({
      project: require('path').join(__dirname, './tsconfig.e2e.json')
    });

    jasmine.getEnv().addReporter(reporter);
    jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));

    console.log("==========> Target report configuration", browser.params.products[process.env.TARGET_REPORT_SKU]);
  },

  afterLaunch: function (exitCode) {
    return new Promise(function (resolve) {
      reporter.afterLaunch(resolve.bind(this, exitCode));
    });
  }
};

For what it's worth, I'm running the tests through a gradle command.

I tried creating a fresh protractor app and saw that it had the same problem. Therefore, I created an issue on their github: https://github.com/angular/protractor/issues/4975


回答1:


Inside protractor config add to jasmineNodeOpts this option.

includeStackTrace: true



来源:https://stackoverflow.com/questions/52729217/protractor-with-jasmine-does-not-show-stack-traces-to-line-with-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!