Tôi có hai bài kiểm tra:
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');
});
thử nghiệm đầu tiên, hộp tìm kiếm, hoạt động tốt. kiểm tra thứ hai, trạng thái, không vượt qua vì giá trị cuối cùng được nhập trong queryInput được chuyển sang kiểm tra thứ hai và queryInput.clear () không hoạt động. Tuy nhiên, trong thử nghiệm thứ hai, nếu tôi thực hiện một cuộc gọi queryInput.sendKeys ("something"), "something" sẽ hiển thị. Nếu tôi lấy ra clear () trong lần kiểm tra thứ hai, tôi sẽ thấy "motorolasomething". Vì vậy, trong khi có vẻ như clear () đang hoạt động, bài kiểm tra của tôi sẽ không vượt qua nếu tôi chỉ có clear () trong bài kiểm tra thứ hai, khi tôi chạy bài kiểm tra thứ hai, tôi sẽ thấy "motorola", ngay cả khi clear () được gọi trước thử nghiệm thứ hai.
Tôi tự hỏi tại sao clear () không được xóa trong lần kiểm tra thứ hai khi tôi không có sendKeys () sau nó.