2015-10-23 84 views
1

我正在學習量角器(以及擴展名爲茉莉花的量角器使用),並且由於某種原因,我需要等待Promise繼續測試。但是,我不知道該怎麼做。如何等待量角器/茉莉花測試的承諾?

讓我們從量角器教程中的代碼,並添加一些代碼,並讓我們添加一個簡單的承諾(在ES6風格)是不會做任何事情

describe('angularjs homepage todo list', function() { 
    it('should add a todo', function() { 
    browser.get('https://angularjs.org'); 

    element(by.model('todoList.todoText')).sendKeys('write first protractor test'); 
    element(by.css('[value="add"]')).click(); 

    var todoList = element.all(by.repeater('todo in todoList.todos')); 

    Promise.resolve().then(() => { 
     expect(todoList.count()).toEqual(3); 
     expect(todoList.get(2).getText()).toEqual('write first protractor test'); 

     // You wrote your first test, cross it off the list 
     todoList.get(2).element(by.css('input')).click(); 
     var completedAmount = element.all(by.css('.done-true')); 
     expect(completedAmount.count()).toEqual(2); 
    }); 
    }); 
}); 

這是不行的,因爲這是回答

$ protractor conf.js 
Using the selenium server at http://localhost:4444/wd/hub 
[launcher] Running 1 instances of WebDriver 
F 

Failures: 

    1) angularjs homepage todo list should add a todo 
    Message: 
    Error while waiting for Protractor to sync with the page: "angular could not be found on the window" 
    Stacktrace: 
    undefined 

Finished in 0.212 seconds 
1 test, 1 assertion, 1 failure 

[launcher] 0 instance(s) of WebDriver still running 
[launcher] chrome #1 failed 1 test(s) 
[launcher] overall: 1 failed spec(s) 
[launcher] Process exited with error code 1 

我應該怎麼做才能使它工作?

回答

0

我解決它以下列方式:

  • 第一,使用jasmine2作爲框架,而不是jasemine通過以創作

framework: 'jasmine2'

conf.js

  • 編輯像這樣的文件

    var flow = browser.flow() 
    
    describe('angularjs homepage todo list', function() { 
        it('should add a todo', function() { 
        browser.get('https://angularjs.org'); 
    
        element(by.model('todoList.todoText')).sendKeys('write first protractor test'); 
        element(by.css('[value="add"]')).click(); 
    
        var todoList = element.all(by.repeater('todo in todoList.todos')); 
    
        flow.execute(function(){Promise.resolve()}); 
        // or, more ES6-y version 
        // flow.execute(() => Promise.resolve()); 
    
        expect(todoList.count()).toEqual(3); 
        expect(todoList.get(2).getText()).toEqual('write first protractor test'); 
    
        // You wrote your first test, cross it off the list 
        todoList.get(2).element(by.css('input')).click(); 
        var completedAmount = element.all(by.css('.done-true')); 
        expect(completedAmount.count()).toEqual(2); 
    
        }); 
    }); 
    

茉莉花實際上是「鏈接」中的承諾,期待一起本身,它方便地解決我的問題。