Node 中的量角器:如何同步将我的测试排序为 运行?

Protractor in Node: How do I order my tests to run synchronously?

我想知道如何按同步顺序执行多个 "describe" 块?

describe('Go To Home Page', function () {  
    browser.ignoreSynchronization = true;
    it("Url should be on Login Page", function ()  {
        browser.get(HomePageUrl).then(function () {
            browser.wait(urlChanged(loginPageUrl), 2000).then(
                function (newurl){
                    var url = browser.getCurrentUrl().then(function (url) {
                        expect(url).tobe(loginPageUrl);
                        //I know I'm at Login page url... how do I kick off next test?                 
                    });                     
                }
            )          
        });
    });
}); 

此测试转到主页,然后如果它被重定向到登录页面,我想使用新的 Describe 块执行我所有的登录测试。问题是,如果我将下一个 Describe 块放在与第一个相同的级别,节点会并行执行所有这些块。

我不想陷入回调地狱...在我看来,上面的代码已经变得太深入了。

Jasmine Asyncronous support 正是为此。

describe('Go To Home Page', function () {  
    browser.ignoreSynchronization = true;
    it("Url should be on Login Page", function (done)  {
        browser.get(HomePageUrl).then(function () {
            browser.wait(urlChanged(loginPageUrl), 2000).then(
                function (newurl){
                    var url = browser.getCurrentUrl().then(function (url) {
                        expect(url).tobe(loginPageUrl);
                        done();      
                    });                     
                }
            )          
        });
    });

   it("next", function ()  {
      //will start this block after previous done callback has been called
   });
}); 

PS Promise 可以而且应该链接在一行中以避免嵌套:

it("Url should be on Login Page", function (done)  {
    browser
        .get(HomePageUrl)
        .then(function () {
            return browser.wait(urlChanged(loginPageUrl), 2000);
        })
        .then(function () {
            return browser.getCurrentUrl();
        })
        .then(function (currentUrl){
            expect(currentUrl).tobe(loginPageUrl);
            done();         
        });
});