【发布时间】:2014-05-03 11:06:48
【问题描述】:
我一直在学习 AngularJS 教程,但在使用 beforeEach 进行端到端测试时遇到了一个奇怪的问题。对于上下文,我目前在step 3 的实验部分。测试代码在这里:
'use strict';
/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */
describe('PhoneCat App', function() {
describe('Phone list view', function() {
beforeEach(function() {
browser.get('app/index.html');
});
it('should filter the phone list as user types into the search box', function() {
var phoneList = element.all(by.repeater('phone in phones'));
var query = element(by.model('query'));
expect(phoneList.count()).toBe(3);
query.sendKeys('nexus');
expect(phoneList.count()).toBe(1);
query.clear();
query.sendKeys('motorola');
expect(phoneList.count()).toBe(2);
});
});
it('should display current filter value within an element with id "status"', function() {
var statusElement = element(by.id('status'));
expect(statusElement.getText()).toMatch(/Current filter:\s*$/);
element(by.model('query')).sendKeys('nexus');
expect(statusElement.getText()).toMatch(/Current filter: nexus\s*$/);
});
});
beforeEach 块应该在每次规范执行之前重新加载页面,但似乎不是,因为当我使用量角器运行它时,插入到第一个规范('motorola')中的查询元素中的最后一个文本仍然存在第二个规范被执行,导致第二个规范失败。
现在,当我将 beforeEach 移到外部 describe 块时,所有规范都成功通过。有任何想法吗?
【问题讨论】:
-
也许是我,但我看不出问题出在哪里:“刷新”应该在 main beforeEach (在
describe('PhoneCat App')下)正常工作,即清理每个测试之间的条目。 -
来自这里的文档 [link] [jasmine.github.io/1.3/… 它应该在每个规范之前的两个地方都有效。
标签: angularjs testing protractor