【问题标题】:Protractor/Jasmin Stop execution or skip test if BeforeAll or BeforeEach failsProtractor/Jasmin 如果 BeforeAll 或 BeforeEach 失败,则停止执行或跳过测试
【发布时间】:2020-04-15 01:34:43
【问题描述】:

如果 BeforeAll 或 BeforeEach 有任何故障,有什么方法可以停止执行或跳过测试?在 Protractor+Jasmin 框架中

我尝试了一些没有帮助的方法,例如:protractor-fail-fast、jasmine-bail-fast、topSpecOnExpectationFailure: true

在我的测试中,如果 Login 在 BeforeAll 或 BeforeEach 中不起作用,测试仍在执行。 如果登录失败,是否有任何原因会跳过 it() 块中的执行。

【问题讨论】:

    标签: jasmine protractor


    【解决方案1】:

    我认为这里不会有很好的解决方案。我可以建议一些这样的技巧:

    describe('Some feature', function () {
        preconditionFailed = false
    
        beforeAll(async function () {
           try {
              await somePreconditions()
              preconditionFailed = false
           } catch(err) {
              preconditionFailed = true
              throw err
           }
        }
    
        beforeEach(async function () {
           try {
              await somePreconditions()
              preconditionFailed = false
           } catch(err) {
              preconditionFailed = true
              throw err
           }
        }
    
        it('should work', async feature() {
            if(preconditionFailed) {
                throw new Error('Precondition failed, cannot start test')
            }
            await someTestLogic()
        })
    
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多