Reputation: 911
I'm trying to make my protractor tests to wait
a condition, but I get inconsistent behaviour. The scenario is this one:
is loading
feedback and hide the close button
.close button
reapears, continue.So, to achieve this I'm observing the close button
. Between user stops writing and debounce event fires close button
is visible. After debounced event fires (we're making request), is loading
element shows and close button
hides [1]. When is finished close button
shows again.
Any idea is really appreciated, thanks!
1: To ease testing I've make close button
dissapear at least 200ms, so that in localhost doesn't dissapear ultra-fast. This should be ok since webdriver polls every 100ms for the wait condition.
So, this is my test:
it('should show "no results" feedback when there are no results', function () {
app.getHomepage();
app.topMenu.searchLink.click();
app.search.termsInput.sendKeys('chipijanders');
app.search.waitForSearch();
expect(app.search.noResults.isDisplayed()).toBe(true);
// Checking the waitForSearch consistency
for (var i = 0; i < 10; i++) {
app.search.closeLink.click();
app.topMenu.searchLink.click();
app.search.termsInput.sendKeys('chipijanders');
app.search.waitForSearch();
expect(app.search.noResults.isDisplayed()).toBe(true);
}
});
And here waitForSearch
:
waitForSearch: function () {
var self = this;
browser.driver.wait(function() {
return self.closeLink.isDisplayed().then(function (isDisplayed) {
return !isDisplayed;
});
});
browser.driver.wait(function() {
return self.closeLink.isDisplayed().then(function (isDisplayed) {
return isDisplayed;
});
});
}
Upvotes: 2
Views: 1018
Reputation: 449
Had an issue recently waiting for a decounced method in underscore. The solution I used was to override _.debounced in protractor.conf like so
onPrepare: function () {
var debounceRightNow = function () {
angular.module('debounceRightNow', []).run(
function () {
_.debounce = function (callback) {
return callback;
};
});
};
browser.addMockModule('debounceRightNow', debounceRightNow);
}
Not sure if that answers your question but it is a nifty solution
Upvotes: 1