[英]How to wait for promise in protractor/ jasmine test?
我正在學習有關量角器(並由此擴展為量角器使用的茉莉花),出於某種原因,我需要等待Promise繼續測試。 但是,我不確定該怎么做。
讓我們從Protractor教程中獲取代碼並添加一些代碼,然后添加一個不執行任何操作的簡單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
我應該怎么做才能使其正常工作?
我通過以下方式解決了它:
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); }); });
茉莉花實際上是將期望中的承諾“鏈接”在一起,很方便地解決了我的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.