Javascript 量角器-beforeach中的异步任务

Javascript 量角器-beforeach中的异步任务,javascript,angularjs,jasmine,protractor,Javascript,Angularjs,Jasmine,Protractor,我正在使用量角器/Jasmine来编写UI测试。 我希望在我的所有测试用例中执行一个特定的任务,即读取一个span(id=“mytxt”)。所以,我想在每次之前完成这项任务。像这样: var mytext=""; beforeEach(function(){ element(by.id('mytxt')).getText().then(function(txt){ mytext = txt; }); }); it('should ...', function()

我正在使用量角器/Jasmine来编写UI测试。 我希望在我的所有测试用例中执行一个特定的任务,即读取一个span(
id=“mytxt”
)。所以,我想在每次之前完成这项任务。像这样:

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

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

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

是否有一种方法可以使测试仅在beforeach中的异步任务完成后执行?

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

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

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

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