I have two tests:
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');
});
the first test, search box, works great. the second test, status, does not pass because the last value entered in queryInput is carried over to the second test, and the queryInput.clear() does not work. However, in the second test, if i make a call queryInput.sendKeys("something"), "something" will display. If I take out the clear() in the second test, I'll see "motorolasomething". So, while it seems the clear() is working, my test is not passing if I just have clear() in the second test, when i run the second test, I will see "motorola", even when clear() is called prior to the second test.
I'm wondering why the clear() is not clearing in the second test when I do not have a sendKeys() after it.