茉莉花报告程序的Onprepare在使用IE执行时导致失败

时间:2019-01-14 07:55:52

标签: jasmine protractor

一段时间后试图弄清楚为什么测试开始失败(仅适用于IE,使用chrome可以正常工作),我发现这是由准备函数引起的,这是代码的这一部分:

  jasmine.getEnv().addReporter({
    specDone: function (result) {
      browser.getCapabilities().then(function (caps) 
      {
        var browserName = caps.get('browserName');
        browser.takeScreenshot().then(function (png) {
          var stream = fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + result.fullName+ '.png');
          stream.write(new Buffer.from(png, 'base64'));
          stream.end();
        });
      });
    }
  });

如果我对此部分发表评论,则测试会顺利进行。 我的登录页面不是Angular,所以我关闭了登录同步并再次打开,不确定是否可以关联。

如何强制量角器在继续运行之前等待这部分完成?

我已经尝试过将这段代码添加到Promise中(在conf文件中)以使量角器等待,但是即使这样,我仍然遇到了茉莉花超时'TimeoutError:Wait time after 20000ms',所以我相信我做错了。 / p>

我得到的错误是:

Failed: Unable to determine type from: E. Last 1 characters read: E
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'xxxxx', ip: 'xx.xx.xx.xx', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.2'
Driver info: driver.version: unknown

完整的conf文件:

var jasmineReporters = require('./lib/node_modules/jasmine-reporters');
var HTMLReport = require('./lib/node_modules/protractor-html-reporter-2');
var mkdirp = require('./lib/node_modules/mkdirp');
var fs = require('./lib/node_modules/fs-extra');
let date = require('./lib/node_modules/date-and-time');  

var environmentToExecute = 'https://myportal' 

exports.config = {

seleniumAddress: 'http://'+process.env.AUTOTEST_ADDRESS+'/wd/hub',

framework: 'jasmine2',

specs: ['all my specs'],

suites: {
  //All my suites
},

allScriptsTimeout: 20000,

onPrepare: function () {   
  {
   //Here I create the folders (removed to make it shorter)
  }

  jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
    consolidateAll: true,
    savePath: './execution_results/reports/xml/',
    filePrefix: 'xmlresults'
  }));

  jasmine.getEnv().addReporter({
    specDone: function (result) {
      browser.getCapabilities().then(function (caps) 
      {
        var browserName = caps.get('browserName');
        browser.takeScreenshot().then(function (png) {
          var stream = fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + result.fullName+ '.png');
          stream.write(new Buffer.from(png, 'base64'));
          stream.end();
        });
      });
    }
  });
},

//HTMLReport called once tests are finished
onComplete: function() 
{
  //I removed this to make it shorter, but basically it is the function
  // that comverts the xml in html and build the report
},

jasmineNodeOpts: {
  showColors: true, // Use colors in the command line report.
  // If true, display spec names.
  isVerbose: true,
  defaultTimeoutInterval: 100000
},

params: {
    //Other files like functions and so on...
  },
  login:{
    //parameters to login
  }
},

multiCapabilities:
[
 {
   'browserName': 'internet explorer',
   'version': 11,
 },
 /*   
 //chrome, firefox...
 */
],

};//end of Conf.js

谢谢!

1 个答案:

答案 0 :(得分:1)

最近,我在Jasmine记者中也遇到了异步操作的问题,不幸的是无法弄清楚如何让它们正确地等待承诺结果,然后再继续。如果其他人对此有信息,我也将不胜感激。

我确实使用全局变量和AfterAll挂钩实现了一项工作,该挂钩能够正确地等待可能对您有用的promise。 我假设您只需要结果的“全名”属性,您就可以尝试这样做。

在onPrepare中声明全局属性,然后可以在报告程序中分配此全局变量值。在 specStarted 而不是 specDone 内为其指定spec全名值。然后,您可以在测试afterAll语句之后的内部创建屏幕截图,这些语句可以正确等待promise的结果。

onPrepare: function () {   
   global.currentlyExecutingSpec = 'tbd';

  jasmine.getEnv().addReporter({
    specStarted: function (result) {
      currentlyExecutingSpec = result.fullName
    }
  })
  jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
    consolidateAll: true,
    savePath: './execution_results/reports/xml/',
    filePrefix: 'xmlresults'
  }));
}

在您的testFiles内部

afterEach(function(){
  browser.getCapabilities().then(function (caps) 
  {
      var browserName = caps.get('browserName');
      browser.takeScreenshot().then(function (png) {
        var stream = 
        fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + currentlyExecutingSpec + '.png');
        stream.write(new Buffer.from(png, 'base64'));
        stream.end();
      });
  };
});