AngularJS E2E测试的执行顺序

问题描述 投票:0回答:1

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

那他们是不同步的吗?以及如何强迫他们以特定顺序运行?

我想链接一堆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个回答
3
投票

“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)");
        });

    });
   });
© www.soinside.com 2019 - 2024. All rights reserved.