在Protractor中运行以下代码
describe('todomvc angular2 tests', function() { it('add to-dos and verify that they are displayed', function() { browser.ignoreSynchronization = true; // The site/app under test uses AngularJS in what might be called a manually bootstrapped fashion, i.e. without use the ng-app directive. browser.get('http://todomvc.com/examples/angular2/'); browser.driver.sleep(1000); // There's got to be a better way to wait for the custom tag (which is a custom AngularJS directive) to load. var el = element(by.css('input.new-todo')); el.clear(); el.sendKeys('task 1\r\n'); el.sendKeys('task 2\r\n'); browser.driver.sleep(2000); // aid in debugging var resultlist = element.all(by.repeater('todo in todoStore.todos')); // This doesn't work... expect(resultlist.count()).toEqual(2); }); });
生成以下输出:
Using the selenium server at http://localhost:4444/wd/hub [launcher] Running 1 instances of WebDriver F Failures: 1) todomvc angular2 tests add to-dos and verify that they are displayed Message: Expected 0 to equal 2. Stacktrace: Error: Failed expectation
在todoStore.todos(即ul.todo-list)中查找和检查项目的最佳方式(或任何工作方式)是什么?
答案 0 :(得分:0)
量角器应该能够很好地看到这些元素。我想知道元素是否不能满足期望?看看这个承诺是否有效:
$$('[ng-repeat="todo in todoStore.todos"]').count().then(function(countOfElements){
expect(countOfElements).toEqual(2, 'Error: Todo count did not match');
})