【问题标题】:How can I retry failed end to end tests in Detox using Mocha?如何使用 Mocha 在 Detox 中重试失败的端到端测试?
【发布时间】:2019-03-22 17:09:06
【问题描述】:

我有一个使用DetoxMochaflaky end-to-end test

Mocha 测试运行器允许multiple retries。我尝试使用推荐的 Mocha 语法:

// auth.spec.js
describe('App authentication', () => {

  this.retries(2);

  it('should have a login screen', async () => {
    await expect(element(by.id('LoginScreenView'))).toBeVisible();
  });

});

但是,在以 Mocha 作为测试运行器运行 Detox 时,this 似乎是一个空对象 ({}),并且没有 retries 函数。

它会产生以下错误:

node_modules/.bin/mocha __e2e__ --opts __e2e__/config/mocha.opts --

configuration ios.sim.debug      --grep :android: --invert     --artifacts-location "__e2e__/artifacts/ios.sim.debug.2018-10-17 22-51-12Z" 
/<path>/__e2e__/auth.spec.js:10
  this.retries(2);
       ^

TypeError: this.retries is not a function
    at Suite.describe (/<path>/__e2e__/auth.spec.js:4:8)
    at Object.create (/<path>/node_modules/mocha/lib/interfaces/common.js:112:19)
    at context.describe.context.context (/<path>/node_modules/mocha/lib/interfaces/bdd.js:40:27)
    at Object.<anonymous> (/<path>/__e2e__/auth.spec.js:3:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at /<path>/node_modules/mocha/lib/mocha.js:250:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/<path>/node_modules/mocha/lib/mocha.js:247:14)
    at Mocha.run (/<path>/node_modules/mocha/lib/mocha.js:576:10)
    at Object.<anonymous> (/<path>/node_modules/mocha/bin/_mocha:637:18)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
child_process.js:644
    throw err;
    ^

有没有办法在 Detox 中自动重试失败的测试?

【问题讨论】:

    标签: react-native mocha.js detox


    【解决方案1】:

    mocha中的this不能使用箭头功能,必须改成普通的

    // auth.spec.js
    describe('App authentication', function () { // change it
    
      this.retries(2);
    

    不建议在 Mocha 中使用最佳实践

    参考: https://mochajs.org/#arrow-functions

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      • 2016-10-17
      • 2015-09-21
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 2017-09-30
      相关资源
      最近更新 更多