失败:无法读取未定义的属性“结果”

时间:2016-09-16 00:34:21

标签: javascript jasmine protractor

获取测试失败屏幕截图的代码段

    afterEach(function() {

        var spec = jasmine.getEnv().currentSpec;
        var passed = spec.results().passed();

      if (!passed) {
        browser.takeScreenshot().then(function(png) {
          writeScreenShot(png, "screenshot.png");
        });
      }

        function writeScreenShot(data, filename) {
                var stream = fs.createWriteStream(filename);
                stream.write(new Buffer(data, 'base64'));
                stream.end();
        }

    });

控制台错误

  Message:
    Failed: Cannot read property 'results' of undefined
  Stack:
    TypeError: Cannot read property 'results' of undefined
        at Object.<anonymous> 

它在这里返回undefined

var spec = jasmine.getEnv().currentSpec;
console.log(spec);

看起来像Jasmine 2引起的问题;任何替代解决方案也欢迎!我使用Jasmine 2

2 个答案:

答案 0 :(得分:1)

Jasmine 2.0起,env.currentSpec不再受支持。

https://github.com/jasmine/jasmine/issues/1212

答案 1 :(得分:0)

&#34; var spec&#34;没有任何东西。这意味着&#34; jasmine.getEnv()。currentSpec&#34;无论出于何种原因都无法正常工作。