【问题标题】:Protractor - Asynchronous tasks in beforeEach量角器 - beforeEach 中的异步任务
【发布时间】:2015-12-19 16:34:45
【问题描述】:

我正在使用 Protractor / Jasmine 编写 UI 测试。 我希望在我的所有测试用例中执行特定任务,即。读取跨度 (id="mytxt")。所以,我想在 beforeEach 中有这个任务。像这样:

var mytext="";
beforeEach(function(){
    element(by.id('mytxt')).getText().then(function(txt){
        mytext = txt;
    });
});

it('should ...', function(){
    expect(mytext).toBe('xyz');
});

有没有办法只在 beforeEach 中的异步任务完成后才执行测试?

【问题讨论】:

    标签: javascript angularjs jasmine protractor


    【解决方案1】:

    您可以像这样使用done 回调:

    var mytext="";
    beforeEach(function(done){
        element(by.id('mytxt')).getText().then(function(txt){
            mytext = txt;
            done();
        });
    });
    
    it('should ...', function(){
        expect(mytext).toBe('xyz');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多