2016-09-16 97 views
0

片段的特性 '结果' 采取截图的测试失败失败:无法读取未定义

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

+0

当恰恰是这种错误发生的历史? – James111

+0

@ James111只有一个地方引用了一个属性'results' ... – usandfriends

+0

@ James111 AfterTest方法在测试用例完成运行后被调用 –

回答

0

“var spec”没有被设置为任何东西。这意味着“jasmine.getEnv()。currentSpec”不能以任何理由工作。

+0

类似于这个http://stackoverflow.com/questions/32198174/currentspec-in-jasmine-2-is-undefined –