testing - AngularJS E2E 测试的执行顺序

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

因此,我注意到 describe() block 中的 it() 函数不会(总是)按照我编写它们的顺序运行。

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

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

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

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
});
...

最佳答案

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

});

您可以在彼此内部嵌套额外的“描述” block ,包含额外的“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)");
        });

    });
   });

关于testing - AngularJS E2E 测试的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17393699/

相关文章:

testing - 如何测试使用从另一个模块导入的客户端 API 函数的函数?

reactjs - 在 Maven 项目中使用 Cypress.io 测试 React

amazon-web-services - 如何自动启动、执行和停止EC2?

javascript - AngularJS 指令匹配

javascript - 如何防止使用 Angular JS 在输入键时提交表单?

unit-testing - 对 Angular 2 中的可观察对象进行单元测试

javascript - AngularJS Controller 中的单元测试 promise

testing - 在不打开浏览器的情况下使用 chromeDriver 运行 Geb 测试

javascript - 使用 groupby 格式化 Json 对象

javascript - 预期 [ ] 为 [ ] Jasmine,如何检查空数组