問題描述
我有兩個測試:
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: nexuss*$/);
//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(),我會看到motorolaso??mething".因此,雖然 clear() 似乎在工作,但如果我在第二個測試中只有 clear(),我的測試沒有通過,當我運行第二個測試時,即使調用 clear(),我也會看到motorola"在第二次測試之前.
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.
我想知道為什么 clear() 之后沒有 sendKeys() 時在第二次測試中沒有清除它.
I'm wondering why the clear() is not clearing in the second test when I do not have a sendKeys() after it.
推薦答案
clear() 的文檔說明如下:
The Documentation of clear() says the following:
[ !webdriver.promise.Promise ] 清除( )
[ !webdriver.promise.Promise ] clear( )
安排一個命令來清除此元素的 {@code 值}.如果底層 DOM 元素既不是文本 INPUT 元素也不是 TEXTAREA元素.
Schedules a command to clear the {@code value} of this element. This command has no effect if the underlying DOM element is neither a text INPUT element nor a TEXTAREA element.
返回:當元素具有被清除了.
Returns: A promise that will be resolved when the element has been cleared.
所以為了清楚地做你想做的事,你必須遵守它返回的承諾!為此,您必須使用 then()
so in order to get clear to do what you want, you have to work with the promise that it returns! to do so you have to use then()
這是它的工作原理:
queryInput.clear().then(function() {
queryInput.sendKeys('motorola');
})
所以 clear()
返回一個清除輸入的承諾,而 then()
告訴承諾在輸入被清除后立即執行什么操作.
so clear()
returns you a promise to clear the input and then()
tells the promise what to do as soon as the input is cleared.
這篇關于量角器清除()不工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!