【问题标题】:Order of execution of AngularJS E2E testsAngularJS E2E 测试的执行顺序
【发布时间】:2013-06-30 18:46:44
【问题描述】:

所以,我注意到describe() 块中的it() 函数并不(总是)按照我编写它们的顺序运行。

那么它们是异步的吗?以及如何强制它们按照一定的顺序运行?

我想链接一堆 UI 突变,基本上让每个 it() 函数在上一步之后检查 UI 的状态。

如果它们是异步执行的,那就更重要了。这意味着每个it() 块都需要包含前一个块中的所有步骤?

it('should do something', function() {
  // app is in state 1
  // do something
  // leave app in state 2
});
it('should continue from the state left after the previous block', function() {
  // app is in state 2
  // do something
  // leave app in state 3
});
it('should continue from the state left after the previous block', function() {
  // app is in state 3
  // do something
  // leave app in state 4
});
it('should continue from the state left after the previous block', function() {
  // app is in state 4
  // do something
  // leave app in state 5
});
...

【问题讨论】:

    标签: testing angularjs jasmine end-to-end angular-scenario


    【解决方案1】:

    “it”函数中的所有内容都是独立的测试。您需要做的是将共享步骤放在“beforeEach”函数中

    describe('Check pdf popup', function() {
        beforeEach(function() {
            element('.navbar a:eq(3)').click();
        });
    
        it('We should see the pdf popup', function() {
            expect(element('.modal h4:visible').text()).toMatch(/Email PDF/);
        });
    
        it('Cancel should dispel the pdf popup', function() {
            // exit pdf box
            element('input[value="Cancel"]').click();
            expect(repeater('.modal h4:visible').count()).toBe(0);
        });
    
        it('if customer email not set, display input for email', function() {
            expect(repeater('.modal #pdfemail:visible').count()).toBe(1);
            expect(repeater('.modal #pdfcustomercheckbox:visible').count()).toBe(0);
        });
    
    });
    

    您可以在彼此之间嵌套额外的“describe”块,包含额外的“beforeEach”函数,具有发出连续命令的效果。

    describe('fuel comparison', function() {
        beforeEach(function() {
            element("#gasvsdiesel").click();
        });
    
        it('should switch to Fuel Comparison calculator', function() {
            expect(element('.brand').text()).
                toBe("Fuel Comparison");
        });
    
        describe('changing gas price', function() {
            beforeEach(function() {
                input("compareFuelPrice").enter("5.888");
            });
    
            it('should change fuelinfo text to show reset link', function() {
                element('#content .nav-pills a[tap-click="tab=\'calculations\'"]').click();
                expect(element("#fuelinfo span:visible").text()).toBe("(Click here to set fuel prices to California defaults)");
            });
    
        });
       });
    

    【讨论】:

    • 就我而言,他们并没有真正的“共享步骤”。我只需要随后的每个it() 继续从前一个离开应用程序的状态。我将如何实现这一点?
    • 我编辑了我的问题以更好地说明我在寻找什么。
    • 每个“它”必须完全独立。您必须在测试之间从头开始。我明白你的要求,但你的想法是错误的。上面的结构是实现你想要的正确方法。
    • 正如我所说,我没有共享步骤。所以它根本不适用于我的情况。 it() 块是同步执行还是异步执行?
    • 你的想法还是错误的。每个测试都是完全独立的。首先运行哪个测试并不重要,因为正确编写的测试不应该依赖于任何其他测试。 “it”语句中的每个代码块都是一个完全独立的测试。我知道您不想这样使用它,但它就是这样设计的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 2018-03-25
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    相关资源
    最近更新 更多