我有两个测试:
it('should filter the phone list as user types into the search box', function() {
var results = ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));
results.then(function(arr) {
expect(arr.length).toEqual(3);
});
var queryInput = ptor.findElement(protractor.By.input('query'));
queryInput.sendKeys('nexus');
results = ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));
results.then(function(arr) {
expect(arr.length).toEqual(1);
});
queryInput.clear();
queryInput.sendKeys('motorola');
results = ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));
results.then(function(arr) {
expect(arr.length).toEqual(2);
});
});
it('should display the current filter value within an element with id "status"',
function() {
//expect(element('#status').text()).toMatch(/Current filter: \s*$/);
var queryInput = ptor.findElement(protractor.By.input('query'));
queryInput.clear();
expect(ptor.findElement(protractor.By.id('status')).getText()).toMatch('Current Filter:');
//input('query').enter('nexus');
//queryInput.clear();
//queryInput.sendKeys('nexus');
//expect(element('#status').text()).toMatch(/Current filter: nexus\s*$/);
//expect(ptor.findElement(protractor.By.id('status')).getText()).toMatch('^\Current Filter:.');
//alternative version of the last assertion that tests just the value of the binding
//using('#status').expect(binding('query')).toBe('nexus');
});
第一个测试,搜索框,效果很好。第二个测试 status 没有通过,因为在 queryInput 中输入的最后一个值被传递到第二个测试,并且 queryInput.clear() 不起作用。但是,在第二个测试中,如果我调用 queryInput.sendKeys("something"),则会显示“something”。如果我在第二个测试中取出 clear(),我会看到“motorolasomething”。因此,虽然 clear() 似乎在工作,但如果我在第二个测试中只有 clear(),我的测试没有通过,当我运行第二个测试时,即使调用 clear(),我也会看到“motorola”在第二次测试之前。
我想知道为什么当我没有 sendKeys() 之后, clear() 没有在第二次测试中清除。